Skip to content

Commit

Permalink
[bdk_chain_redesign] Fix calculation bugs.
Browse files Browse the repository at this point in the history
* `IndexedTxGraph::try_balance` should include "confirmed and spendable"
  into `confirmed` balance.
* `TxGraph::try_list_chain_unspents` filter logic should be reversed.
  • Loading branch information
rajarshimaitra authored and evanlinjin committed Apr 28, 2023
1 parent e536307 commit 911af34
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions crates/chain/src/indexed_tx_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,10 @@ impl<A: Anchor, I: OwnedIndexer> IndexedTxGraph<A, I> {

match &txout.chain_position {
ObservedAs::Confirmed(_) => {
if txout.is_on_coinbase {
if txout.is_mature(tip_height) {
confirmed += txout.txout.value;
} else {
immature += txout.txout.value;
}
if txout.is_confirmed_and_spendable(tip_height) {
confirmed += txout.txout.value;
} else if !txout.is_mature(tip_height) {
immature += txout.txout.value;
}
}
ObservedAs::Unconfirmed(_) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/chain/src/tx_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ impl<A: Anchor> TxGraph<A> {
chain_tip: BlockId,
) -> impl Iterator<Item = Result<FullTxOut<ObservedAs<A>>, C::Error>> + 'a {
self.try_list_chain_txouts(chain, chain_tip)
.filter(|r| !matches!(r, Ok(txo) if txo.spent_by.is_none()))
.filter(|r| matches!(r, Ok(txo) if txo.spent_by.is_none()))
}

/// List unspent outputs (UTXOs) that are in `chain` with `chain_tip`.
Expand Down

0 comments on commit 911af34

Please sign in to comment.