Skip to content

Commit cb72f4a

Browse files
evanlinjinclaude
andcommitted
refactor(chain)!: Change trust_predicate to accept FullTxOut
BREAKING CHANGE: The trust_predicate parameter in CanonicalView::balance() now takes &FullTxOut<A> instead of ScriptBuf as its second argument. This provides more context to the predicate function. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 7245631 commit cb72f4a

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

crates/chain/src/canonical_view.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ impl<A: Anchor> CanonicalView<A> {
355355
pub fn balance<'v, O: Clone + 'v>(
356356
&'v self,
357357
outpoints: impl IntoIterator<Item = (O, OutPoint)> + 'v,
358-
mut trust_predicate: impl FnMut(&O, ScriptBuf) -> bool,
358+
mut trust_predicate: impl FnMut(&O, &FullTxOut<A>) -> bool,
359359
additional_confirmations: u32,
360360
) -> Balance {
361361
let mut immature = Amount::ZERO;
@@ -376,7 +376,7 @@ impl<A: Anchor> CanonicalView<A> {
376376

377377
if confirmations < required_confirmations {
378378
// Not enough confirmations, treat as trusted/untrusted pending
379-
if trust_predicate(&spk_i, txout.txout.script_pubkey) {
379+
if trust_predicate(&spk_i, &txout) {
380380
trusted_pending += txout.txout.value;
381381
} else {
382382
untrusted_pending += txout.txout.value;
@@ -388,7 +388,7 @@ impl<A: Anchor> CanonicalView<A> {
388388
}
389389
}
390390
ChainPosition::Unconfirmed { .. } => {
391-
if trust_predicate(&spk_i, txout.txout.script_pubkey) {
391+
if trust_predicate(&spk_i, &txout) {
392392
trusted_pending += txout.txout.value;
393393
} else {
394394
untrusted_pending += txout.txout.value;

crates/chain/tests/test_indexed_tx_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ fn test_list_owned_txouts() {
473473
.canonical_view(&local_chain, chain_tip, CanonicalizationParams::default())
474474
.balance(
475475
graph.index.outpoints().iter().cloned(),
476-
|_, spk: ScriptBuf| trusted_spks.contains(&spk),
476+
|_, txout| trusted_spks.contains(&txout.txout.script_pubkey),
477477
0,
478478
);
479479

crates/chain/tests/test_tx_graph_conflicts.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod common;
55

66
use bdk_chain::{local_chain::LocalChain, Balance, BlockId};
77
use bdk_testenv::{block_id, hash, local_chain};
8-
use bitcoin::{Amount, BlockHash, OutPoint, ScriptBuf};
8+
use bitcoin::{Amount, BlockHash, OutPoint};
99
use common::*;
1010
use std::collections::{BTreeSet, HashSet};
1111

@@ -1032,8 +1032,12 @@ fn test_tx_conflict_handling() {
10321032
.canonical_view(&local_chain, chain_tip, env.canonicalization_params.clone())
10331033
.balance(
10341034
env.indexer.outpoints().iter().cloned(),
1035-
|_, spk: ScriptBuf| env.indexer.index_of_spk(spk).is_some(),
1036-
1,
1035+
|_, txout| {
1036+
env.indexer
1037+
.index_of_spk(txout.txout.script_pubkey.clone())
1038+
.is_some()
1039+
},
1040+
0,
10371041
);
10381042
assert_eq!(
10391043
balance, scenario.exp_balance,

0 commit comments

Comments
 (0)