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:
parent
a6fdfb2ae4
commit
b1f861b932
@ -180,11 +180,11 @@ fn main() -> anyhow::Result<()> {
|
|||||||
let mut once = BTreeSet::new();
|
let mut once = BTreeSet::new();
|
||||||
move |k, spk_i, _| {
|
move |k, spk_i, _| {
|
||||||
if once.insert(k) {
|
if once.insert(k) {
|
||||||
eprint!("\nScanning {}: ", k);
|
eprint!("\nScanning {}: {} ", k, spk_i);
|
||||||
} else {
|
} else {
|
||||||
eprint!("{} ", spk_i);
|
eprint!("{} ", spk_i);
|
||||||
}
|
}
|
||||||
let _ = io::stdout().flush();
|
io::stdout().flush().expect("must flush");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
@ -229,7 +229,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
.map(|(k, i, spk)| (k.to_owned(), i, spk.to_owned()))
|
.map(|(k, i, spk)| (k.to_owned(), i, spk.to_owned()))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
request = request.chain_spks(all_spks.into_iter().map(|(k, spk_i, spk)| {
|
request = request.chain_spks(all_spks.into_iter().map(|(k, spk_i, spk)| {
|
||||||
eprintln!("scanning {}: {}", k, spk_i);
|
eprint!("Scanning {}: {}", k, spk_i);
|
||||||
spk
|
spk
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@ -241,7 +241,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
request =
|
request =
|
||||||
request.chain_spks(unused_spks.into_iter().map(move |(k, spk_i, spk)| {
|
request.chain_spks(unused_spks.into_iter().map(move |(k, spk_i, spk)| {
|
||||||
eprintln!(
|
eprint!(
|
||||||
"Checking if address {} {}:{} has been used",
|
"Checking if address {} {}:{} has been used",
|
||||||
Address::from_script(&spk, args.network).unwrap(),
|
Address::from_script(&spk, args.network).unwrap(),
|
||||||
k,
|
k,
|
||||||
@ -260,7 +260,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
.map(|(_, utxo)| utxo)
|
.map(|(_, utxo)| utxo)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
request = request.chain_outpoints(utxos.into_iter().map(|utxo| {
|
request = request.chain_outpoints(utxos.into_iter().map(|utxo| {
|
||||||
eprintln!(
|
eprint!(
|
||||||
"Checking if outpoint {} (value: {}) has been spent",
|
"Checking if outpoint {} (value: {}) has been spent",
|
||||||
utxo.outpoint, utxo.txout.value
|
utxo.outpoint, utxo.txout.value
|
||||||
);
|
);
|
||||||
@ -279,10 +279,36 @@ fn main() -> anyhow::Result<()> {
|
|||||||
request = request.chain_txids(
|
request = request.chain_txids(
|
||||||
unconfirmed_txids
|
unconfirmed_txids
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.inspect(|txid| eprintln!("Checking if {} is confirmed yet", txid)),
|
.inspect(|txid| eprint!("Checking if {} is confirmed yet", txid)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let total_spks = request.spks.len();
|
||||||
|
let total_txids = request.txids.len();
|
||||||
|
let total_ops = request.outpoints.len();
|
||||||
|
request = request
|
||||||
|
.inspect_spks({
|
||||||
|
let mut visited = 0;
|
||||||
|
move |_| {
|
||||||
|
visited += 1;
|
||||||
|
eprintln!(" [ {:>6.2}% ]", (visited * 100) as f32 / total_spks as f32)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.inspect_txids({
|
||||||
|
let mut visited = 0;
|
||||||
|
move |_| {
|
||||||
|
visited += 1;
|
||||||
|
eprintln!(" [ {:>6.2}% ]", (visited * 100) as f32 / total_txids as f32)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.inspect_outpoints({
|
||||||
|
let mut visited = 0;
|
||||||
|
move |_| {
|
||||||
|
visited += 1;
|
||||||
|
eprintln!(" [ {:>6.2}% ]", (visited * 100) as f32 / total_ops as f32)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let res = client
|
let res = client
|
||||||
.sync(request, scan_options.batch_size)
|
.sync(request, scan_options.batch_size)
|
||||||
.context("scanning the blockchain")?;
|
.context("scanning the blockchain")?;
|
||||||
|
@ -3,6 +3,7 @@ const SEND_AMOUNT: Amount = Amount::from_sat(5000);
|
|||||||
const STOP_GAP: usize = 50;
|
const STOP_GAP: usize = 50;
|
||||||
const BATCH_SIZE: usize = 5;
|
const BATCH_SIZE: usize = 5;
|
||||||
|
|
||||||
|
use std::io::Write;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use bdk::bitcoin::{Address, Amount};
|
use bdk::bitcoin::{Address, Amount};
|
||||||
@ -38,13 +39,19 @@ fn main() -> Result<(), anyhow::Error> {
|
|||||||
print!("Syncing...");
|
print!("Syncing...");
|
||||||
let client = electrum_client::Client::new("ssl://electrum.blockstream.info:60002")?;
|
let client = electrum_client::Client::new("ssl://electrum.blockstream.info:60002")?;
|
||||||
|
|
||||||
let request = wallet.start_full_scan().inspect_spks_for_all_keychains({
|
let request = wallet
|
||||||
let mut once = HashSet::<KeychainKind>::new();
|
.start_full_scan()
|
||||||
move |k, spk_i, _| match once.insert(k) {
|
.inspect_spks_for_all_keychains({
|
||||||
true => print!("\nScanning keychain [{:?}]", k),
|
let mut once = HashSet::<KeychainKind>::new();
|
||||||
false => print!(" {:<3}", spk_i),
|
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
|
let mut update = client
|
||||||
.full_scan(request, STOP_GAP, BATCH_SIZE)?
|
.full_scan(request, STOP_GAP, BATCH_SIZE)?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user