From 42a5de54cb7d571891159dd85a191cf82dda15c6 Mon Sep 17 00:00:00 2001 From: thunderbiscuit Date: Fri, 27 Feb 2026 13:45:11 -0500 Subject: [PATCH] temp: taking a look at not passing the wallet to the builder --- examples/example.rs | 9 ++++++--- src/builder.rs | 19 ++++++++++++------- tests/client.rs | 7 ++++++- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/examples/example.rs b/examples/example.rs index 5ae2f5f..85f5971 100644 --- a/examples/example.rs +++ b/examples/example.rs @@ -62,9 +62,12 @@ async fn main() -> anyhow::Result<()> { warning_subscriber, mut update_subscriber, node, - } = Builder::new(NETWORK) - .build_with_wallet(&wallet, scan_type) - .unwrap(); + } = Builder::new(NETWORK).build_with_wallet( + wallet.spk_index().clone(), + wallet.latest_checkpoint(), + wallet.network(), + scan_type, + )?; tokio::task::spawn(async move { node.run().await }); tokio::task::spawn(async move { traces(info_subscriber, warning_subscriber).await }); diff --git a/src/builder.rs b/src/builder.rs index dcbe85f..ccb7c09 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -52,9 +52,11 @@ use std::fmt::Display; +use bdk_wallet::bitcoin::Network; +use bdk_wallet::chain::keychain_txout::KeychainTxOutIndex; use bdk_wallet::{ chain::{CheckPoint, IndexedTxGraph}, - Wallet, + KeychainKind, }; pub use bip157::Builder; use bip157::{chain::ChainState, HeaderCheckpoint}; @@ -68,7 +70,9 @@ pub trait BuilderExt { /// Attempt to build the node with scripts from a [`Wallet`] and following a [`ScanType`]. fn build_with_wallet( self, - wallet: &Wallet, + txout_index: KeychainTxOutIndex, + chain_tip: CheckPoint, + network: Network, scan_type: ScanType, ) -> Result; } @@ -76,16 +80,17 @@ pub trait BuilderExt { impl BuilderExt for Builder { fn build_with_wallet( mut self, - wallet: &Wallet, + txout_index: KeychainTxOutIndex, + chain_tip: CheckPoint, + network: Network, scan_type: ScanType, ) -> Result { - let network = wallet.network(); if self.network().ne(&network) { return Err(BuilderError::NetworkMismatch); } match scan_type { ScanType::Sync => { - let current_cp = wallet.latest_checkpoint(); + let current_cp = chain_tip.clone(); let sync_start = walk_back_max_reorg(current_cp); self = self.chain_state(ChainState::Checkpoint(sync_start)); } @@ -101,12 +106,12 @@ impl BuilderExt for Builder { warn_rx, event_rx, } = client; - let indexed_graph = IndexedTxGraph::new(wallet.spk_index().clone()); + let indexed_graph = IndexedTxGraph::new(txout_index); let update_subscriber = UpdateSubscriber::new( requester.clone(), scan_type, event_rx, - wallet.latest_checkpoint(), + chain_tip, indexed_graph, ); Ok(LightClient { diff --git a/tests/client.rs b/tests/client.rs index 5667780..037ed6b 100644 --- a/tests/client.rs +++ b/tests/client.rs @@ -52,7 +52,12 @@ fn init_node( .add_peer(peer) .data_dir(tempdir) .required_peers(1) - .build_with_wallet(wallet, ScanType::Sync)?) + .build_with_wallet( + wallet.spk_index().clone(), + wallet.latest_checkpoint(), + wallet.network(), + ScanType::Sync, + )?) } #[tokio::test]