From 2e14fe17806d10c3d3d2657a92178be2d57c0fe7 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 16 Jun 2014 18:54:46 -0500 Subject: [PATCH] fix tx-pool unspent output handling. fixes #26. --- lib/bcoin/tx-pool.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/bcoin/tx-pool.js b/lib/bcoin/tx-pool.js index fae9ab23..5adddb1e 100644 --- a/lib/bcoin/tx-pool.js +++ b/lib/bcoin/tx-pool.js @@ -70,7 +70,8 @@ TXPool.prototype.add = function add(tx, noWrite) { } this._all[hash] = tx; - var own = this._wallet.ownOutput(tx); + var ownInput = this._wallet.ownInput(tx); + var ownOutput = this._wallet.ownOutput(tx); var updated = false; // Consume unspent money or add orphans @@ -92,7 +93,16 @@ TXPool.prototype.add = function add(tx, noWrite) { continue; } - if (!own) + // Only add orphans if the tx has outputs that are ours. + // if (!ownOutput) + // continue; + + // Only add orphans if this input is ours or the tx has outputs that are ours. + // if (!ownOutput && (!ownInput || !~ownInput.indexOf(input))) + // continue; + + // Only add orphans if this input is ours. + if (!ownInput || !~ownInput.indexOf(input)) continue; // Add orphan, if no parent transaction is yet known @@ -103,7 +113,7 @@ TXPool.prototype.add = function add(tx, noWrite) { this._orphans[key] = [orphan]; } - if (!own) { + if (!ownOutput) { if (updated) this.emit('update', this._lastTs, tx); @@ -130,6 +140,11 @@ TXPool.prototype.add = function add(tx, noWrite) { for (var i = 0; i < tx.outputs.length; i++) { var out = tx.outputs[i]; + // Do not add unspents for outputs that aren't ours. + if (!~ownOutput.indexOf(out)) { + continue; + } + var key = hash + '/' + i; var orphans = this._orphans[key];