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 = []
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

9
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(){

Loading…
Cancel
Save