/// [`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());
/// // 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();
/// ```
.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(),
.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();
});