From 96e6cee67d3de31e0c8d7de631c11337e72eb01a Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 20 Oct 2016 20:23:01 -0700 Subject: [PATCH] txdb: fix coin incrementation. --- lib/wallet/txdb.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/wallet/txdb.js b/lib/wallet/txdb.js index 71bad1c6..a989328c 100644 --- a/lib/wallet/txdb.js +++ b/lib/wallet/txdb.js @@ -779,7 +779,6 @@ TXDB.prototype.resolveInput = co(function* resolveInput(tx, index, path) { if (stx.height === -1) { credit.spent = true; this.saveCredit(credit, path); - this.pending.coin++; if (tx.height !== -1) this.pending.confirmed += credit.coin.value; } @@ -991,6 +990,7 @@ TXDB.prototype.insert = co(function* insert(tx) { // be updated as it reflects the on-chain // balance _and_ mempool balance assuming // everything in the mempool were to confirm. + this.pending.coin--; this.pending.unconfirmed -= coin.value; if (tx.height === -1) { @@ -1010,7 +1010,6 @@ TXDB.prototype.insert = co(function* insert(tx) { // coin will be indexed as an undo // coin so it can be reconnected // later during a reorg. - this.pending.coin--; this.pending.confirmed -= coin.value; this.removeCredit(credit, path); } @@ -1129,6 +1128,7 @@ TXDB.prototype.confirm = co(function* confirm(tx) { // first place. this.spendCredit(credit, tx, i); + this.pending.coin--; this.pending.unconfirmed -= credit.coin.value; } @@ -1144,7 +1144,6 @@ TXDB.prototype.confirm = co(function* confirm(tx) { // We can now safely remove the credit // entirely, now that we know it's also // been removed on-chain. - this.pending.coin--; this.pending.confirmed -= coin.value; this.removeCredit(credit, path); @@ -1176,7 +1175,6 @@ TXDB.prototype.confirm = co(function* confirm(tx) { coin = credit.coin; coin.height = tx.height; - this.pending.coin++; this.pending.confirmed += output.value; this.saveCredit(credit, path); @@ -1264,12 +1262,11 @@ TXDB.prototype.erase = co(function* erase(tx) { // Recalculate the balance, remove // from stxo set, remove the undo // coin, and resave the credit. + this.pending.coin++; this.pending.unconfirmed += coin.value; - if (tx.height !== -1) { - this.pending.coin++; + if (tx.height !== -1) this.pending.confirmed += coin.value; - } this.unspendCredit(tx, i); this.saveCredit(credit, path); @@ -1449,7 +1446,6 @@ TXDB.prototype.disconnect = co(function* disconnect(tx) { details.setInput(i, path, coin); - this.pending.coin++; this.pending.confirmed += coin.value; // Resave the credit and mark it @@ -1486,7 +1482,6 @@ TXDB.prototype.disconnect = co(function* disconnect(tx) { coin = credit.coin; coin.height = -1; - this.pending.coin++; this.pending.confirmed -= output.value; this.saveCredit(credit, path);