]> Untitled Git - bdk/commitdiff
[bdk_chain_redesign] Fix calculation bugs.
authorrajarshimaitra <rajarshi149@gmail.com>
Thu, 27 Apr 2023 14:08:25 +0000 (19:38 +0530)
committer志宇 <hello@evanlinjin.me>
Fri, 28 Apr 2023 11:07:12 +0000 (19:07 +0800)
* `IndexedTxGraph::try_balance` should include "confirmed and spendable"
  into `confirmed` balance.
* `TxGraph::try_list_chain_unspents` filter logic should be reversed.

crates/chain/src/indexed_tx_graph.rs
crates/chain/src/tx_graph.rs

index c4ee3209184525bc62184296638e817332e9aca5..6d8c16ffa1fd71ff0d2905b54333f08b187e2fd8 100644 (file)
@@ -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(_) => {
index ca6d0788a0f493ad6f62f7c05b8e1df3c56fada8..cee688be77f1c4473ef17d485adbc295ec59b52b 100644 (file)
@@ -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`.