[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.
This commit is contained in:
parent
e536307e5c
commit
911af34f50
@ -229,14 +229,12 @@ impl<A: Anchor, I: OwnedIndexer> IndexedTxGraph<A, I> {
|
|||||||
|
|
||||||
match &txout.chain_position {
|
match &txout.chain_position {
|
||||||
ObservedAs::Confirmed(_) => {
|
ObservedAs::Confirmed(_) => {
|
||||||
if txout.is_on_coinbase {
|
if txout.is_confirmed_and_spendable(tip_height) {
|
||||||
if txout.is_mature(tip_height) {
|
|
||||||
confirmed += txout.txout.value;
|
confirmed += txout.txout.value;
|
||||||
} else {
|
} else if !txout.is_mature(tip_height) {
|
||||||
immature += txout.txout.value;
|
immature += txout.txout.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
ObservedAs::Unconfirmed(_) => {
|
ObservedAs::Unconfirmed(_) => {
|
||||||
if should_trust(&txout.txout.script_pubkey) {
|
if should_trust(&txout.txout.script_pubkey) {
|
||||||
trusted_pending += txout.txout.value;
|
trusted_pending += txout.txout.value;
|
||||||
|
@ -860,7 +860,7 @@ impl<A: Anchor> TxGraph<A> {
|
|||||||
chain_tip: BlockId,
|
chain_tip: BlockId,
|
||||||
) -> impl Iterator<Item = Result<FullTxOut<ObservedAs<A>>, C::Error>> + 'a {
|
) -> impl Iterator<Item = Result<FullTxOut<ObservedAs<A>>, C::Error>> + 'a {
|
||||||
self.try_list_chain_txouts(chain, chain_tip)
|
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`.
|
/// List unspent outputs (UTXOs) that are in `chain` with `chain_tip`.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user