feat: update logging of electrum examples

* Syncing with `example_electrum` now shows progress as a percentage.
* Flush stdout more aggressively.
This commit is contained in:
志宇
2024-05-04 19:27:11 +08:00
parent a6fdfb2ae4
commit b1f861b932
2 changed files with 46 additions and 13 deletions

View File

@@ -3,6 +3,7 @@ const SEND_AMOUNT: Amount = Amount::from_sat(5000);
const STOP_GAP: usize = 50;
const BATCH_SIZE: usize = 5;
use std::io::Write;
use std::str::FromStr;
use bdk::bitcoin::{Address, Amount};
@@ -38,13 +39,19 @@ fn main() -> Result<(), anyhow::Error> {
print!("Syncing...");
let client = electrum_client::Client::new("ssl://electrum.blockstream.info:60002")?;
let request = wallet.start_full_scan().inspect_spks_for_all_keychains({
let mut once = HashSet::<KeychainKind>::new();
move |k, spk_i, _| match once.insert(k) {
true => print!("\nScanning keychain [{:?}]", k),
false => print!(" {:<3}", spk_i),
}
});
let request = wallet
.start_full_scan()
.inspect_spks_for_all_keychains({
let mut once = HashSet::<KeychainKind>::new();
move |k, spk_i, _| {
if once.insert(k) {
print!("\nScanning keychain [{:?}]", k)
} else {
print!(" {:<3}", spk_i)
}
}
})
.inspect_spks_for_all_keychains(|_, _, _| std::io::stdout().flush().expect("must flush"));
let mut update = client
.full_scan(request, STOP_GAP, BATCH_SIZE)?