From 06b049d7aba5919446a7851f0dc9efdd9a654052 Mon Sep 17 00:00:00 2001 From: Vihiga Tyonum Date: Wed, 11 Feb 2026 17:34:15 +0100 Subject: [PATCH] chore: Update bdk_wallet to v2.3 - Add wallet events to full_scan and sync subcommands --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/handlers.rs | 26 ++++++++++++++++---------- src/utils.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d984ac4..e20f66f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -325,9 +325,9 @@ dependencies = [ [[package]] name = "bdk_wallet" -version = "2.1.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d30b5dba770184863b5d966ccbc6a11d12c145450be3b6a4435308297e6a12dc" +checksum = "b03f1e31ccc562f600981f747d2262b84428cbff52c9c9cdf14d15fb15bd2286" dependencies = [ "bdk_chain", "bip39", diff --git a/Cargo.toml b/Cargo.toml index 4603662..b871f4b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ readme = "README.md" license = "MIT" [dependencies] -bdk_wallet = { version = "2.1.0", features = ["rusqlite", "keys-bip39", "compiler", "std"] } +bdk_wallet = { version = "2.3.0", features = ["rusqlite", "keys-bip39", "compiler", "std"] } clap = { version = "4.6", features = ["derive","env"] } clap_complete = "4.6" dirs = { version = "6.0.0" } diff --git a/src/handlers.rs b/src/handlers.rs index 7276233..a6e4e29 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -888,8 +888,9 @@ pub(crate) async fn handle_online_wallet_subcommand( client .populate_tx_cache(wallet.tx_graph().full_txs().map(|tx_node| tx_node.tx)); - let update = client.full_scan(request, _stop_gap, *batch_size, false)?; - wallet.apply_update(update)?; + let update = client.full_scan(request, _stop_gap, batch_size, false)?; + let wallet_events = wallet.apply_update_events(update)?; + print_wallet_events(&wallet_events); } #[cfg(feature = "esplora")] Esplora { @@ -900,7 +901,8 @@ pub(crate) async fn handle_online_wallet_subcommand( .full_scan(request, _stop_gap, *parallel_requests) .await .map_err(|e| *e)?; - wallet.apply_update(update)?; + let wallet_events = wallet.apply_update_events(update)?; + print_wallet_events(&wallet_events); } #[cfg(feature = "rpc")] @@ -1834,10 +1836,12 @@ pub async fn sync_wallet(client: &BlockchainClient, wallet: &mut Wallet) -> Resu // already have. client.populate_tx_cache(wallet.tx_graph().full_txs().map(|tx_node| tx_node.tx)); - let update = client.sync(request, *batch_size, false)?; - wallet - .apply_update(update) - .map_err(|e| Error::Generic(e.to_string())) + let update = client.sync(request, batch_size, false)?; + let wallet_events = wallet + .apply_update_events(update) + .map_err(|e| Error::Generic(e.to_string()))?; + print_wallet_events(&wallet_events); + Ok(()) } #[cfg(feature = "esplora")] Esplora { @@ -1848,9 +1852,11 @@ pub async fn sync_wallet(client: &BlockchainClient, wallet: &mut Wallet) -> Resu .sync(request, *parallel_requests) .await .map_err(|e| *e)?; - wallet - .apply_update(update) - .map_err(|e| Error::Generic(e.to_string())) + let wallet_events = wallet + .apply_update_events(update) + .map_err(|e| Error::Generic(e.to_string()))?; + print_wallet_events(&wallet_events); + Ok(()) } #[cfg(feature = "rpc")] RpcClient { client } => { diff --git a/src/utils.rs b/src/utils.rs index 34baf86..3f77539 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -45,6 +45,8 @@ use cli_table::{Cell, CellStruct, Style, Table}; feature = "cbf" ))] use crate::commands::ClientType; +#[cfg(any(feature = "electrum", feature = "esplora",))] +use bdk_wallet::event::WalletEvent; use bdk_wallet::Wallet; #[cfg(any(feature = "sqlite", feature = "redb"))] @@ -704,3 +706,45 @@ pub fn load_wallet_config( Ok((wallet_opts, network)) } +#[cfg(any(feature = "electrum", feature = "esplora",))] +pub fn print_wallet_events(events: &Vec) { + for event in events { + match event { + WalletEvent::TxConfirmed { + txid, + tx: _, + block_time, + old_block_time: _, + } => { + eprintln!( + "Transaction {} confirmed in block {:?}", + txid, block_time.block_id + ); + } + WalletEvent::TxUnconfirmed { + txid, + tx: _, + old_block_time: _, + } => { + eprintln!("Transaction {txid} became unconfirmed"); + } + WalletEvent::TxReplaced { + txid, + tx: _, + conflicts: _, + } => { + eprintln!("Received new transaction: {txid}"); + } + WalletEvent::TxDropped { txid, tx: _ } => { + eprintln!("Transaction {txid} has been dropped"); + } + WalletEvent::ChainTipChanged { old_tip, new_tip } => { + eprintln!( + "Wallet has synced to {:?} chain tip from {:?}", + new_tip.height, old_tip.height + ); + } + _ => eprintln!(), + } + } +} -- 2.49.0