@@ -17,9 +17,9 @@ use bitcoin::block::Header;
17
17
use bitcoin:: constants:: genesis_block;
18
18
use bitcoin:: network:: Network ;
19
19
use bitcoin:: { Amount , BlockHash , Txid } ;
20
- use bitcoind :: bitcoincore_rpc :: RpcApi ;
21
- use electrsd:: bitcoind :: bitcoincore_rpc :: bitcoincore_rpc_json :: AddressType ;
22
- use electrsd:: { bitcoind , bitcoind :: BitcoinD , ElectrsD } ;
20
+
21
+ use electrsd:: corepc_node :: Node as BitcoinD ;
22
+ use electrsd:: { corepc_node , ElectrsD } ;
23
23
24
24
use std:: collections:: { HashMap , HashSet } ;
25
25
use std:: env;
@@ -28,10 +28,10 @@ use std::time::Duration;
28
28
29
29
pub fn setup_bitcoind_and_electrsd ( ) -> ( BitcoinD , ElectrsD ) {
30
30
let bitcoind_exe =
31
- env:: var ( "BITCOIND_EXE" ) . ok ( ) . or_else ( || bitcoind :: downloaded_exe_path ( ) . ok ( ) ) . expect (
31
+ env:: var ( "BITCOIND_EXE" ) . ok ( ) . or_else ( || corepc_node :: downloaded_exe_path ( ) . ok ( ) ) . expect (
32
32
"you need to provide an env var BITCOIND_EXE or specify a bitcoind version feature" ,
33
33
) ;
34
- let mut bitcoind_conf = bitcoind :: Conf :: default ( ) ;
34
+ let mut bitcoind_conf = corepc_node :: Conf :: default ( ) ;
35
35
bitcoind_conf. network = "regtest" ;
36
36
let bitcoind = BitcoinD :: with_conf ( bitcoind_exe, & bitcoind_conf) . unwrap ( ) ;
37
37
@@ -47,14 +47,15 @@ pub fn setup_bitcoind_and_electrsd() -> (BitcoinD, ElectrsD) {
47
47
}
48
48
49
49
pub fn generate_blocks_and_wait ( bitcoind : & BitcoinD , electrsd : & ElectrsD , num : usize ) {
50
- let cur_height = bitcoind. client . get_block_count ( ) . expect ( "failed to get current block height" ) ;
51
- let address = bitcoind
50
+ let cur_height = bitcoind
52
51
. client
53
- . get_new_address ( Some ( "test" ) , Some ( AddressType :: Legacy ) )
54
- . expect ( "failed to get new address" )
55
- . assume_checked ( ) ;
52
+ . get_block_count ( )
53
+ . expect ( "failed to get current block height" )
54
+ . into_model ( )
55
+ . 0 ;
56
+ let address = bitcoind. client . new_address ( ) . expect ( "failed to get new address" ) ;
56
57
// TODO: expect this Result once the WouldBlock issue is resolved upstream.
57
- let _block_hashes_res = bitcoind. client . generate_to_address ( num as u64 , & address) ;
58
+ let _block_hashes_res = bitcoind. client . generate_to_address ( num, & address) ;
58
59
wait_for_block ( electrsd, cur_height as usize + num) ;
59
60
}
60
61
@@ -175,36 +176,20 @@ macro_rules! test_syncing {
175
176
assert_eq!( events. len( ) , 1 ) ;
176
177
177
178
// Check registered confirmed transactions are marked confirmed
178
- let new_address = $bitcoind
179
- . client
180
- . get_new_address( Some ( "test" ) , Some ( AddressType :: Legacy ) )
181
- . unwrap( )
182
- . assume_checked( ) ;
179
+ let new_address = $bitcoind. client. new_address( ) . unwrap( ) ;
183
180
let txid = $bitcoind
184
181
. client
185
- . send_to_address(
186
- & new_address,
187
- Amount :: from_sat( 5000 ) ,
188
- None ,
189
- None ,
190
- None ,
191
- None ,
192
- None ,
193
- None ,
194
- )
182
+ . send_to_address( & new_address, Amount :: from_sat( 5000 ) )
183
+ . unwrap( )
184
+ . 0
185
+ . parse( )
195
186
. unwrap( ) ;
196
187
let second_txid = $bitcoind
197
188
. client
198
- . send_to_address(
199
- & new_address,
200
- Amount :: from_sat( 5000 ) ,
201
- None ,
202
- None ,
203
- None ,
204
- None ,
205
- None ,
206
- None ,
207
- )
189
+ . send_to_address( & new_address, Amount :: from_sat( 5000 ) )
190
+ . unwrap( )
191
+ . 0
192
+ . parse( )
208
193
. unwrap( ) ;
209
194
$tx_sync. register_tx( & txid, & new_address. script_pubkey( ) ) ;
210
195
@@ -224,16 +209,12 @@ macro_rules! test_syncing {
224
209
assert!( $confirmable. unconfirmed_txs. lock( ) . unwrap( ) . is_empty( ) ) ;
225
210
226
211
// Now take an arbitrary output of the second transaction and check we'll confirm its spend.
227
- let tx_res = $bitcoind. client. get_transaction( & second_txid, None ) . unwrap( ) ;
228
- let block_hash = tx_res. info . blockhash . unwrap( ) ;
229
- let tx = tx_res. transaction ( ) . unwrap ( ) ;
212
+ let tx_res = $bitcoind. client. get_transaction( second_txid) . unwrap ( ) . into_model ( ) . unwrap( ) ;
213
+ let block_hash = tx_res. block_hash . unwrap( ) ;
214
+ let tx = tx_res. tx ;
230
215
let prev_outpoint = tx. input. first( ) . unwrap( ) . previous_output;
231
- let prev_tx = $bitcoind
232
- . client
233
- . get_transaction( & prev_outpoint. txid, None )
234
- . unwrap( )
235
- . transaction( )
236
- . unwrap( ) ;
216
+ let prev_tx =
217
+ $bitcoind. client. get_transaction( prev_outpoint. txid) . unwrap( ) . into_model( ) . unwrap( ) . tx;
237
218
let prev_script_pubkey = prev_tx. output[ prev_outpoint. vout as usize ] . script_pubkey. clone( ) ;
238
219
let output = WatchedOutput {
239
220
block_hash: Some ( block_hash) ,
@@ -251,19 +232,26 @@ macro_rules! test_syncing {
251
232
assert!( $confirmable. unconfirmed_txs. lock( ) . unwrap( ) . is_empty( ) ) ;
252
233
253
234
// Check previously confirmed transactions are marked unconfirmed when they are reorged.
254
- let best_block_hash = $bitcoind. client. get_best_block_hash( ) . unwrap( ) ;
255
- $bitcoind. client. invalidate_block( & best_block_hash) . unwrap( ) ;
235
+ let best_block_hash =
236
+ $bitcoind. client. get_best_block_hash( ) . unwrap( ) . into_model( ) . unwrap( ) . 0 ;
237
+ $bitcoind. client. invalidate_block( best_block_hash) . unwrap( ) ;
256
238
257
239
// We're getting back to the previous height with a new tip, but best block shouldn't change.
258
240
generate_blocks_and_wait( & $bitcoind, & $electrsd, 1 ) ;
259
- assert_ne!( $bitcoind. client. get_best_block_hash( ) . unwrap( ) , best_block_hash) ;
241
+ assert_ne!(
242
+ $bitcoind. client. get_best_block_hash( ) . unwrap( ) . into_model( ) . unwrap( ) . 0 ,
243
+ best_block_hash
244
+ ) ;
260
245
maybe_await!( $tx_sync. sync( vec![ & $confirmable] ) ) . unwrap( ) ;
261
246
let events = std:: mem:: take( & mut * $confirmable. events. lock( ) . unwrap( ) ) ;
262
247
assert_eq!( events. len( ) , 0 ) ;
263
248
264
249
// Now we're surpassing previous height, getting new tip.
265
250
generate_blocks_and_wait( & $bitcoind, & $electrsd, 1 ) ;
266
- assert_ne!( $bitcoind. client. get_best_block_hash( ) . unwrap( ) , best_block_hash) ;
251
+ assert_ne!(
252
+ $bitcoind. client. get_best_block_hash( ) . unwrap( ) . into_model( ) . unwrap( ) . 0 ,
253
+ best_block_hash
254
+ ) ;
267
255
maybe_await!( $tx_sync. sync( vec![ & $confirmable] ) ) . unwrap( ) ;
268
256
269
257
// Transactions still confirmed but under new tip.
0 commit comments