block.addtx.
This commit is contained in:
parent
755d0a2c64
commit
3a7fc3a679
@ -11,6 +11,7 @@ var utils = require('./utils');
|
|||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var constants = bcoin.protocol.constants;
|
var constants = bcoin.protocol.constants;
|
||||||
var siphash = require('./siphash');
|
var siphash = require('./siphash');
|
||||||
|
var AbstractBlock = bcoin.abstractblock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a compact block (bip152): `cmpctblock` packet.
|
* Represents a compact block (bip152): `cmpctblock` packet.
|
||||||
@ -26,7 +27,7 @@ function CompactBlock(options) {
|
|||||||
if (!(this instanceof CompactBlock))
|
if (!(this instanceof CompactBlock))
|
||||||
return new CompactBlock(options);
|
return new CompactBlock(options);
|
||||||
|
|
||||||
bcoin.abstractblock.call(this, options);
|
AbstractBlock.call(this, options);
|
||||||
|
|
||||||
this.keyNonce = null;
|
this.keyNonce = null;
|
||||||
this.ids = [];
|
this.ids = [];
|
||||||
@ -42,7 +43,7 @@ function CompactBlock(options) {
|
|||||||
this.fromOptions(options);
|
this.fromOptions(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.inherits(CompactBlock, bcoin.abstractblock);
|
utils.inherits(CompactBlock, AbstractBlock);
|
||||||
|
|
||||||
CompactBlock.prototype._verify = function _verify(ret) {
|
CompactBlock.prototype._verify = function _verify(ret) {
|
||||||
return this.verifyHeaders(ret);
|
return this.verifyHeaders(ret);
|
||||||
|
|||||||
@ -11,6 +11,7 @@ var bcoin = require('./env');
|
|||||||
var utils = require('./utils');
|
var utils = require('./utils');
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var constants = bcoin.protocol.constants;
|
var constants = bcoin.protocol.constants;
|
||||||
|
var AbstractBlock = bcoin.abstractblock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a full block.
|
* Represents a full block.
|
||||||
@ -24,7 +25,7 @@ function Block(options) {
|
|||||||
if (!(this instanceof Block))
|
if (!(this instanceof Block))
|
||||||
return new Block(options);
|
return new Block(options);
|
||||||
|
|
||||||
bcoin.abstractblock.call(this, options);
|
AbstractBlock.call(this, options);
|
||||||
|
|
||||||
this.txs = [];
|
this.txs = [];
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ function Block(options) {
|
|||||||
this.fromOptions(options);
|
this.fromOptions(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.inherits(Block, bcoin.abstractblock);
|
utils.inherits(Block, AbstractBlock);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inject properties from options object.
|
* Inject properties from options object.
|
||||||
@ -235,16 +236,9 @@ Block.prototype.hasWitness = function hasWitness() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Block.prototype.addTX = function addTX(tx) {
|
Block.prototype.addTX = function addTX(tx) {
|
||||||
var index;
|
var index = this.txs.push(tx) - 1;
|
||||||
|
|
||||||
if (!(tx instanceof bcoin.tx))
|
|
||||||
tx = new bcoin.tx(tx);
|
|
||||||
|
|
||||||
index = this.txs.push(tx) - 1;
|
|
||||||
|
|
||||||
tx.setBlock(this, index);
|
tx.setBlock(this, index);
|
||||||
|
return index;
|
||||||
return tx;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
var bcoin = require('./env');
|
var bcoin = require('./env');
|
||||||
var utils = require('./utils');
|
var utils = require('./utils');
|
||||||
|
var AbstractBlock = bcoin.abstractblock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents block headers obtained from the network via `headers`.
|
* Represents block headers obtained from the network via `headers`.
|
||||||
@ -22,10 +23,10 @@ function Headers(options) {
|
|||||||
if (!(this instanceof Headers))
|
if (!(this instanceof Headers))
|
||||||
return new Headers(options);
|
return new Headers(options);
|
||||||
|
|
||||||
bcoin.abstractblock.call(this, options);
|
AbstractBlock.call(this, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.inherits(Headers, bcoin.abstractblock);
|
utils.inherits(Headers, AbstractBlock);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do non-contextual verification on the headers.
|
* Do non-contextual verification on the headers.
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
var bcoin = require('./env');
|
var bcoin = require('./env');
|
||||||
var utils = require('./utils');
|
var utils = require('./utils');
|
||||||
|
var AbstractBlock = bcoin.abstractblock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A block object which is essentially a "placeholder"
|
* A block object which is essentially a "placeholder"
|
||||||
@ -40,7 +41,7 @@ function MemBlock(options) {
|
|||||||
if (!(this instanceof MemBlock))
|
if (!(this instanceof MemBlock))
|
||||||
return new MemBlock(options);
|
return new MemBlock(options);
|
||||||
|
|
||||||
bcoin.abstractblock.call(this, options);
|
AbstractBlock.call(this, options);
|
||||||
|
|
||||||
this.memory = true;
|
this.memory = true;
|
||||||
this.coinbaseHeight = -1;
|
this.coinbaseHeight = -1;
|
||||||
@ -50,7 +51,7 @@ function MemBlock(options) {
|
|||||||
this.fromOptions(options);
|
this.fromOptions(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.inherits(MemBlock, bcoin.abstractblock);
|
utils.inherits(MemBlock, AbstractBlock);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inject properties from options object.
|
* Inject properties from options object.
|
||||||
|
|||||||
@ -12,6 +12,7 @@ var utils = require('./utils');
|
|||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var constants = bcoin.protocol.constants;
|
var constants = bcoin.protocol.constants;
|
||||||
var DUMMY = new Buffer([0]);
|
var DUMMY = new Buffer([0]);
|
||||||
|
var AbstractBlock = bcoin.abstractblock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a merkle (filtered) block.
|
* Represents a merkle (filtered) block.
|
||||||
@ -25,7 +26,7 @@ function MerkleBlock(options) {
|
|||||||
if (!(this instanceof MerkleBlock))
|
if (!(this instanceof MerkleBlock))
|
||||||
return new MerkleBlock(options);
|
return new MerkleBlock(options);
|
||||||
|
|
||||||
bcoin.abstractblock.call(this, options);
|
AbstractBlock.call(this, options);
|
||||||
|
|
||||||
this.hashes = [];
|
this.hashes = [];
|
||||||
this.flags = DUMMY;
|
this.flags = DUMMY;
|
||||||
@ -42,7 +43,7 @@ function MerkleBlock(options) {
|
|||||||
this.fromOptions(options);
|
this.fromOptions(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.inherits(MerkleBlock, bcoin.abstractblock);
|
utils.inherits(MerkleBlock, AbstractBlock);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inject properties from options object.
|
* Inject properties from options object.
|
||||||
@ -92,19 +93,13 @@ MerkleBlock.prototype.getSize = function getSize() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
MerkleBlock.prototype.addTX = function addTX(tx) {
|
MerkleBlock.prototype.addTX = function addTX(tx) {
|
||||||
var index, hash;
|
var hash = tx.hash('hex');
|
||||||
|
var index = this.map[hash];
|
||||||
if (!(tx instanceof bcoin.tx))
|
|
||||||
tx = new bcoin.tx(tx);
|
|
||||||
|
|
||||||
hash = tx.hash('hex');
|
|
||||||
index = this.map[hash];
|
|
||||||
|
|
||||||
this.txs.push(tx);
|
this.txs.push(tx);
|
||||||
|
|
||||||
tx.setBlock(this, index);
|
tx.setBlock(this, index);
|
||||||
|
|
||||||
return tx;
|
return index;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -14,6 +14,7 @@ var constants = bcoin.protocol.constants;
|
|||||||
var Script = bcoin.script;
|
var Script = bcoin.script;
|
||||||
var opcodes = constants.opcodes;
|
var opcodes = constants.opcodes;
|
||||||
var FundingError = bcoin.errors.FundingError;
|
var FundingError = bcoin.errors.FundingError;
|
||||||
|
var TX = bcoin.tx;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A mutable transaction object.
|
* A mutable transaction object.
|
||||||
@ -101,7 +102,7 @@ function MTX(options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.inherits(MTX, bcoin.tx);
|
utils.inherits(MTX, TX);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiate MTX from options.
|
* Instantiate MTX from options.
|
||||||
@ -143,7 +144,7 @@ MTX.prototype.clone = function clone() {
|
|||||||
MTX.prototype.addInput = function addInput(options, index) {
|
MTX.prototype.addInput = function addInput(options, index) {
|
||||||
var input;
|
var input;
|
||||||
|
|
||||||
if (options instanceof bcoin.tx)
|
if (options instanceof TX)
|
||||||
options = bcoin.coin.fromTX(options, index);
|
options = bcoin.coin.fromTX(options, index);
|
||||||
|
|
||||||
if (options instanceof bcoin.coin) {
|
if (options instanceof bcoin.coin) {
|
||||||
@ -1333,7 +1334,7 @@ MTX.fromExtended = function fromExtended(data, enc) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
MTX.prototype.toTX = function toTX() {
|
MTX.prototype.toTX = function toTX() {
|
||||||
return new bcoin.tx(this);
|
return new TX(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -339,6 +339,11 @@ main.deployments = {
|
|||||||
bit: 1,
|
bit: 1,
|
||||||
startTime: 2000000000, // Far in the future
|
startTime: 2000000000, // Far in the future
|
||||||
timeout: 2100000000
|
timeout: 2100000000
|
||||||
|
},
|
||||||
|
mast: {
|
||||||
|
bit: 2,
|
||||||
|
startTime: 2000000000, // Far in the future
|
||||||
|
timeout: 2100000000
|
||||||
}
|
}
|
||||||
// bip109: {
|
// bip109: {
|
||||||
// bit: 28,
|
// bit: 28,
|
||||||
@ -572,6 +577,11 @@ testnet.deployments = {
|
|||||||
bit: 1,
|
bit: 1,
|
||||||
startTime: 1462060800, // May 1st 2016
|
startTime: 1462060800, // May 1st 2016
|
||||||
timeout: 1493596800 // May 1st 2017
|
timeout: 1493596800 // May 1st 2017
|
||||||
|
},
|
||||||
|
mast: {
|
||||||
|
bit: 2,
|
||||||
|
startTime: 2000000000, // Far in the future
|
||||||
|
timeout: 2100000000
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -718,6 +728,11 @@ regtest.deployments = {
|
|||||||
bit: 1,
|
bit: 1,
|
||||||
startTime: 0,
|
startTime: 0,
|
||||||
timeout: 999999999999
|
timeout: 999999999999
|
||||||
|
},
|
||||||
|
mast: {
|
||||||
|
bit: 2,
|
||||||
|
startTime: 2000000000, // Far in the future
|
||||||
|
timeout: 2100000000
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user