Skip to content

Commit e7db237

Browse files
temp: taking a look at not passing the wallet to the builder
1 parent c619621 commit e7db237

3 files changed

Lines changed: 25 additions & 13 deletions

File tree

examples/example.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,12 @@ async fn main() -> anyhow::Result<()> {
6363
mut update_subscriber,
6464
node,
6565
} = Builder::new(NETWORK)
66-
.build_with_wallet(&wallet, scan_type)
67-
.unwrap();
66+
.build_with_wallet(
67+
wallet.spk_index().clone(),
68+
wallet.latest_checkpoint(),
69+
wallet.network(),
70+
scan_type
71+
)?;
6872

6973
tokio::task::spawn(async move { node.run().await });
7074
tokio::task::spawn(async move { traces(info_subscriber, warning_subscriber).await });

src/builder.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@
5252
5353
use std::fmt::Display;
5454

55-
use bdk_wallet::{
56-
chain::{CheckPoint, IndexedTxGraph},
57-
Wallet,
58-
};
55+
use bdk_wallet::{chain::{CheckPoint, IndexedTxGraph}, KeychainKind};
56+
use bdk_wallet::bitcoin::Network;
57+
use bdk_wallet::chain::keychain_txout::KeychainTxOutIndex;
5958
pub use bip157::Builder;
6059
use bip157::{chain::ChainState, HeaderCheckpoint};
6160

@@ -68,24 +67,27 @@ pub trait BuilderExt {
6867
/// Attempt to build the node with scripts from a [`Wallet`] and following a [`ScanType`].
6968
fn build_with_wallet(
7069
self,
71-
wallet: &Wallet,
70+
txout_index: KeychainTxOutIndex<KeychainKind>,
71+
chain_tip: CheckPoint,
72+
network: Network,
7273
scan_type: ScanType,
7374
) -> Result<LightClient, BuilderError>;
7475
}
7576

7677
impl BuilderExt for Builder {
7778
fn build_with_wallet(
7879
mut self,
79-
wallet: &Wallet,
80+
txout_index: KeychainTxOutIndex<KeychainKind>,
81+
chain_tip: CheckPoint,
82+
network: Network,
8083
scan_type: ScanType,
8184
) -> Result<LightClient, BuilderError> {
82-
let network = wallet.network();
8385
if self.network().ne(&network) {
8486
return Err(BuilderError::NetworkMismatch);
8587
}
8688
match scan_type {
8789
ScanType::Sync => {
88-
let current_cp = wallet.latest_checkpoint();
90+
let current_cp = chain_tip.clone();
8991
let sync_start = walk_back_max_reorg(current_cp);
9092
self = self.chain_state(ChainState::Checkpoint(sync_start));
9193
}
@@ -101,12 +103,12 @@ impl BuilderExt for Builder {
101103
warn_rx,
102104
event_rx,
103105
} = client;
104-
let indexed_graph = IndexedTxGraph::new(wallet.spk_index().clone());
106+
let indexed_graph = IndexedTxGraph::new(txout_index);
105107
let update_subscriber = UpdateSubscriber::new(
106108
requester.clone(),
107109
scan_type,
108110
event_rx,
109-
wallet.latest_checkpoint(),
111+
chain_tip,
110112
indexed_graph,
111113
);
112114
Ok(LightClient {

tests/client.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ fn init_node(
5252
.add_peer(peer)
5353
.data_dir(tempdir)
5454
.required_peers(1)
55-
.build_with_wallet(wallet, ScanType::Sync)?)
55+
.build_with_wallet(
56+
wallet.spk_index().clone(),
57+
wallet.latest_checkpoint(),
58+
wallet.network(),
59+
ScanType::Sync
60+
)?
61+
)
5662
}
5763

5864
#[tokio::test]

0 commit comments

Comments
 (0)