From e064e9d29da787ad374417b2f09914f0d9ca424c Mon Sep 17 00:00:00 2001 From: Wei Lu Date: Thu, 12 Jun 2014 13:11:28 +0800 Subject: [PATCH] wallet.createTx ignores pending utxo --- src/wallet.js | 5 +++-- test/wallet.js | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/wallet.js b/src/wallet.js index 5e04b74..1466774 100644 --- a/src/wallet.js +++ b/src/wallet.js @@ -103,7 +103,8 @@ function Wallet(seed, network) { return { receive: key, address: o.address, - value: o.value + value: o.value, + pending: o.pending } } @@ -211,7 +212,7 @@ function Wallet(seed, network) { for (var key in me.outputs) { var output = me.outputs[key] - if (!output.spend) unspent.push(output) + if (!output.spend && !output.pending) unspent.push(output) } var sortByValueDesc = unspent.sort(function(o1, o2){ diff --git a/test/wallet.js b/test/wallet.js index 00fea42..2f96899 100644 --- a/test/wallet.js +++ b/test/wallet.js @@ -439,6 +439,25 @@ describe('Wallet', function() { assert.equal(tx.ins.length, 1) assert.deepEqual(tx.ins[0].outpoint, { hash: fakeTxHash(3), index: 0 }) }) + + it('ignores pending outputs', function(){ + utxo.push( + { + "hash": fakeTxHash(4), + "outputIndex": 0, + "address" : address2, + "value": 530000, + "pending": true + } + ) + wallet.setUnspentOutputs(utxo) + + var tx = wallet.createTx(to, value) + + assert.equal(tx.ins.length, 1) + assert.deepEqual(tx.ins[0].outpoint, { hash: fakeTxHash(3), index: 0 }) + }) + }) describe(networks.testnet, function(){