Skip to content
This repository has been archived by the owner on Mar 14, 2023. It is now read-only.

Commit

Permalink
RPC Example: Fix duration logging
Browse files Browse the repository at this point in the history
  • Loading branch information
evanlinjin committed Dec 21, 2022
1 parent b02e3b2 commit 35ef8ec
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions bdk_rpc_example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ fn main() -> anyhow::Result<()> {
});

let mut tip = 0;
let start_time = SystemTime::now();
let mut start_time = None;

for data in recv.iter() {
if sigterm_flag.load(Ordering::Relaxed) {
Expand All @@ -134,19 +134,25 @@ fn main() -> anyhow::Result<()> {
local_tip,
target_tip,
} => {
tip = target_tip;
let now = SystemTime::now();

println!(
"sync start: current_tip={}, target_tip={}",
local_tip, target_tip
"sync start: time={:?}, current_tip={}, target_tip={}",
now, local_tip, target_tip
);

tip = target_tip;
start_time = Some(SystemTime::now());
continue;
}
RpcData::Synced => {
let balance = keychain_tracker
.full_utxos()
.map(|(_, utxo)| utxo.txout.value)
.sum::<u64>();
let duration = SystemTime::now().duration_since(start_time)?.as_secs();
let duration = start_time
.map(|t| t.elapsed().expect("should succeed").as_secs())
.unwrap_or(0);
println!(
"sync finished: duration={}s, tip={}, balance={}sats",
duration, tip, balance
Expand Down

0 comments on commit 35ef8ec

Please sign in to comment.