@@ -15,6 +15,7 @@ use crate::sign::EntropySource;
1515use crate :: chain:: channelmonitor:: ChannelMonitor ;
1616use crate :: chain:: transaction:: OutPoint ;
1717use crate :: events:: { ClosureReason , Event , HTLCDestination , MessageSendEvent , MessageSendEventsProvider , PathFailure , PaymentPurpose , PaymentFailureReason } ;
18+ use crate :: events:: bump_transaction:: { BumpTransactionEventHandler , Wallet , WalletSource } ;
1819use crate :: ln:: { PaymentPreimage , PaymentHash , PaymentSecret } ;
1920use crate :: ln:: channelmanager:: { AChannelManager , ChainParameters , ChannelManager , ChannelManagerReadArgs , RAACommitmentOrder , PaymentSendFailure , RecipientOnionFields , PaymentId , MIN_CLTV_EXPIRY_DELTA } ;
2021use crate :: routing:: gossip:: { P2PGossipSync , NetworkGraph , NetworkUpdate } ;
@@ -32,13 +33,11 @@ use crate::util::ser::{ReadableArgs, Writeable};
3233
3334use bitcoin:: blockdata:: block:: { Block , BlockHeader } ;
3435use bitcoin:: blockdata:: transaction:: { Transaction , TxOut } ;
35- use bitcoin:: network:: constants:: Network ;
36-
3736use bitcoin:: hash_types:: BlockHash ;
3837use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
3938use bitcoin:: hashes:: Hash as _;
40-
41- use bitcoin:: secp256k1:: PublicKey ;
39+ use bitcoin :: network :: constants :: Network ;
40+ use bitcoin:: secp256k1:: { PublicKey , SecretKey } ;
4241
4342use crate :: io;
4443use crate :: prelude:: * ;
@@ -289,6 +288,19 @@ fn do_connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: Block, sk
289288 }
290289 call_claimable_balances ( node) ;
291290 node. node . test_process_background_events ( ) ;
291+
292+ for tx in & block. txdata {
293+ for input in & tx. input {
294+ node. wallet_source . remove_utxo ( input. previous_output ) ;
295+ }
296+ let wallet_script = node. wallet_source . get_change_script ( ) . unwrap ( ) ;
297+ for ( idx, output) in tx. output . iter ( ) . enumerate ( ) {
298+ if output. script_pubkey == wallet_script {
299+ let outpoint = bitcoin:: OutPoint { txid : tx. txid ( ) , vout : idx as u32 } ;
300+ node. wallet_source . add_utxo ( outpoint, output. value ) ;
301+ }
302+ }
303+ }
292304}
293305
294306pub fn disconnect_blocks < ' a , ' b , ' c , ' d > ( node : & ' a Node < ' b , ' c , ' d > , count : u32 ) {
@@ -375,6 +387,13 @@ pub struct Node<'a, 'b: 'a, 'c: 'b> {
375387 pub blocks : Arc < Mutex < Vec < ( Block , u32 ) > > > ,
376388 pub connect_style : Rc < RefCell < ConnectStyle > > ,
377389 pub override_init_features : Rc < RefCell < Option < InitFeatures > > > ,
390+ pub wallet_source : Arc < test_utils:: TestWalletSource > ,
391+ pub bump_tx_handler : BumpTransactionEventHandler <
392+ & ' c test_utils:: TestBroadcaster ,
393+ Arc < Wallet < Arc < test_utils:: TestWalletSource > , & ' c test_utils:: TestLogger > > ,
394+ & ' b test_utils:: TestKeysInterface ,
395+ & ' c test_utils:: TestLogger ,
396+ > ,
378397}
379398impl < ' a , ' b , ' c > Node < ' a , ' b , ' c > {
380399 pub fn best_block_hash ( & self ) -> BlockHash {
@@ -2622,6 +2641,7 @@ pub fn create_network<'a, 'b: 'a, 'c: 'b>(node_count: usize, cfgs: &'b Vec<NodeC
26222641
26232642 for i in 0 ..node_count {
26242643 let gossip_sync = P2PGossipSync :: new ( cfgs[ i] . network_graph . as_ref ( ) , None , cfgs[ i] . logger ) ;
2644+ let wallet_source = Arc :: new ( test_utils:: TestWalletSource :: new ( SecretKey :: from_slice ( & [ i as u8 + 1 ; 32 ] ) . unwrap ( ) ) ) ;
26252645 nodes. push ( Node {
26262646 chain_source : cfgs[ i] . chain_source , tx_broadcaster : cfgs[ i] . tx_broadcaster ,
26272647 fee_estimator : cfgs[ i] . fee_estimator , router : & cfgs[ i] . router ,
@@ -2632,6 +2652,11 @@ pub fn create_network<'a, 'b: 'a, 'c: 'b>(node_count: usize, cfgs: &'b Vec<NodeC
26322652 blocks : Arc :: clone ( & cfgs[ i] . tx_broadcaster . blocks ) ,
26332653 connect_style : Rc :: clone ( & connect_style) ,
26342654 override_init_features : Rc :: clone ( & cfgs[ i] . override_init_features ) ,
2655+ wallet_source : Arc :: clone ( & wallet_source) ,
2656+ bump_tx_handler : BumpTransactionEventHandler :: new (
2657+ cfgs[ i] . tx_broadcaster , Arc :: new ( Wallet :: new ( Arc :: clone ( & wallet_source) , cfgs[ i] . logger ) ) ,
2658+ & cfgs[ i] . keys_manager , cfgs[ i] . logger ,
2659+ ) ,
26352660 } )
26362661 }
26372662
0 commit comments