Skip to content

Commit b71dafc

Browse files
committed
chore: Update bdk_wallet to v2.3
- Add wallet events to full_scan and sync subcommands
1 parent 1dc41d0 commit b71dafc

File tree

4 files changed

+63
-13
lines changed

4 files changed

+63
-13
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ readme = "README.md"
1212
license = "MIT"
1313

1414
[dependencies]
15-
bdk_wallet = { version = "2.1.0", features = ["rusqlite", "keys-bip39", "compiler", "std"] }
15+
bdk_wallet = { version = "2.3.0", features = ["rusqlite", "keys-bip39", "compiler", "std"] }
1616
clap = { version = "4.6", features = ["derive","env"] }
1717
clap_complete = "4.6"
1818
dirs = { version = "6.0.0" }

src/handlers.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,9 @@ pub(crate) async fn handle_online_wallet_subcommand(
633633
client
634634
.populate_tx_cache(wallet.tx_graph().full_txs().map(|tx_node| tx_node.tx));
635635

636-
let update = client.full_scan(request, _stop_gap, *batch_size, false)?;
637-
wallet.apply_update(update)?;
636+
let update = client.full_scan(request, _stop_gap, batch_size, false)?;
637+
let wallet_events = wallet.apply_update_events(update)?;
638+
print_wallet_events(&wallet_events);
638639
}
639640
#[cfg(feature = "esplora")]
640641
Esplora {
@@ -645,7 +646,8 @@ pub(crate) async fn handle_online_wallet_subcommand(
645646
.full_scan(request, _stop_gap, *parallel_requests)
646647
.await
647648
.map_err(|e| *e)?;
648-
wallet.apply_update(update)?;
649+
let wallet_events = wallet.apply_update_events(update)?;
650+
print_wallet_events(&wallet_events);
649651
}
650652

651653
#[cfg(feature = "rpc")]
@@ -1535,10 +1537,12 @@ pub async fn sync_wallet(client: &BlockchainClient, wallet: &mut Wallet) -> Resu
15351537
// already have.
15361538
client.populate_tx_cache(wallet.tx_graph().full_txs().map(|tx_node| tx_node.tx));
15371539

1538-
let update = client.sync(request, *batch_size, false)?;
1539-
wallet
1540-
.apply_update(update)
1541-
.map_err(|e| Error::Generic(e.to_string()))
1540+
let update = client.sync(request, batch_size, false)?;
1541+
let wallet_events = wallet
1542+
.apply_update_events(update)
1543+
.map_err(|e| Error::Generic(e.to_string()))?;
1544+
print_wallet_events(&wallet_events);
1545+
Ok(())
15421546
}
15431547
#[cfg(feature = "esplora")]
15441548
Esplora {
@@ -1549,9 +1553,11 @@ pub async fn sync_wallet(client: &BlockchainClient, wallet: &mut Wallet) -> Resu
15491553
.sync(request, *parallel_requests)
15501554
.await
15511555
.map_err(|e| *e)?;
1552-
wallet
1553-
.apply_update(update)
1554-
.map_err(|e| Error::Generic(e.to_string()))
1556+
let wallet_events = wallet
1557+
.apply_update_events(update)
1558+
.map_err(|e| Error::Generic(e.to_string()))?;
1559+
print_wallet_events(&wallet_events);
1560+
Ok(())
15551561
}
15561562
#[cfg(feature = "rpc")]
15571563
RpcClient { client } => {

src/utils.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ use cli_table::{Cell, CellStruct, Style, Table};
4343
feature = "cbf"
4444
))]
4545
use crate::commands::ClientType;
46+
#[cfg(any(feature = "electrum", feature = "esplora",))]
47+
use bdk_wallet::event::WalletEvent;
4648

4749
use bdk_wallet::Wallet;
4850
#[cfg(any(feature = "sqlite", feature = "redb"))]
@@ -663,3 +665,45 @@ pub fn load_wallet_config(
663665

664666
Ok((wallet_opts, network))
665667
}
668+
#[cfg(any(feature = "electrum", feature = "esplora",))]
669+
pub fn print_wallet_events(events: &Vec<WalletEvent>) {
670+
for event in events {
671+
match event {
672+
WalletEvent::TxConfirmed {
673+
txid,
674+
tx: _,
675+
block_time,
676+
old_block_time: _,
677+
} => {
678+
eprintln!(
679+
"Transaction {} confirmed in block {:?}",
680+
txid, block_time.block_id
681+
);
682+
}
683+
WalletEvent::TxUnconfirmed {
684+
txid,
685+
tx: _,
686+
old_block_time: _,
687+
} => {
688+
eprintln!("Transaction {txid} became unconfirmed");
689+
}
690+
WalletEvent::TxReplaced {
691+
txid,
692+
tx: _,
693+
conflicts: _,
694+
} => {
695+
eprintln!("Received new transaction: {txid}");
696+
}
697+
WalletEvent::TxDropped { txid, tx: _ } => {
698+
eprintln!("Transaction {txid} has been dropped");
699+
}
700+
WalletEvent::ChainTipChanged { old_tip, new_tip } => {
701+
eprintln!(
702+
"Wallet has synced to {:?} chain tip from {:?}",
703+
new_tip.height, old_tip.height
704+
);
705+
}
706+
_ => eprintln!(),
707+
}
708+
}
709+
}

0 commit comments

Comments
 (0)