Skip to content

Commit 4eb37d3

Browse files
committed
chore: Update bdk_wallet to v2.3
- Add wallet events to full_scan and sync subcommands
1 parent 15b6f5b commit 4eb37d3

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.5", features = ["derive","env"] }
1717
dirs = { version = "6.0.0" }
1818
env_logger = "0.11.6"

src/handlers.rs

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

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

650652
#[cfg(feature = "rpc")]
@@ -1524,10 +1526,12 @@ pub async fn sync_wallet(client: &BlockchainClient, wallet: &mut Wallet) -> Resu
15241526
// already have.
15251527
client.populate_tx_cache(wallet.tx_graph().full_txs().map(|tx_node| tx_node.tx));
15261528

1527-
let update = client.sync(request, *batch_size, false)?;
1528-
wallet
1529-
.apply_update(update)
1530-
.map_err(|e| Error::Generic(e.to_string()))
1529+
let update = client.sync(request, batch_size, false)?;
1530+
let wallet_events = wallet
1531+
.apply_update_events(update)
1532+
.map_err(|e| Error::Generic(e.to_string()))?;
1533+
print_wallet_events(&wallet_events);
1534+
Ok(())
15311535
}
15321536
#[cfg(feature = "esplora")]
15331537
Esplora {
@@ -1538,9 +1542,11 @@ pub async fn sync_wallet(client: &BlockchainClient, wallet: &mut Wallet) -> Resu
15381542
.sync(request, *parallel_requests)
15391543
.await
15401544
.map_err(|e| *e)?;
1541-
wallet
1542-
.apply_update(update)
1543-
.map_err(|e| Error::Generic(e.to_string()))
1545+
let wallet_events = wallet
1546+
.apply_update_events(update)
1547+
.map_err(|e| Error::Generic(e.to_string()))?;
1548+
print_wallet_events(&wallet_events);
1549+
Ok(())
15441550
}
15451551
#[cfg(feature = "rpc")]
15461552
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)