@@ -42,9 +42,7 @@ use cli_table::{Cell, CellStruct, Style, Table};
4242 feature = "rpc" ,
4343 feature = "cbf"
4444) ) ]
45- use crate :: commands:: ClientType ;
46- #[ cfg( any( feature = "electrum" , feature = "esplora" , ) ) ]
47- use bdk_wallet:: event:: WalletEvent ;
45+ use { crate :: commands:: ClientType , bdk_wallet:: event:: WalletEvent } ;
4846
4947use bdk_wallet:: Wallet ;
5048#[ cfg( any( feature = "sqlite" , feature = "redb" ) ) ]
@@ -359,10 +357,12 @@ pub async fn sync_kyoto_client(
359357
360358 let update = handle. update_subscriber . lock ( ) . await . update ( ) . await ?;
361359 tracing:: info!( "Received update: applying to wallet" ) ;
362- wallet
363- . apply_update ( update)
360+ let events = wallet
361+ . apply_update_events ( update)
364362 . map_err ( |e| Error :: Generic ( format ! ( "Failed to apply update: {e}" ) ) ) ?;
365363
364+ print_wallet_events ( & events) ;
365+
366366 tracing:: info!(
367367 "Chain tip: {}, Transactions: {}, Balance: {}" ,
368368 wallet. local_chain( ) . tip( ) . height( ) ,
@@ -665,45 +665,61 @@ pub fn load_wallet_config(
665665
666666 Ok ( ( wallet_opts, network) )
667667}
668- #[ cfg( any( feature = "electrum" , feature = "esplora" , ) ) ]
669- pub fn print_wallet_events ( events : & Vec < WalletEvent > ) {
668+
669+ #[ cfg( any(
670+ feature = "electrum" ,
671+ feature = "esplora" ,
672+ feature = "cbf" ,
673+ feature = "rpc"
674+ ) ) ]
675+ pub fn print_wallet_events ( events : & [ WalletEvent ] ) {
670676 for event in events {
671677 match event {
672- WalletEvent :: TxConfirmed {
673- txid,
674- tx : _,
675- block_time,
676- old_block_time : _,
677- } => {
678+ WalletEvent :: ChainTipChanged { old_tip, new_tip } => {
678679 eprintln ! (
679- "Transaction {} confirmed in block {:? }" ,
680- txid , block_time . block_id
680+ "Chain tip advanced from height {} to { }" ,
681+ old_tip . height , new_tip . height
681682 ) ;
682683 }
684+ WalletEvent :: TxConfirmed {
685+ txid,
686+ block_time,
687+ old_block_time,
688+ ..
689+ } => match old_block_time {
690+ Some ( old) => eprintln ! (
691+ "Transaction {txid} re-confirmed at height {} (was height {}, likely a reorg)" ,
692+ block_time. block_id. height, old. block_id. height
693+ ) ,
694+ None => eprintln ! (
695+ "Transaction {txid} confirmed at height {}" ,
696+ block_time. block_id. height
697+ ) ,
698+ } ,
683699 WalletEvent :: TxUnconfirmed {
684700 txid,
685- tx : _,
686- old_block_time : _,
687- } => {
688- eprintln ! ( "Transaction {txid} became unconfirmed" ) ;
689- }
701+ old_block_time,
702+ ..
703+ } => match old_block_time {
704+ Some ( old) => eprintln ! (
705+ "Transaction {txid} became unconfirmed (was confirmed at height {}, likely a reorg)" ,
706+ old. block_id. height
707+ ) ,
708+ None => eprintln ! ( "Transaction {txid} seen in mempool" ) ,
709+ } ,
690710 WalletEvent :: TxReplaced {
691- txid,
692- tx : _,
693- conflicts : _,
711+ txid, conflicts, ..
694712 } => {
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 } => {
713+ let ids: Vec < String > = conflicts. iter ( ) . map ( |( _, c) | c. to_string ( ) ) . collect ( ) ;
701714 eprintln ! (
702- "Wallet has synced to {:?} chain tip from {:?} " ,
703- new_tip . height , old_tip . height
715+ "Transaction {txid} was replaced (conflicts with: {}) " ,
716+ ids . join ( ", " )
704717 ) ;
705718 }
706- _ => eprintln ! ( ) ,
719+ WalletEvent :: TxDropped { txid, .. } => {
720+ eprintln ! ( "Transaction {txid} dropped from the mempool" ) ;
721+ }
722+ _ => { }
707723 }
708724 }
709725}
0 commit comments