[[package]]
name = "bdk_wallet"
-version = "2.3.0"
+version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b03f1e31ccc562f600981f747d2262b84428cbff52c9c9cdf14d15fb15bd2286"
+checksum = "c99821af39c7df004bd411ece2ef22d9fba5a631b4489f3d9a0ac0d19637e2d0"
dependencies = [
"bdk_chain",
"bip39",
license = "MIT"
[dependencies]
-bdk_wallet = { version = "2.3.0", features = ["rusqlite", "keys-bip39", "compiler", "std"] }
+bdk_wallet = { version = "2.4.0", features = ["rusqlite", "keys-bip39", "compiler", "std"] }
clap = { version = "4.6", features = ["derive","env"] }
clap_complete = "4.6"
dirs = { version = "6.0.0" }
NO_EXPECTED_MEMPOOL_TXS,
);
- while let Some(block_event) = emitter.next_block()? {
- if block_event.block_height() % 10_000 == 0 {
- let percent_done = f64::from(block_event.block_height())
- / f64::from(blockchain_info.headers as u32)
- * 100f64;
- println!(
- "Applying block at height: {}, {:.2}% done.",
+ let block_events = wallet.events_helper(|w| {
+ while let Some(block_event) = emitter.next_block()? {
+ if block_event.block_height() % 10_000 == 0 {
+ let percent_done = f64::from(block_event.block_height())
+ / f64::from(blockchain_info.headers as u32)
+ * 100f64;
+ println!(
+ "Applying block at height: {}, {:.2}% done.",
+ block_event.block_height(),
+ percent_done
+ );
+ }
+
+ w.apply_block_connected_to(
+ &block_event.block,
block_event.block_height(),
- percent_done
- );
+ block_event.connected_to(),
+ )?;
}
-
- wallet.apply_block_connected_to(
- &block_event.block,
- block_event.block_height(),
- block_event.connected_to(),
- )?;
- }
+ Ok::<_, Error>(())
+ })?;
+ print_wallet_events(&block_events);
let mempool_txs = emitter.mempool()?;
- wallet.apply_unconfirmed_txs(mempool_txs.update);
+ let mempool_events = wallet.apply_unconfirmed_txs_events(mempool_txs.update);
+ print_wallet_events(&mempool_events);
+
+ let evicted_events = wallet.apply_evicted_txs_events(mempool_txs.evicted);
+ print_wallet_events(&evicted_events);
}
#[cfg(feature = "cbf")]
KyotoClient { client } => {
.filter(|tx| tx.chain_position.is_unconfirmed()),
);
- while let Some(block_event) = emitter.next_block()? {
- if block_event.block_height() % 10_000 == 0 {
- let percent_done = f64::from(block_event.block_height())
- / f64::from(blockchain_info.headers as u32)
- * 100f64;
- println!(
- "Applying block at height: {}, {:.2}% done.",
+ let block_events = wallet.events_helper(|w| {
+ while let Some(block_event) = emitter.next_block()? {
+ if block_event.block_height() % 10_000 == 0 {
+ let percent_done = f64::from(block_event.block_height())
+ / f64::from(blockchain_info.headers as u32)
+ * 100f64;
+ println!(
+ "Applying block at height: {}, {:.2}% done.",
+ block_event.block_height(),
+ percent_done
+ );
+ }
+ w.apply_block_connected_to(
+ &block_event.block,
block_event.block_height(),
- percent_done
- );
+ block_event.connected_to(),
+ )?;
}
-
- wallet.apply_block_connected_to(
- &block_event.block,
- block_event.block_height(),
- block_event.connected_to(),
- )?;
- }
+ Ok::<_, Error>(())
+ })?;
+ print_wallet_events(&block_events);
let mempool_txs = emitter.mempool()?;
- wallet.apply_unconfirmed_txs(mempool_txs.update);
+ let mempool_events = wallet.apply_unconfirmed_txs_events(mempool_txs.update);
+ print_wallet_events(&mempool_events);
+
+ let evicted_events = wallet.apply_evicted_txs_events(mempool_txs.evicted);
+ print_wallet_events(&evicted_events);
Ok(())
}
#[cfg(feature = "cbf")]
feature = "rpc",
feature = "cbf"
))]
-use crate::commands::ClientType;
-#[cfg(any(feature = "electrum", feature = "esplora",))]
-use bdk_wallet::event::WalletEvent;
+use {crate::commands::ClientType, bdk_wallet::event::WalletEvent};
use bdk_wallet::Wallet;
#[cfg(any(feature = "sqlite", feature = "redb"))]
let update = handle.update_subscriber.lock().await.update().await?;
tracing::info!("Received update: applying to wallet");
- wallet
- .apply_update(update)
+ let events = wallet
+ .apply_update_events(update)
.map_err(|e| Error::Generic(format!("Failed to apply update: {e}")))?;
+ print_wallet_events(&events);
+
tracing::info!(
"Chain tip: {}, Transactions: {}, Balance: {}",
wallet.local_chain().tip().height(),
Ok((wallet_opts, network))
}
-#[cfg(any(feature = "electrum", feature = "esplora",))]
-pub fn print_wallet_events(events: &Vec<WalletEvent>) {
+
+#[cfg(any(
+ feature = "electrum",
+ feature = "esplora",
+ feature = "cbf",
+ feature = "rpc"
+))]
+pub fn print_wallet_events(events: &[WalletEvent]) {
for event in events {
match event {
- WalletEvent::TxConfirmed {
- txid,
- tx: _,
- block_time,
- old_block_time: _,
- } => {
+ WalletEvent::ChainTipChanged { old_tip, new_tip } => {
eprintln!(
- "Transaction {} confirmed in block {:?}",
- txid, block_time.block_id
+ "Chain tip advanced from height {} to {}",
+ old_tip.height, new_tip.height
);
}
+ WalletEvent::TxConfirmed {
+ txid,
+ block_time,
+ old_block_time,
+ ..
+ } => match old_block_time {
+ Some(old) => eprintln!(
+ "Transaction {txid} re-confirmed at height {} (was height {}, likely a reorg)",
+ block_time.block_id.height, old.block_id.height
+ ),
+ None => eprintln!(
+ "Transaction {txid} confirmed at height {}",
+ block_time.block_id.height
+ ),
+ },
WalletEvent::TxUnconfirmed {
txid,
- tx: _,
- old_block_time: _,
- } => {
- eprintln!("Transaction {txid} became unconfirmed");
- }
+ old_block_time,
+ ..
+ } => match old_block_time {
+ Some(old) => eprintln!(
+ "Transaction {txid} became unconfirmed (was confirmed at height {}, likely a reorg)",
+ old.block_id.height
+ ),
+ None => eprintln!("Transaction {txid} seen in mempool"),
+ },
WalletEvent::TxReplaced {
- txid,
- tx: _,
- conflicts: _,
+ txid, conflicts, ..
} => {
- eprintln!("Received new transaction: {txid}");
- }
- WalletEvent::TxDropped { txid, tx: _ } => {
- eprintln!("Transaction {txid} has been dropped");
- }
- WalletEvent::ChainTipChanged { old_tip, new_tip } => {
+ let ids: Vec<String> = conflicts.iter().map(|(_, c)| c.to_string()).collect();
eprintln!(
- "Wallet has synced to {:?} chain tip from {:?}",
- new_tip.height, old_tip.height
+ "Transaction {txid} was replaced (conflicts with: {})",
+ ids.join(", ")
);
}
- _ => eprintln!(),
+ WalletEvent::TxDropped { txid, .. } => {
+ eprintln!("Transaction {txid} dropped from the mempool");
+ }
+ _ => {}
}
}
}