block.addtx.

This commit is contained in:
Christopher Jeffrey 2016-06-29 16:45:23 -07:00
parent 755d0a2c64
commit 3a7fc3a679
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
7 changed files with 39 additions and 31 deletions

View File

@ -11,6 +11,7 @@ var utils = require('./utils');
var assert = utils.assert;
var constants = bcoin.protocol.constants;
var siphash = require('./siphash');
var AbstractBlock = bcoin.abstractblock;
/**
* Represents a compact block (bip152): `cmpctblock` packet.
@ -26,7 +27,7 @@ function CompactBlock(options) {
if (!(this instanceof CompactBlock))
return new CompactBlock(options);
bcoin.abstractblock.call(this, options);
AbstractBlock.call(this, options);
this.keyNonce = null;
this.ids = [];
@ -42,7 +43,7 @@ function CompactBlock(options) {
this.fromOptions(options);
}
utils.inherits(CompactBlock, bcoin.abstractblock);
utils.inherits(CompactBlock, AbstractBlock);
CompactBlock.prototype._verify = function _verify(ret) {
return this.verifyHeaders(ret);

View File

@ -11,6 +11,7 @@ var bcoin = require('./env');
var utils = require('./utils');
var assert = utils.assert;
var constants = bcoin.protocol.constants;
var AbstractBlock = bcoin.abstractblock;
/**
* Represents a full block.
@ -24,7 +25,7 @@ function Block(options) {
if (!(this instanceof Block))
return new Block(options);
bcoin.abstractblock.call(this, options);
AbstractBlock.call(this, options);
this.txs = [];
@ -40,7 +41,7 @@ function Block(options) {
this.fromOptions(options);
}
utils.inherits(Block, bcoin.abstractblock);
utils.inherits(Block, AbstractBlock);
/**
* Inject properties from options object.
@ -235,16 +236,9 @@ Block.prototype.hasWitness = function hasWitness() {
*/
Block.prototype.addTX = function addTX(tx) {
var index;
if (!(tx instanceof bcoin.tx))
tx = new bcoin.tx(tx);
index = this.txs.push(tx) - 1;
var index = this.txs.push(tx) - 1;
tx.setBlock(this, index);
return tx;
return index;
};
/**

View File

@ -9,6 +9,7 @@
var bcoin = require('./env');
var utils = require('./utils');
var AbstractBlock = bcoin.abstractblock;
/**
* Represents block headers obtained from the network via `headers`.
@ -22,10 +23,10 @@ function Headers(options) {
if (!(this instanceof Headers))
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.

View File

@ -9,6 +9,7 @@
var bcoin = require('./env');
var utils = require('./utils');
var AbstractBlock = bcoin.abstractblock;
/**
* A block object which is essentially a "placeholder"
@ -40,7 +41,7 @@ function MemBlock(options) {
if (!(this instanceof MemBlock))
return new MemBlock(options);
bcoin.abstractblock.call(this, options);
AbstractBlock.call(this, options);
this.memory = true;
this.coinbaseHeight = -1;
@ -50,7 +51,7 @@ function MemBlock(options) {
this.fromOptions(options);
}
utils.inherits(MemBlock, bcoin.abstractblock);
utils.inherits(MemBlock, AbstractBlock);
/**
* Inject properties from options object.

View File

@ -12,6 +12,7 @@ var utils = require('./utils');
var assert = utils.assert;
var constants = bcoin.protocol.constants;
var DUMMY = new Buffer([0]);
var AbstractBlock = bcoin.abstractblock;
/**
* Represents a merkle (filtered) block.
@ -25,7 +26,7 @@ function MerkleBlock(options) {
if (!(this instanceof MerkleBlock))
return new MerkleBlock(options);
bcoin.abstractblock.call(this, options);
AbstractBlock.call(this, options);
this.hashes = [];
this.flags = DUMMY;
@ -42,7 +43,7 @@ function MerkleBlock(options) {
this.fromOptions(options);
}
utils.inherits(MerkleBlock, bcoin.abstractblock);
utils.inherits(MerkleBlock, AbstractBlock);
/**
* Inject properties from options object.
@ -92,19 +93,13 @@ MerkleBlock.prototype.getSize = function getSize() {
*/
MerkleBlock.prototype.addTX = function addTX(tx) {
var index, hash;
if (!(tx instanceof bcoin.tx))
tx = new bcoin.tx(tx);
hash = tx.hash('hex');
index = this.map[hash];
var hash = tx.hash('hex');
var index = this.map[hash];
this.txs.push(tx);
tx.setBlock(this, index);
return tx;
return index;
};
/**

View File

@ -14,6 +14,7 @@ var constants = bcoin.protocol.constants;
var Script = bcoin.script;
var opcodes = constants.opcodes;
var FundingError = bcoin.errors.FundingError;
var TX = bcoin.tx;
/**
* A mutable transaction object.
@ -101,7 +102,7 @@ function MTX(options) {
}
}
utils.inherits(MTX, bcoin.tx);
utils.inherits(MTX, TX);
/**
* Instantiate MTX from options.
@ -143,7 +144,7 @@ MTX.prototype.clone = function clone() {
MTX.prototype.addInput = function addInput(options, index) {
var input;
if (options instanceof bcoin.tx)
if (options instanceof TX)
options = bcoin.coin.fromTX(options, index);
if (options instanceof bcoin.coin) {
@ -1333,7 +1334,7 @@ MTX.fromExtended = function fromExtended(data, enc) {
*/
MTX.prototype.toTX = function toTX() {
return new bcoin.tx(this);
return new TX(this);
};
/**

View File

@ -339,6 +339,11 @@ main.deployments = {
bit: 1,
startTime: 2000000000, // Far in the future
timeout: 2100000000
},
mast: {
bit: 2,
startTime: 2000000000, // Far in the future
timeout: 2100000000
}
// bip109: {
// bit: 28,
@ -572,6 +577,11 @@ testnet.deployments = {
bit: 1,
startTime: 1462060800, // May 1st 2016
timeout: 1493596800 // May 1st 2017
},
mast: {
bit: 2,
startTime: 2000000000, // Far in the future
timeout: 2100000000
}
};
@ -718,6 +728,11 @@ regtest.deployments = {
bit: 1,
startTime: 0,
timeout: 999999999999
},
mast: {
bit: 2,
startTime: 2000000000, // Far in the future
timeout: 2100000000
}
};