fix tx-pool unspent output handling. fixes #26.

This commit is contained in:
Christopher Jeffrey 2014-06-16 18:54:46 -05:00
parent 3a7b20ddee
commit 2e14fe1780

View File

@ -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];