From 3a7fc3a6792bc4c612b9eca12df67af19ac66cf0 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 29 Jun 2016 16:45:23 -0700 Subject: [PATCH] block.addtx. --- lib/bcoin/bip152.js | 5 +++-- lib/bcoin/block.js | 16 +++++----------- lib/bcoin/headers.js | 5 +++-- lib/bcoin/memblock.js | 5 +++-- lib/bcoin/merkleblock.js | 17 ++++++----------- lib/bcoin/mtx.js | 7 ++++--- lib/bcoin/protocol/network.js | 15 +++++++++++++++ 7 files changed, 39 insertions(+), 31 deletions(-) diff --git a/lib/bcoin/bip152.js b/lib/bcoin/bip152.js index 26fc0360..30a36c2f 100644 --- a/lib/bcoin/bip152.js +++ b/lib/bcoin/bip152.js @@ -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); diff --git a/lib/bcoin/block.js b/lib/bcoin/block.js index 6d83328c..dec40e1e 100644 --- a/lib/bcoin/block.js +++ b/lib/bcoin/block.js @@ -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; }; /** diff --git a/lib/bcoin/headers.js b/lib/bcoin/headers.js index 2206d565..d6959ba3 100644 --- a/lib/bcoin/headers.js +++ b/lib/bcoin/headers.js @@ -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. diff --git a/lib/bcoin/memblock.js b/lib/bcoin/memblock.js index ce3532de..70e3873b 100644 --- a/lib/bcoin/memblock.js +++ b/lib/bcoin/memblock.js @@ -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. diff --git a/lib/bcoin/merkleblock.js b/lib/bcoin/merkleblock.js index a4e50771..11c41490 100644 --- a/lib/bcoin/merkleblock.js +++ b/lib/bcoin/merkleblock.js @@ -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; }; /** diff --git a/lib/bcoin/mtx.js b/lib/bcoin/mtx.js index afdd2f5b..b9202823 100644 --- a/lib/bcoin/mtx.js +++ b/lib/bcoin/mtx.js @@ -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); }; /** diff --git a/lib/bcoin/protocol/network.js b/lib/bcoin/protocol/network.js index 3fa974a7..0b8d9be2 100644 --- a/lib/bcoin/protocol/network.js +++ b/lib/bcoin/protocol/network.js @@ -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 } };