Browse Source

getUnspentOutputs excludes spent outputs

hk-custom-address
Wei Lu 11 years ago
parent
commit
9fc5505730
  1. 3
      src/wallet.js
  2. 9
      test/wallet.js

3
src/wallet.js

@ -64,7 +64,8 @@ var Wallet = function (seed, options) {
var utxo = [] var utxo = []
for(var key in this.outputs){ 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 return utxo

9
test/wallet.js

@ -171,16 +171,23 @@ describe('Wallet', function() {
}) })
describe('getUnspentOutputs', function(){ describe('getUnspentOutputs', function(){
it('parses wallet outputs to the expect format', function(){ beforeEach(function(){
wallet.outputs[expectedOutputKey] = { wallet.outputs[expectedOutputKey] = {
receive: expectedOutputKey, receive: expectedOutputKey,
scriptPubKey: expectedUtxo[0].scriptPubKey, scriptPubKey: expectedUtxo[0].scriptPubKey,
address: expectedUtxo[0].address, address: expectedUtxo[0].address,
value: expectedUtxo[0].value value: expectedUtxo[0].value
} }
})
it('parses wallet outputs to the expect format', function(){
assert.deepEqual(wallet.getUnspentOutputs(), expectedUtxo) assert.deepEqual(wallet.getUnspentOutputs(), expectedUtxo)
}) })
it('excludes spent outputs', function(){
wallet.outputs[expectedOutputKey].spend = "sometxn:m"
assert.deepEqual(wallet.getUnspentOutputs(), [])
})
}) })
describe('setUnspentOutputs', function(){ describe('setUnspentOutputs', function(){

Loading…
Cancel
Save