Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use extension trait #89

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@
//! }
//! ```

use std::{collections::HashSet, path::PathBuf, time::Duration};
use std::{path::PathBuf, time::Duration};

use bdk_chain::local_chain::MissingGenesisError;
use bdk_wallet::{KeychainKind, Wallet};
use bdk_wallet::Wallet;
use kyoto::NodeBuilder;
pub use kyoto::{
db::error::SqlInitializationError, AddrV2, HeaderCheckpoint, ScriptBuf, ServiceFlags,
TrustedPeer,
};

use crate::{EventReceiver, LightClient};
use crate::{EventReceiver, LightClient, WalletExt};

const RECOMMENDED_PEERS: u8 = 2;

Expand Down Expand Up @@ -153,20 +153,9 @@ impl LightClientBuilder {
}
node_builder =
node_builder.num_required_peers(self.connections.unwrap_or(RECOMMENDED_PEERS));
let mut spks: HashSet<ScriptBuf> = HashSet::new();
for keychain in [KeychainKind::External, KeychainKind::Internal] {
// The user may choose to recover a wallet with lookahead scripts
// or use the last revealed index plus some padding to find new transactions
let last_revealed = wallet
.spk_index()
.last_revealed_index(keychain)
.unwrap_or(0);
let lookahead_index = last_revealed + wallet.spk_index().lookahead();
for index in 0..=lookahead_index {
spks.insert(wallet.peek_address(keychain, index).script_pubkey());
}
}
let (node, kyoto_client) = node_builder.add_scripts(spks).build_node()?;
let (node, kyoto_client) = node_builder
.add_scripts(wallet.peek_revealed_plus_lookahead().collect())
.build_node()?;
let (sender, receiver) = kyoto_client.split();
let event_receiver =
EventReceiver::from_index(wallet.local_chain().tip(), wallet.spk_index(), receiver)?;
Expand Down
Loading