]> Untitled Git - bdk/commitdiff
docs(core): add detailed SyncRequest output example
authorDmenec <Domenec.Madrid@uab.cat>
Thu, 11 Dec 2025 11:00:01 +0000 (12:00 +0100)
committerDmenec <Domenec.Madrid@uab.cat>
Thu, 5 Feb 2026 11:50:34 +0000 (12:50 +0100)
crates/core/src/spk_client.rs
examples/example_electrum/src/main.rs
examples/example_esplora/src/main.rs

index 2c80e70af81abddfc9508762ec8fff1e0821a5d6..8612959cbb538b4f677f09850d20c9e12c093f39 100644 (file)
@@ -225,6 +225,7 @@ impl<I, D> SyncRequestBuilder<I, D> {
 /// [`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<I, D> SyncRequestBuilder<I, D> {
 ///     // 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();
 /// ```
index aa89f07e18340fdb61e8309e9e0d3546ac3a5f87..c9266630367138ff1f12bdca580cec75891e3b74 100644 (file)
@@ -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(),
index 99f72391cda6c1748a5f157c9d15ff55a1c3faa0..9bc3231e6e9a8f01cea9fc60ff13483ba606a89f 100644 (file)
@@ -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();
                     });