From: rajarshimaitra Date: Thu, 27 Apr 2023 14:08:25 +0000 (+0530) Subject: [bdk_chain_redesign] Fix calculation bugs. X-Git-Tag: v1.0.0-alpha.1~19^2~2 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/database/scripts/struct.CommandStringError.html?a=commitdiff_plain;h=911af34f509ad0b4c86c0be819d79b202679e3e5;p=bdk [bdk_chain_redesign] Fix calculation bugs. * `IndexedTxGraph::try_balance` should include "confirmed and spendable" into `confirmed` balance. * `TxGraph::try_list_chain_unspents` filter logic should be reversed. --- diff --git a/crates/chain/src/indexed_tx_graph.rs b/crates/chain/src/indexed_tx_graph.rs index c4ee3209..6d8c16ff 100644 --- a/crates/chain/src/indexed_tx_graph.rs +++ b/crates/chain/src/indexed_tx_graph.rs @@ -229,12 +229,10 @@ impl IndexedTxGraph { 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(_) => { diff --git a/crates/chain/src/tx_graph.rs b/crates/chain/src/tx_graph.rs index ca6d0788..cee688be 100644 --- a/crates/chain/src/tx_graph.rs +++ b/crates/chain/src/tx_graph.rs @@ -860,7 +860,7 @@ impl TxGraph { chain_tip: BlockId, ) -> impl Iterator>, 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`.