From 82b1d8fbdcd5ffee0b500125aece6730a5daa5ba Mon Sep 17 00:00:00 2001 From: Wei Lu Date: Sat, 21 Jun 2014 14:26:38 +0800 Subject: [PATCH] wallet: do not delete pending incoming tx from outputs --- src/wallet.js | 8 +++++++- test/wallet.js | 25 ++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/wallet.js b/src/wallet.js index d3c3fbe..65651f0 100644 --- a/src/wallet.js +++ b/src/wallet.js @@ -175,7 +175,13 @@ function Wallet(seed, network) { var output = txinId + ':' + txIn.index - if(me.outputs[output]) delete me.outputs[output] + if (!(output in me.outputs)) return + + if (isPending) { + return me.outputs[output].pending = true + } + + delete me.outputs[output] }) } diff --git a/test/wallet.js b/test/wallet.js index 58a0283..456838e 100644 --- a/test/wallet.js +++ b/test/wallet.js @@ -264,12 +264,35 @@ describe('Wallet', function() { }) describe("processPendingTx", function(){ - it("sets the pending flag on output", function(){ + it("incoming: sets the pending flag on output", function(){ wallet.addresses = [addresses[0]] wallet.processPendingTx(tx) verifyOutputAdded(0, true) }) + + describe("when tx ins outpoint contains a known txhash:i", function(){ + var spendTx + beforeEach(function(){ + wallet.addresses = [addresses[0]] + wallet.processConfirmedTx(tx) + + spendTx = Transaction.fromHex(fixtureTx2Hex) + }) + + it("outgoing: sets the pending flag on output instead of deleting it", function(){ + var txIn = spendTx.ins[0] + var txInId = new Buffer(txIn.hash) + Array.prototype.reverse.call(txInId) + txInId = txInId.toString('hex') + + var key = txInId + ':' + txIn.index + assert(!wallet.outputs[key].pending) + + wallet.processPendingTx(spendTx) + assert(wallet.outputs[key].pending) + }) + }) }) describe('processConfirmedTx', function(){