@@ -2576,23 +2576,39 @@ impl Wallet {
25762576 block : & Block ,
25772577 height : u32 ,
25782578 ) -> Result < Vec < WalletEvent > , CannotConnectError > {
2579- let connected_to = match height. checked_sub ( 1 ) {
2580- Some ( prev_height) => BlockId {
2581- height : prev_height,
2582- hash : block. header . prev_blockhash ,
2583- } ,
2584- None => BlockId {
2585- height,
2586- hash : block. block_hash ( ) ,
2587- } ,
2588- } ;
2589- self . apply_block_connected_to_events ( block, height, connected_to)
2590- . map_err ( |err| match err {
2591- ApplyHeaderError :: InconsistentBlocks => {
2592- unreachable ! ( "connected_to is derived from the block so must be consistent" )
2593- }
2594- ApplyHeaderError :: CannotConnect ( err) => err,
2579+ // snapshot of chain tip and transactions before update
2580+ let chain_tip1 = self . chain . tip ( ) . block_id ( ) ;
2581+ let wallet_txs1 = self
2582+ . transactions ( )
2583+ . map ( |wtx| {
2584+ (
2585+ wtx. tx_node . txid ,
2586+ ( wtx. tx_node . tx . clone ( ) , wtx. chain_position ) ,
2587+ )
25952588 } )
2589+ . collect :: < BTreeMap < Txid , ( Arc < Transaction > , ChainPosition < ConfirmationBlockTime > ) > > ( ) ;
2590+
2591+ self . apply_block ( block, height) ?;
2592+
2593+ // chain tip and transactions after update
2594+ let chain_tip2 = self . chain . tip ( ) . block_id ( ) ;
2595+ let wallet_txs2 = self
2596+ . transactions ( )
2597+ . map ( |wtx| {
2598+ (
2599+ wtx. tx_node . txid ,
2600+ ( wtx. tx_node . tx . clone ( ) , wtx. chain_position ) ,
2601+ )
2602+ } )
2603+ . collect :: < BTreeMap < Txid , ( Arc < Transaction > , ChainPosition < ConfirmationBlockTime > ) > > ( ) ;
2604+
2605+ Ok ( wallet_events (
2606+ self ,
2607+ chain_tip1,
2608+ chain_tip2,
2609+ wallet_txs1,
2610+ wallet_txs2,
2611+ ) )
25962612 }
25972613
25982614 /// Applies relevant transactions from `block` of `height` to the wallet, and connects the
0 commit comments