6
6
7
7
use std:: collections:: BTreeMap ;
8
8
use std:: { error, fmt} ;
9
+ use std:: convert:: TryInto ;
9
10
10
11
use actual_rand as rand;
11
12
use bitcoin:: blockdata:: witness:: Witness ;
@@ -17,7 +18,8 @@ use bitcoin::{
17
18
absolute, psbt, secp256k1, sighash, transaction, Amount , OutPoint , Sequence , Transaction , TxIn ,
18
19
TxOut , Txid ,
19
20
} ;
20
- use bitcoind:: bitcoincore_rpc:: { json, Client , RpcApi } ;
21
+ use bitcoind:: client:: json:: model; // FIXME: Re-export this from someplace easier.
22
+ use bitcoind:: { Client , AddressType } ;
21
23
use miniscript:: bitcoin:: { self , ecdsa, taproot, ScriptBuf } ;
22
24
use miniscript:: psbt:: { PsbtExt , PsbtInputExt } ;
23
25
use miniscript:: { Descriptor , Miniscript , ScriptContext , ToPublicKey } ;
@@ -30,11 +32,10 @@ fn btc<F: Into<f64>>(btc: F) -> Amount { Amount::from_btc(btc.into()).unwrap() }
30
32
31
33
// Find the Outpoint by spk
32
34
fn get_vout ( cl : & Client , txid : Txid , value : Amount , spk : ScriptBuf ) -> ( OutPoint , TxOut ) {
33
- let tx = cl
34
- . get_transaction ( & txid, None )
35
- . unwrap ( )
36
- . transaction ( )
37
- . unwrap ( ) ;
35
+ let json = cl. get_transaction ( txid) . unwrap ( ) ;
36
+ let concrete: model:: GetTransaction = json. try_into ( ) . unwrap ( ) ;
37
+ let tx = concrete. tx ;
38
+
38
39
for ( i, txout) in tx. output . into_iter ( ) . enumerate ( ) {
39
40
if txout. value == value && spk == txout. script_pubkey {
40
41
return ( OutPoint :: new ( txid, i as u32 ) , txout) ;
@@ -77,9 +78,9 @@ pub fn test_desc_satisfy(
77
78
let x_only_pks = & testdata. pubdata . x_only_pks ;
78
79
// Generate some blocks
79
80
let blocks = cl
80
- . generate_to_address ( 1 , & cl. get_new_address ( None , None ) . unwrap ( ) . assume_checked ( ) )
81
+ . generate_to_address ( 1 , & cl. new_address ( ) . unwrap ( ) )
81
82
. unwrap ( ) ;
82
- assert_eq ! ( blocks. len( ) , 1 ) ;
83
+ assert_eq ! ( blocks. 0 . len( ) , 1 ) ;
83
84
84
85
let definite_desc = test_util:: parse_test_desc ( descriptor, & testdata. pubdata )
85
86
. map_err ( |_| DescError :: DescParseError ) ?
@@ -92,13 +93,13 @@ pub fn test_desc_satisfy(
92
93
93
94
// Next send some btc to each address corresponding to the miniscript
94
95
let txid = cl
95
- . send_to_address ( & desc_address, btc ( 1 ) , None , None , None , None , None , None )
96
+ . send_to_address ( & desc_address, btc ( 1 ) )
96
97
. unwrap ( ) ;
97
98
// Wait for the funds to mature.
98
99
let blocks = cl
99
- . generate_to_address ( 2 , & cl. get_new_address ( None , None ) . unwrap ( ) . assume_checked ( ) )
100
+ . generate_to_address ( 2 , & cl. new_address ( ) . unwrap ( ) )
100
101
. unwrap ( ) ;
101
- assert_eq ! ( blocks. len( ) , 2 ) ;
102
+ assert_eq ! ( blocks. 0 . len( ) , 2 ) ;
102
103
// Create a PSBT for each transaction.
103
104
// Spend one input and spend one output for simplicity.
104
105
let mut psbt = Psbt {
@@ -130,9 +131,8 @@ pub fn test_desc_satisfy(
130
131
// the node wallet tracks the receiving transaction
131
132
// and we can check it by gettransaction RPC.
132
133
let addr = cl
133
- . get_new_address ( None , Some ( json:: AddressType :: Bech32 ) )
134
- . unwrap ( )
135
- . assume_checked ( ) ;
134
+ . new_address_with_type ( AddressType :: Bech32 )
135
+ . unwrap ( ) ;
136
136
// Had to decrease 'value', so that fees can be increased
137
137
// (Was getting insufficient fees error, for deep script trees)
138
138
psbt. unsigned_tx
@@ -285,18 +285,20 @@ pub fn test_desc_satisfy(
285
285
// Send the transactions to bitcoin node for mining.
286
286
// Regtest mode has standardness checks
287
287
// Check whether the node accepts the transactions
288
- let txid = cl
288
+ let json = cl
289
289
. send_raw_transaction ( & tx)
290
290
. unwrap_or_else ( |_| panic ! ( "send tx failed for desc {}" , definite_desc) ) ;
291
+ let concrete: model:: SendRawTransaction = json. try_into ( ) . unwrap ( ) ;
292
+ let txid = concrete. 0 ;
291
293
292
294
// Finally mine the blocks and await confirmations
293
295
let _blocks = cl
294
- . generate_to_address ( 1 , & cl. get_new_address ( None , None ) . unwrap ( ) . assume_checked ( ) )
296
+ . generate_to_address ( 1 , & cl. new_address ( ) . unwrap ( ) )
295
297
. unwrap ( ) ;
296
298
// Get the required transactions from the node mined in the blocks.
297
299
// Check whether the transaction is mined in blocks
298
300
// Assert that the confirmations are > 0.
299
- let num_conf = cl. get_transaction ( & txid, None ) . unwrap ( ) . info . confirmations ;
301
+ let num_conf = cl. get_transaction ( txid) . unwrap ( ) . confirmations ;
300
302
assert ! ( num_conf > 0 ) ;
301
303
Ok ( tx. input [ 0 ] . witness . clone ( ) )
302
304
}
0 commit comments