From c7ae1f3d6be1b84803a804cac1ebc28921b67365 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 24 Feb 2016 07:32:05 -0800 Subject: [PATCH] minor refactor --- lib/bcoin/block.js | 1 - lib/bcoin/merkleblock.js | 6 +++--- lib/bcoin/mtx.js | 4 ++++ lib/bcoin/tx-pool.js | 2 +- lib/bcoin/tx.js | 8 ++++++-- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/bcoin/block.js b/lib/bcoin/block.js index 74f3471a..8328b9e1 100644 --- a/lib/bcoin/block.js +++ b/lib/bcoin/block.js @@ -17,7 +17,6 @@ var network = bcoin.protocol.network; function Block(data) { var self = this; - var tx, height; if (!(this instanceof Block)) return new Block(data); diff --git a/lib/bcoin/merkleblock.js b/lib/bcoin/merkleblock.js index 62d4ed4e..2370bedd 100644 --- a/lib/bcoin/merkleblock.js +++ b/lib/bcoin/merkleblock.js @@ -26,14 +26,14 @@ function MerkleBlock(data) { this.hashes = (data.hashes || []).map(function(hash) { return utils.toHex(hash); }); + this.flags = data.flags || []; - this.txs = data.txs || []; // List of matched TXs this.tx = []; // TXs that will be pushed on - this.txs = data.txs || []; + this.txs = []; if (!this._raw) this._raw = this.render(); @@ -116,7 +116,7 @@ MerkleBlock.prototype._verify = function _verify() { // Verify the partial merkle tree if we are a merkleblock. if (!this._verifyPartial()) { - utils.debug('MerkleBlock failed merkle test: %s', this.rhash); + utils.debug('Block failed merkle test: %s', this.rhash); return false; } diff --git a/lib/bcoin/mtx.js b/lib/bcoin/mtx.js index 0ae3053d..58b5e89a 100644 --- a/lib/bcoin/mtx.js +++ b/lib/bcoin/mtx.js @@ -62,6 +62,10 @@ function MTX(options) { utils.inherits(MTX, bcoin.tx); +MTX.prototype._init = function _init() { + ; +}; + MTX.prototype.clone = function clone() { var tx = new MTX(this); diff --git a/lib/bcoin/tx-pool.js b/lib/bcoin/tx-pool.js index d723d7e9..46248a46 100644 --- a/lib/bcoin/tx-pool.js +++ b/lib/bcoin/tx-pool.js @@ -67,7 +67,7 @@ TXPool.prototype.add = function add(tx, noWrite) { if (!this._wallet.ownInput(tx) && !this._wallet.ownOutput(tx)) return false; - if (tx instanceof bcoin.tx) + if (tx.type === 'tx') tx = bcoin.mtx.fromTX(tx); // Ignore stale pending transactions diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index 3a3af8a3..ee4645bc 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -54,7 +54,11 @@ function TX(data, block) { }, this); } - if (block && !data.ts) { + this._init(block); +} + +TX.prototype._init = function _init(block) { + if (block && this.ts === 0) { if (block.type === 'merkleblock') { if (block.hasTX(this.hash('hex'))) this.setBlock(block); @@ -68,7 +72,7 @@ function TX(data, block) { if (!this._size) this._size = this._raw.length; -} +}; TX.prototype.setBlock = function setBlock(block) { this.relayedBy = block.relayedBy;