@@ -15,6 +15,7 @@ use crate::sign::EntropySource;
15
15
use crate :: chain:: channelmonitor:: ChannelMonitor ;
16
16
use crate :: chain:: transaction:: OutPoint ;
17
17
use crate :: events:: { ClosureReason , Event , HTLCDestination , MessageSendEvent , MessageSendEventsProvider , PathFailure , PaymentPurpose , PaymentFailureReason } ;
18
+ use crate :: events:: bump_transaction:: { BumpTransactionEventHandler , Wallet , WalletSource } ;
18
19
use crate :: ln:: { PaymentPreimage , PaymentHash , PaymentSecret } ;
19
20
use crate :: ln:: channelmanager:: { AChannelManager , ChainParameters , ChannelManager , ChannelManagerReadArgs , RAACommitmentOrder , PaymentSendFailure , RecipientOnionFields , PaymentId , MIN_CLTV_EXPIRY_DELTA } ;
20
21
use crate :: routing:: gossip:: { P2PGossipSync , NetworkGraph , NetworkUpdate } ;
@@ -32,13 +33,11 @@ use crate::util::ser::{ReadableArgs, Writeable};
32
33
33
34
use bitcoin:: blockdata:: block:: { Block , BlockHeader } ;
34
35
use bitcoin:: blockdata:: transaction:: { Transaction , TxOut } ;
35
- use bitcoin:: network:: constants:: Network ;
36
-
37
36
use bitcoin:: hash_types:: BlockHash ;
38
37
use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
39
38
use bitcoin:: hashes:: Hash as _;
40
-
41
- use bitcoin:: secp256k1:: PublicKey ;
39
+ use bitcoin :: network :: constants :: Network ;
40
+ use bitcoin:: secp256k1:: { PublicKey , SecretKey } ;
42
41
43
42
use crate :: io;
44
43
use crate :: prelude:: * ;
@@ -289,6 +288,19 @@ fn do_connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: Block, sk
289
288
}
290
289
call_claimable_balances ( node) ;
291
290
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
+ }
292
304
}
293
305
294
306
pub 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> {
375
387
pub blocks : Arc < Mutex < Vec < ( Block , u32 ) > > > ,
376
388
pub connect_style : Rc < RefCell < ConnectStyle > > ,
377
389
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
+ > ,
378
397
}
379
398
impl < ' a , ' b , ' c > Node < ' a , ' b , ' c > {
380
399
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
2622
2641
2623
2642
for i in 0 ..node_count {
2624
2643
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 ( ) ) ) ;
2625
2645
nodes. push ( Node {
2626
2646
chain_source : cfgs[ i] . chain_source , tx_broadcaster : cfgs[ i] . tx_broadcaster ,
2627
2647
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
2632
2652
blocks : Arc :: clone ( & cfgs[ i] . tx_broadcaster . blocks ) ,
2633
2653
connect_style : Rc :: clone ( & connect_style) ,
2634
2654
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
+ ) ,
2635
2660
} )
2636
2661
}
2637
2662
0 commit comments