From cd795cf96f213627b58ac177e56a6c9e2623bcea Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 25 Jul 2017 01:53:58 -0700 Subject: [PATCH] block: remove addTX. --- lib/net/pool.js | 2 +- lib/primitives/block.js | 18 +++++------------- lib/primitives/merkleblock.js | 16 ---------------- scripts/gen.js | 2 +- 4 files changed, 7 insertions(+), 31 deletions(-) diff --git a/lib/net/pool.js b/lib/net/pool.js index 58ccf241..8ecc212c 100644 --- a/lib/net/pool.js +++ b/lib/net/pool.js @@ -2506,7 +2506,7 @@ Pool.prototype._handleTX = async function handleTX(peer, packet) { peer.merkleMap.add(hash); - block.addTX(tx); + block.txs.push(tx); if (--peer.merkleMatches === 0) { peer.merkleBlock = null; diff --git a/lib/primitives/block.js b/lib/primitives/block.js index bd225bf6..2500616f 100644 --- a/lib/primitives/block.js +++ b/lib/primitives/block.js @@ -58,8 +58,10 @@ Block.prototype.fromOptions = function fromOptions(options) { if (options.txs) { assert(Array.isArray(options.txs)); - for (let tx of options.txs) - this.addTX(tx); + for (let tx of options.txs) { + assert(tx instanceof TX); + this.txs.push(tx); + } } }; @@ -243,16 +245,6 @@ Block.prototype.hasWitness = function hasWitness() { return false; }; -/** - * Add a transaction to the block's tx vector. - * @param {TX} tx - * @returns {Number} - */ - -Block.prototype.addTX = function addTX(tx) { - return this.txs.push(tx) - 1; -}; - /** * Test the block's transaction vector against a hash. * @param {Hash} hash @@ -660,7 +652,7 @@ Block.prototype.fromReader = function fromReader(br) { for (let i = 0; i < count; i++) { let tx = TX.fromReader(br); witness += tx._witness; - this.addTX(tx); + this.txs.push(tx); } if (!this.mutable) { diff --git a/lib/primitives/merkleblock.js b/lib/primitives/merkleblock.js index b5c628ed..ec8dc51e 100644 --- a/lib/primitives/merkleblock.js +++ b/lib/primitives/merkleblock.js @@ -107,22 +107,6 @@ MerkleBlock.prototype.refresh = function refresh(all) { tx.refresh(); }; -/** - * Add a transaction to the block's tx vector. - * @param {TX} tx - * @returns {Number} - */ - -MerkleBlock.prototype.addTX = function addTX(tx) { - let tree = this.getTree(); - let hash = tx.hash('hex'); - let index = tree.map.get(hash); - - this.txs.push(tx); - - return index != null ? index : -1; -}; - /** * Test the block's _matched_ transaction vector against a hash. * @param {Hash} hash diff --git a/scripts/gen.js b/scripts/gen.js index e4782e99..457c7c4c 100644 --- a/scripts/gen.js +++ b/scripts/gen.js @@ -68,7 +68,7 @@ function createGenesisBlock(options) { height: 0 }); - block.addTX(tx); + block.txs.push(tx); return block; }