txdb: fix coin incrementation.

This commit is contained in:
Christopher Jeffrey 2016-10-20 20:23:01 -07:00
parent 8e1b2ea8e9
commit 96e6cee67d
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -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);