Skip to content

Commit

Permalink
refactor!(wallet): rename scan to full_scan
Browse files Browse the repository at this point in the history
refactor!(esplora): rename scan to full_scan, simplify scan_txs_with_keychain keychain_spks type
  • Loading branch information
notmandatory committed Nov 13, 2023
1 parent 9e01dee commit 11c0c0b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
8 changes: 4 additions & 4 deletions crates/bdk/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2020,11 +2020,11 @@ impl<D> Wallet<D> {
&self.chain
}

/// Get data needed to start a wallet scan
/// Get data needed to start a wallet full scan.
///
/// Collect the wallet keychain script pub keys, local chain, and previous chain tip data needed
/// to start a blockchain scan.
pub fn start_scan(
/// to start a blockchain full scan.
pub fn start_full_scan(
&self,
) -> ScanRequest<KeychainKind, impl Iterator<Item = (u32, ScriptBuf)> + Clone> {
let spks_by_keychain = self.spks_of_all_keychains();
Expand All @@ -2036,7 +2036,7 @@ impl<D> Wallet<D> {
}
}

/// Get data needed to start a wallet sync
/// Get data needed to start a wallet sync.
///
/// Collect the wallet keychain script pub keys, local chain, previous chain tip, UTXOs, and
/// unconfirmed transaction id data needed to start a blockchain sync.
Expand Down
20 changes: 9 additions & 11 deletions crates/esplora/src/async_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@ use crate::{anchor_from_status, ASSUME_FINAL_DEPTH};
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
pub trait EsploraAsyncExt {
/// Scan keychain spks for transaction histories
/// Do a full scan of keychain spks to search for spks with transaction histories.
///
/// Scan iterates through spks of all keychains and collecting tx graph updates for
/// A full scan iterates through spks of all keychains and collecting tx graph updates for
/// each spk. We start with the lowest derivation index spk and stop scanning after `stop_gap`
/// number of consecutive spks have no transaction history. A Scan is done in situations of
/// wallet restoration. It is a special case. Applications should use "sync" style updates
/// after an initial scan.
/// number of consecutive spks have no transaction history.
///
/// A full scan is done in situations of wallet restoration. It is a special case. Applications
/// should use "sync" style updates after an initial full scan.
///
/// A tuple is returned with the values:
/// * last_active_indices, contains the last active derivation indices per keychain (`K`),
/// which is used to update a wallets [`KeychainTxOutIndex`].
/// * graph_update, contains an update to a wallet's internal [`TxGraph`].
/// * chain_update, contains an update to a wallet's internal [`LocalChain`].
async fn scan<K: Clone + Ord + Send, I: Iterator<Item = (u32, ScriptBuf)> + Send>(
async fn full_scan<K: Clone + Ord + Send, I: Iterator<Item = (u32, ScriptBuf)> + Send>(
&self,
scan_request: ScanRequest<K, I>,
stop_gap: usize,
Expand Down Expand Up @@ -128,12 +129,9 @@ pub trait EsploraAsyncExt {
/// transactions. `parallel_requests` specifies the max number of HTTP requests to make in
/// parallel.
#[allow(clippy::result_large_err)]
async fn scan_txs_with_keychains<K: Ord + Clone + Send>(
async fn scan_txs_with_keychains<K: Ord + Clone + Send, I: Iterator<Item = (u32, ScriptBuf)> + Send>(
&self,
keychain_spks: BTreeMap<
K,
impl IntoIterator<IntoIter = impl Iterator<Item = (u32, ScriptBuf)> + Send> + Send,
>,
keychain_spks: BTreeMap<K, I>,
txids: impl IntoIterator<IntoIter = impl Iterator<Item = Txid> + Send> + Send,
outpoints: impl IntoIterator<IntoIter = impl Iterator<Item = OutPoint> + Send> + Send,
stop_gap: usize,
Expand Down
4 changes: 2 additions & 2 deletions example-crates/wallet_esplora_async/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// wallet restoration. It is a special case. Applications should use "sync" style updates
// after an initial scan.
if prompt("Scan wallet") {
let scan_request = wallet.start_scan();
let scan_request = wallet.start_full_scan();
let wallet_update = client
.scan(scan_request, STOP_GAP, PARALLEL_REQUESTS)
.full_scan(scan_request, STOP_GAP, PARALLEL_REQUESTS)
.await?;
wallet.apply_update(wallet_update.into())?;
wallet.commit()?;
Expand Down

0 comments on commit 11c0c0b

Please sign in to comment.