1- #![ cfg( all( not( target_os = "windows" ) , any( feature = "esplora-blocking" , feature = "esplora-async" , feature = "electrum" ) ) ) ]
1+ #![ cfg( all(
2+ not( target_os = "windows" ) ,
3+ any( feature = "esplora-blocking" , feature = "esplora-async" , feature = "electrum" )
4+ ) ) ]
25
3- #[ cfg( any( feature = "esplora-blocking" , feature = "esplora-async" ) ) ]
4- use lightning_transaction_sync:: EsploraSyncClient ;
5- #[ cfg( feature = "electrum" ) ]
6- use lightning_transaction_sync:: ElectrumSyncClient ;
7- use lightning:: chain:: { Confirm , Filter , WatchedOutput } ;
86use lightning:: chain:: transaction:: { OutPoint , TransactionData } ;
7+ use lightning:: chain:: { Confirm , Filter , WatchedOutput } ;
98use lightning:: util:: test_utils:: TestLogger ;
9+ #[ cfg( feature = "electrum" ) ]
10+ use lightning_transaction_sync:: ElectrumSyncClient ;
11+ #[ cfg( any( feature = "esplora-blocking" , feature = "esplora-async" ) ) ]
12+ use lightning_transaction_sync:: EsploraSyncClient ;
1013
11- use electrsd:: { bitcoind, bitcoind:: BitcoinD , ElectrsD } ;
12- use bitcoin:: { Amount , Txid , BlockHash } ;
14+ use bdk_macros:: maybe_await;
1315use bitcoin:: blockdata:: block:: Header ;
1416use bitcoin:: blockdata:: constants:: genesis_block;
1517use bitcoin:: network:: Network ;
16- use electrsd :: bitcoind :: bitcoincore_rpc :: bitcoincore_rpc_json :: AddressType ;
18+ use bitcoin :: { Amount , BlockHash , Txid } ;
1719use bitcoind:: bitcoincore_rpc:: RpcApi ;
18- use bdk_macros:: maybe_await;
20+ use electrsd:: bitcoind:: bitcoincore_rpc:: bitcoincore_rpc_json:: AddressType ;
21+ use electrsd:: { bitcoind, bitcoind:: BitcoinD , ElectrsD } ;
1922
23+ use std:: collections:: { HashMap , HashSet } ;
2024use std:: env;
2125use std:: sync:: Mutex ;
2226use std:: time:: Duration ;
23- use std:: collections:: { HashMap , HashSet } ;
2427
2528pub fn setup_bitcoind_and_electrsd ( ) -> ( BitcoinD , ElectrsD ) {
2629 let bitcoind_exe =
@@ -63,8 +66,11 @@ pub fn wait_for_block(electrsd: &ElectrsD, min_height: usize) {
6366 // it didn't. Since we can't proceed without subscribing, we try again after a delay
6467 // and panic if it still fails.
6568 std:: thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
66- electrsd. client . block_headers_subscribe_raw ( ) . expect ( "failed to subscribe to block headers" )
67- }
69+ electrsd
70+ . client
71+ . block_headers_subscribe_raw ( )
72+ . expect ( "failed to subscribe to block headers" )
73+ } ,
6874 } ;
6975 loop {
7076 if header. height >= min_height {
9096 None if delay. as_millis ( ) < 512 => {
9197 delay = delay. mul_f32 ( 2.0 ) ;
9298 tries += 1 ;
93- }
99+ } ,
94100 None if tries == 10 => panic ! ( "Exceeded our maximum wait time." ) ,
95101 None => tries += 1 ,
96102 }
@@ -132,7 +138,8 @@ impl Confirm for TestConfirmable {
132138 let block_hash = header. block_hash ( ) ;
133139 self . confirmed_txs . lock ( ) . unwrap ( ) . insert ( txid, ( block_hash, height) ) ;
134140 self . unconfirmed_txs . lock ( ) . unwrap ( ) . remove ( & txid) ;
135- self . events . lock ( ) . unwrap ( ) . push ( TestConfirmableEvent :: Confirmed ( txid, block_hash, height) ) ;
141+ let event = TestConfirmableEvent :: Confirmed ( txid, block_hash, height) ;
142+ self . events . lock ( ) . unwrap ( ) . push ( event) ;
136143 }
137144 }
138145
@@ -145,11 +152,13 @@ impl Confirm for TestConfirmable {
145152 fn best_block_updated ( & self , header : & Header , height : u32 ) {
146153 let block_hash = header. block_hash ( ) ;
147154 * self . best_block . lock ( ) . unwrap ( ) = ( block_hash, height) ;
148- self . events . lock ( ) . unwrap ( ) . push ( TestConfirmableEvent :: BestBlockUpdated ( block_hash, height) ) ;
155+ let event = TestConfirmableEvent :: BestBlockUpdated ( block_hash, height) ;
156+ self . events . lock ( ) . unwrap ( ) . push ( event) ;
149157 }
150158
151159 fn get_relevant_txids ( & self ) -> Vec < ( Txid , u32 , Option < BlockHash > ) > {
152- self . confirmed_txs . lock ( ) . unwrap ( ) . iter ( ) . map ( |( & txid, ( hash, height) ) | ( txid, * height, Some ( * hash) ) ) . collect :: < Vec < _ > > ( )
160+ let lock = self . confirmed_txs . lock ( ) . unwrap ( ) ;
161+ lock. iter ( ) . map ( |( & txid, ( hash, height) ) | ( txid, * height, Some ( * hash) ) ) . collect ( )
153162 }
154163}
155164
@@ -165,12 +174,37 @@ macro_rules! test_syncing {
165174 assert_eq!( events. len( ) , 1 ) ;
166175
167176 // Check registered confirmed transactions are marked confirmed
168- let new_address = $bitcoind. client. get_new_address( Some ( "test" ) ,
169- Some ( AddressType :: Legacy ) ) . unwrap( ) . assume_checked( ) ;
170- let txid = $bitcoind. client. send_to_address( & new_address, Amount :: from_sat( 5000 ) , None , None ,
171- None , None , None , None ) . unwrap( ) ;
172- let second_txid = $bitcoind. client. send_to_address( & new_address, Amount :: from_sat( 5000 ) , None ,
173- None , None , None , None , None ) . unwrap( ) ;
177+ let new_address = $bitcoind
178+ . client
179+ . get_new_address( Some ( "test" ) , Some ( AddressType :: Legacy ) )
180+ . unwrap( )
181+ . assume_checked( ) ;
182+ let txid = $bitcoind
183+ . client
184+ . send_to_address(
185+ & new_address,
186+ Amount :: from_sat( 5000 ) ,
187+ None ,
188+ None ,
189+ None ,
190+ None ,
191+ None ,
192+ None ,
193+ )
194+ . unwrap( ) ;
195+ let second_txid = $bitcoind
196+ . client
197+ . send_to_address(
198+ & new_address,
199+ Amount :: from_sat( 5000 ) ,
200+ None ,
201+ None ,
202+ None ,
203+ None ,
204+ None ,
205+ None ,
206+ )
207+ . unwrap( ) ;
174208 $tx_sync. register_tx( & txid, & new_address. payload( ) . script_pubkey( ) ) ;
175209
176210 maybe_await!( $tx_sync. sync( vec![ & $confirmable] ) ) . unwrap( ) ;
@@ -193,13 +227,17 @@ macro_rules! test_syncing {
193227 let block_hash = tx_res. info. blockhash. unwrap( ) ;
194228 let tx = tx_res. transaction( ) . unwrap( ) ;
195229 let prev_outpoint = tx. input. first( ) . unwrap( ) . previous_output;
196- let prev_tx = $bitcoind. client. get_transaction( & prev_outpoint. txid, None ) . unwrap( ) . transaction( )
230+ let prev_tx = $bitcoind
231+ . client
232+ . get_transaction( & prev_outpoint. txid, None )
233+ . unwrap( )
234+ . transaction( )
197235 . unwrap( ) ;
198236 let prev_script_pubkey = prev_tx. output[ prev_outpoint. vout as usize ] . script_pubkey. clone( ) ;
199237 let output = WatchedOutput {
200238 block_hash: Some ( block_hash) ,
201239 outpoint: OutPoint { txid: prev_outpoint. txid, index: prev_outpoint. vout as u16 } ,
202- script_pubkey: prev_script_pubkey
240+ script_pubkey: prev_script_pubkey,
203241 } ;
204242
205243 $tx_sync. register_output( output) ;
0 commit comments