From e08fa5306121158c00b63486aa578ec5fb614974 Mon Sep 17 00:00:00 2001 From: Rob N Date: Tue, 1 Oct 2024 06:56:03 -1000 Subject: [PATCH] fix(builder): always use lookahead --- examples/wallet.rs | 1 - src/builder.rs | 18 +----------------- src/lib.rs | 5 +++++ 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/examples/wallet.rs b/examples/wallet.rs index 3126878..8e78597 100644 --- a/examples/wallet.rs +++ b/examples/wallet.rs @@ -34,7 +34,6 @@ async fn main() -> anyhow::Result<()> { let (node, mut client) = LightClientBuilder::new(&wallet) .scan_after(170_000) .peers(peers) - .use_lookahead_scripts() .build() .unwrap(); diff --git a/src/builder.rs b/src/builder.rs index 33f7161..7e95fca 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -58,7 +58,6 @@ use kyoto::{ use crate::Client; -const PEEK_INDEX: u32 = 20; const RECOMMENDED_PEERS: u8 = 2; #[derive(Debug)] @@ -70,7 +69,6 @@ pub struct LightClientBuilder<'a> { birthday_height: Option, data_dir: Option, timeout: Option, - lookahead: bool, } impl<'a> LightClientBuilder<'a> { @@ -83,7 +81,6 @@ impl<'a> LightClientBuilder<'a> { birthday_height: None, data_dir: None, timeout: None, - lookahead: false, } } /// Add peers to connect to over the P2P network. @@ -112,15 +109,6 @@ impl<'a> LightClientBuilder<'a> { self } - /// Use all the scripts up to the wallet's lookahead parameter. Only to be used during wallet - /// recovery, when we do not have any knowledge of the scripts used in the wallet yet. For - /// more information on the wallet lookahead, - /// see [`KeychainTxOutIndex`](bdk_wallet::chain::indexer::keychain_txout::KeychainTxOutIndex). - pub fn use_lookahead_scripts(mut self) -> Self { - self.lookahead = true; - self - } - /// Configure the duration of time a remote node has to respond to a message. pub fn timeout_duration(mut self, timeout: Duration) -> Self { self.timeout = Some(timeout); @@ -215,11 +203,7 @@ impl<'a> LightClientBuilder<'a> { .spk_index() .last_revealed_index(keychain) .unwrap_or(0); - let lookahead_index = if self.lookahead { - last_revealed + self.wallet.spk_index().lookahead() - } else { - last_revealed + PEEK_INDEX - }; + let lookahead_index = last_revealed + self.wallet.spk_index().lookahead(); for index in 0..=lookahead_index { spks.insert(self.wallet.peek_address(keychain, index).script_pubkey()); } diff --git a/src/lib.rs b/src/lib.rs index 9d9a4bf..4c4d302 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -286,6 +286,11 @@ where /// Add more scripts to the node. For example, a user may reveal a Bitcoin address to receive a /// payment, so this script should be added to the [`Node`]. + /// + /// ## Note + /// + /// When using the [`LightClientBuidler`](crate::builder), the wallet lookahead will be used + /// to peek ahead and scan for additional scripts. pub async fn add_script(&self, script: impl Into) -> Result<(), ClientError> { self.client.add_script(script).await }