Wallet: remove txId:index storage for spent outputs
This commit is contained in:
parent
0f9674e65f
commit
735feab7ba
2 changed files with 16 additions and 10 deletions
|
@ -96,7 +96,7 @@ Wallet.prototype.processConfirmedTx = function(tx){
|
|||
}
|
||||
|
||||
Wallet.prototype.__processTx = function(tx, isPending) {
|
||||
var txid = tx.getId()
|
||||
var txId = tx.getId()
|
||||
|
||||
tx.outs.forEach(function(txOut, i) {
|
||||
var address
|
||||
|
@ -109,7 +109,7 @@ Wallet.prototype.__processTx = function(tx, isPending) {
|
|||
|
||||
var myAddresses = this.addresses.concat(this.changeAddresses)
|
||||
if (myAddresses.indexOf(address) > -1) {
|
||||
var output = txid + ':' + i
|
||||
var output = txId + ':' + i
|
||||
|
||||
this.outputs[output] = {
|
||||
from: output,
|
||||
|
@ -131,8 +131,9 @@ Wallet.prototype.__processTx = function(tx, isPending) {
|
|||
if (!(output in this.outputs)) return
|
||||
|
||||
if (isPending) {
|
||||
this.outputs[output].to = txid + ':' + i
|
||||
this.outputs[output].pending = true
|
||||
this.outputs[output].spent = true
|
||||
|
||||
} else {
|
||||
delete this.outputs[output]
|
||||
}
|
||||
|
@ -206,7 +207,11 @@ Wallet.prototype.getUnspentOutputs = function() {
|
|||
|
||||
for(var key in this.outputs){
|
||||
var output = this.outputs[key]
|
||||
if(!output.to) utxo.push(outputToUnspentOutput(output))
|
||||
|
||||
// Don't include pending spent outputs
|
||||
if (!output.spent) {
|
||||
utxo.push(outputToUnspentOutput(output))
|
||||
}
|
||||
}
|
||||
|
||||
return utxo
|
||||
|
|
|
@ -246,10 +246,10 @@ describe('Wallet', function() {
|
|||
assert.deepEqual(wallet.getUnspentOutputs(), [utxo])
|
||||
})
|
||||
|
||||
it("ignores pending spending outputs (outputs with 'to' property)", function() {
|
||||
it("ignores pending spending outputs (outputs with 'spent' property)", function() {
|
||||
var output = wallet.outputs[expectedOutputKey]
|
||||
output.to = fakeTxId(0) + ':' + 0
|
||||
output.pending = true
|
||||
output.spent = true
|
||||
assert.deepEqual(wallet.getUnspentOutputs(), [])
|
||||
})
|
||||
})
|
||||
|
@ -331,18 +331,19 @@ describe('Wallet', function() {
|
|||
spendTx = Transaction.fromHex(fixtureTx2Hex)
|
||||
})
|
||||
|
||||
it("outgoing: sets the pending flag and 'to' on output", function() {
|
||||
it("outgoing: sets the pending flag and 'spent' on output", function() {
|
||||
var txIn = spendTx.ins[0]
|
||||
var txInId = new Buffer(txIn.hash)
|
||||
Array.prototype.reverse.call(txInId)
|
||||
txInId = txInId.toString('hex')
|
||||
|
||||
var key = txInId + ':' + txIn.index
|
||||
assert(!wallet.outputs[key].pending)
|
||||
var output = wallet.outputs[key]
|
||||
|
||||
assert(!output.pending)
|
||||
wallet.processPendingTx(spendTx)
|
||||
assert(wallet.outputs[key].pending)
|
||||
assert.equal(wallet.outputs[key].to, spendTx.getId() + ':' + 0)
|
||||
assert(output.pending)
|
||||
assert(output.spent, true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Reference in a new issue