Skip to content

Commit

Permalink
Merge PR #464 'pinheadmz/finalize1'
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Sep 3, 2020
2 parents 97737f1 + 81e83bd commit 7826128
Show file tree
Hide file tree
Showing 3 changed files with 287 additions and 16 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# HSD Release Notes & Changelog

## unreleased

### Wallet changes

- Fixes a bug that ignored the effect of sending or receiving a FINALIZE on a
wallet's `lockedConfirmed` and `lockedUnconfirmed` balance.

## v2.2.0

### Upgrading
Expand Down
42 changes: 42 additions & 0 deletions lib/wallet/txdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,14 @@ class TXDB {
state.coin(path, -1);
state.unconfirmed(path, -coin.value);

// FINALIZE is a special case: locked coins _leave_ the wallet.
if (tx.output(i) && tx.covenant(i).isFinalize()) {
if (!block)
state.ulocked(path, -tx.outputs[i].value);
else
state.clocked(path, -tx.outputs[i].value);
}

if (!block) {
// If the tx is not mined, we do not
// disconnect the coin, we simply mark
Expand Down Expand Up @@ -1157,6 +1165,10 @@ class TXDB {
// been removed on-chain.
state.confirmed(path, -coin.value);

// FINALIZE is a special case: locked coins _leave_ the wallet.
if (tx.output(i) && tx.covenant(i).isFinalize())
state.clocked(path, -tx.outputs[i].value);

await this.removeCredit(b, credit, path);

view.addCoin(coin);
Expand Down Expand Up @@ -1300,6 +1312,15 @@ class TXDB {
state.coin(path, 1);
state.unconfirmed(path, coin.value);

// FINALIZE is a special case: locked coins _leave_ the wallet.
// In this case a TX is erased, adding them back.
if (tx.output(i) && tx.covenant(i).isFinalize()) {
if (!block)
state.ulocked(path, tx.outputs[i].value);
else
state.clocked(path, tx.outputs[i].value);
}

if (block)
state.confirmed(path, coin.value);

Expand Down Expand Up @@ -1499,6 +1520,11 @@ class TXDB {

state.confirmed(path, coin.value);

// FINALIZE is a special case: locked coins _leave_ the wallet.
// In this case a TX is reversed, adding them back.
if (tx.output(i) && tx.covenant(i).isFinalize())
state.clocked(path, tx.outputs[i].value);

// Resave the credit and mark it
// as spent in the mempool instead.
credit.spent = true;
Expand Down Expand Up @@ -1719,6 +1745,14 @@ class TXDB {

break;
}

case types.FINALIZE: {
if (height === -1)
state.ulocked(path, output.value);
else
state.clocked(path, output.value);
break;
}
}
}

Expand Down Expand Up @@ -1792,6 +1826,14 @@ class TXDB {

break;
}

case types.FINALIZE: {
if (height === -1)
state.ulocked(path, -output.value);
else
state.clocked(path, -output.value);
break;
}
}
}

Expand Down
Loading

0 comments on commit 7826128

Please sign in to comment.