diff --git a/src/wallet.js b/src/wallet.js index 43ad691..37e7187 100644 --- a/src/wallet.js +++ b/src/wallet.js @@ -64,7 +64,8 @@ var Wallet = function (seed, options) { var utxo = [] for(var key in this.outputs){ - utxo.push(outputToUnspentOutput(this.outputs[key])) + var output = this.outputs[key] + if(!output.spend) utxo.push(outputToUnspentOutput(output)) } return utxo diff --git a/test/wallet.js b/test/wallet.js index 80074e1..5f3996e 100644 --- a/test/wallet.js +++ b/test/wallet.js @@ -171,16 +171,23 @@ describe('Wallet', function() { }) describe('getUnspentOutputs', function(){ - it('parses wallet outputs to the expect format', function(){ + beforeEach(function(){ wallet.outputs[expectedOutputKey] = { receive: expectedOutputKey, scriptPubKey: expectedUtxo[0].scriptPubKey, address: expectedUtxo[0].address, value: expectedUtxo[0].value } + }) + it('parses wallet outputs to the expect format', function(){ assert.deepEqual(wallet.getUnspentOutputs(), expectedUtxo) }) + + it('excludes spent outputs', function(){ + wallet.outputs[expectedOutputKey].spend = "sometxn:m" + assert.deepEqual(wallet.getUnspentOutputs(), []) + }) }) describe('setUnspentOutputs', function(){