From: Dmenec Date: Thu, 11 Dec 2025 11:00:01 +0000 (+0100) Subject: docs(core): add detailed SyncRequest output example X-Git-Url: http://internal-gitweb-vhost/%22https:/parse/scripts/-sqlite/database/enum.InsertCheckpointError.html?a=commitdiff_plain;h=d0889f37ae1176eb1510a8d260cde8e05fe68f76;p=bdk docs(core): add detailed SyncRequest output example --- diff --git a/crates/core/src/spk_client.rs b/crates/core/src/spk_client.rs index 2c80e70a..8612959c 100644 --- a/crates/core/src/spk_client.rs +++ b/crates/core/src/spk_client.rs @@ -225,6 +225,7 @@ impl SyncRequestBuilder { /// [`chain_tip`](SyncRequestBuilder::chain_tip) (if provided). /// /// ```rust +/// # use std::io::{self, Write}; /// # use bdk_chain::{bitcoin::{hashes::Hash, ScriptBuf}, local_chain::LocalChain}; /// # use bdk_chain::spk_client::SyncRequest; /// # let (local_chain, _) = LocalChain::from_genesis(Hash::all_zeros()); @@ -236,7 +237,22 @@ impl SyncRequestBuilder { /// // Provide list of scripts to scan for transactions against. /// .spks(scripts) /// // This is called for every synced item. -/// .inspect(|item, progress| println!("{} (remaining: {})", item, progress.remaining())) +/// .inspect(|item, progress| { +/// let pc = (100.0 * progress.consumed() as f32) / progress.total() as f32; +/// match item { +/// // In this example I = (), so the first field of Spk is unit. +/// bdk_chain::spk_client::SyncItem::Spk((), spk) => { +/// eprintln!("[ SCANNING {pc:03.0}% ] script {}", spk); +/// } +/// bdk_chain::spk_client::SyncItem::Txid(txid) => { +/// eprintln!("[ SCANNING {pc:03.0}% ] txid {}", txid); +/// } +/// bdk_chain::spk_client::SyncItem::OutPoint(op) => { +/// eprintln!("[ SCANNING {pc:03.0}% ] outpoint {}", op); +/// } +/// } +/// let _ = io::stderr().flush(); +/// }) /// // Finish constructing the sync request. /// .build(); /// ``` diff --git a/examples/example_electrum/src/main.rs b/examples/example_electrum/src/main.rs index aa89f07e..c9266630 100644 --- a/examples/example_electrum/src/main.rs +++ b/examples/example_electrum/src/main.rs @@ -210,9 +210,22 @@ fn main() -> anyhow::Result<()> { .chain_tip(chain_tip.clone()) .inspect(|item, progress| { let pc = (100 * progress.consumed()) as f32 / progress.total() as f32; - eprintln!("[ SCANNING {pc:03.0}% ] {item}"); + match item { + bdk_chain::spk_client::SyncItem::Spk((keychain, index), spk) => { + eprintln!( + "[ SCANNING {pc:3.0}% ] script {} {} {}", + keychain, index, spk + ); + } + bdk_chain::spk_client::SyncItem::Txid(txid) => { + eprintln!("[ SCANNING {pc:3.0}% ] txid {}", txid); + } + bdk_chain::spk_client::SyncItem::OutPoint(op) => { + eprintln!("[ SCANNING {pc:3.0}% ] outpoint {}", op); + } + } + let _ = io::stderr().flush(); }); - let canonical_view = graph.canonical_view( &*chain, chain_tip.block_id(), diff --git a/examples/example_esplora/src/main.rs b/examples/example_esplora/src/main.rs index 99f72391..9bc3231e 100644 --- a/examples/example_esplora/src/main.rs +++ b/examples/example_esplora/src/main.rs @@ -215,8 +215,20 @@ fn main() -> anyhow::Result<()> { .chain_tip(local_tip.clone()) .inspect(|item, progress| { let pc = (100 * progress.consumed()) as f32 / progress.total() as f32; - eprintln!("[ SCANNING {pc:03.0}% ] {item}"); - // Flush early to ensure we print at every iteration. + match item { + bdk_chain::spk_client::SyncItem::Spk((keychain, index), spk) => { + eprintln!( + "[ SCANNING {pc:3.0}% ] script {} {} {}", + keychain, index, spk + ); + } + bdk_chain::spk_client::SyncItem::Txid(txid) => { + eprintln!("[ SCANNING {pc:3.0}% ] txid {}", txid); + } + bdk_chain::spk_client::SyncItem::OutPoint(op) => { + eprintln!("[ SCANNING {pc:3.0}% ] outpoint {}", op); + } + } let _ = io::stderr().flush(); });