getUnspentOutputs excludes spent outputs
This commit is contained in:
parent
77b5d1ee21
commit
9fc5505730
2 changed files with 10 additions and 2 deletions
|
@ -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
|
||||||
|
|
|
@ -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…
Reference in a new issue