@@ -10,17 +10,16 @@ use std::{error, fmt};
1010use actual_rand as rand;
1111use bitcoin:: blockdata:: witness:: Witness ;
1212use bitcoin:: hashes:: { sha256d, Hash } ;
13- use bitcoin:: util:: psbt:: PartiallySignedTransaction as Psbt ;
14- use bitcoin:: util:: sighash:: SighashCache ;
15- use bitcoin:: util:: taproot:: { LeafVersion , TapLeafHash } ;
16- use bitcoin:: util:: { psbt, sighash} ;
13+ use bitcoin:: psbt:: Psbt ;
14+ use bitcoin:: sighash:: SighashCache ;
15+ use bitcoin:: taproot:: { LeafVersion , TapLeafHash } ;
1716use bitcoin:: {
18- secp256k1, Amount , LockTime , OutPoint , SchnorrSig , Script , Sequence , Transaction , TxIn , TxOut ,
19- Txid ,
17+ absolute, psbt, secp256k1, sighash, Amount , OutPoint , Sequence , Transaction , TxIn , TxOut , Txid ,
2018} ;
2119use bitcoind:: bitcoincore_rpc:: { json, Client , RpcApi } ;
20+ use miniscript:: bitcoin:: { self , ecdsa, taproot, ScriptBuf } ;
2221use miniscript:: psbt:: { PsbtExt , PsbtInputExt } ;
23- use miniscript:: { bitcoin , Descriptor , Miniscript , ScriptContext , ToPublicKey } ;
22+ use miniscript:: { Descriptor , Miniscript , ScriptContext , ToPublicKey } ;
2423mod setup;
2524
2625use rand:: RngCore ;
@@ -31,7 +30,7 @@ fn btc<F: Into<f64>>(btc: F) -> Amount {
3130}
3231
3332// Find the Outpoint by spk
34- fn get_vout ( cl : & Client , txid : Txid , value : u64 , spk : Script ) -> ( OutPoint , TxOut ) {
33+ fn get_vout ( cl : & Client , txid : Txid , value : u64 , spk : ScriptBuf ) -> ( OutPoint , TxOut ) {
3534 let tx = cl
3635 . get_transaction ( & txid, None )
3736 . unwrap ( )
@@ -79,7 +78,7 @@ pub fn test_desc_satisfy(
7978 let x_only_pks = & testdata. pubdata . x_only_pks ;
8079 // Generate some blocks
8180 let blocks = cl
82- . generate_to_address ( 1 , & cl. get_new_address ( None , None ) . unwrap ( ) )
81+ . generate_to_address ( 1 , & cl. get_new_address ( None , None ) . unwrap ( ) . assume_checked ( ) )
8382 . unwrap ( ) ;
8483 assert_eq ! ( blocks. len( ) , 1 ) ;
8584
@@ -98,15 +97,15 @@ pub fn test_desc_satisfy(
9897 . unwrap ( ) ;
9998 // Wait for the funds to mature.
10099 let blocks = cl
101- . generate_to_address ( 2 , & cl. get_new_address ( None , None ) . unwrap ( ) )
100+ . generate_to_address ( 2 , & cl. get_new_address ( None , None ) . unwrap ( ) . assume_checked ( ) )
102101 . unwrap ( ) ;
103102 assert_eq ! ( blocks. len( ) , 2 ) ;
104103 // Create a PSBT for each transaction.
105104 // Spend one input and spend one output for simplicity.
106105 let mut psbt = Psbt {
107106 unsigned_tx : Transaction {
108107 version : 2 ,
109- lock_time : LockTime :: from_time ( 1_603_866_330 )
108+ lock_time : absolute :: LockTime :: from_time ( 1_603_866_330 )
110109 . expect ( "valid timestamp" )
111110 . into ( ) , // 10/28/2020 @ 6:25am (UTC)
112111 input : vec ! [ ] ,
@@ -134,7 +133,8 @@ pub fn test_desc_satisfy(
134133 // and we can check it by gettransaction RPC.
135134 let addr = cl
136135 . get_new_address ( None , Some ( json:: AddressType :: Bech32 ) )
137- . unwrap ( ) ;
136+ . unwrap ( )
137+ . assume_checked ( ) ;
138138 // Had to decrease 'value', so that fees can be increased
139139 // (Was getting insufficient fees error, for deep script trees)
140140 psbt. unsigned_tx . output . push ( TxOut {
@@ -158,7 +158,7 @@ pub fn test_desc_satisfy(
158158 match derived_desc {
159159 Descriptor :: Tr ( ref tr) => {
160160 // Fixme: take a parameter
161- let hash_ty = sighash:: SchnorrSighashType :: Default ;
161+ let hash_ty = sighash:: TapSighashType :: Default ;
162162
163163 let internal_key_present = x_only_pks
164164 . iter ( )
@@ -180,7 +180,7 @@ pub fn test_desc_satisfy(
180180 rand:: thread_rng ( ) . fill_bytes ( & mut aux_rand) ;
181181 let schnorr_sig =
182182 secp. sign_schnorr_with_aux_rand ( & msg, & internal_keypair, & aux_rand) ;
183- psbt. inputs [ 0 ] . tap_key_sig = Some ( SchnorrSig {
183+ psbt. inputs [ 0 ] . tap_key_sig = Some ( taproot :: Signature {
184184 sig : schnorr_sig,
185185 hash_ty : hash_ty,
186186 } ) ;
@@ -206,13 +206,11 @@ pub fn test_desc_satisfy(
206206 let mut aux_rand = [ 0u8 ; 32 ] ;
207207 rand:: thread_rng ( ) . fill_bytes ( & mut aux_rand) ;
208208 let sig = secp. sign_schnorr_with_aux_rand ( & msg, & keypair, & aux_rand) ;
209- // FIXME: uncomment when == is supported for secp256k1::KeyPair. (next major release)
210- // let x_only_pk = pks[xonly_keypairs.iter().position(|&x| x == keypair).unwrap()];
211- // Just recalc public key
212- let ( x_only_pk, _parity) = secp256k1:: XOnlyPublicKey :: from_keypair ( & keypair) ;
209+ let x_only_pk =
210+ x_only_pks[ xonly_keypairs. iter ( ) . position ( |& x| x == keypair) . unwrap ( ) ] ;
213211 psbt. inputs [ 0 ] . tap_script_sigs . insert (
214212 ( x_only_pk, leaf_hash) ,
215- bitcoin :: SchnorrSig {
213+ taproot :: Signature {
216214 sig,
217215 hash_ty : hash_ty,
218216 } ,
@@ -258,7 +256,7 @@ pub fn test_desc_satisfy(
258256 . to_secp_msg ( ) ;
259257
260258 // Fixme: Take a parameter
261- let hash_ty = bitcoin :: EcdsaSighashType :: All ;
259+ let hash_ty = sighash :: EcdsaSighashType :: All ;
262260
263261 // Finally construct the signature and add to psbt
264262 for sk in sks_reqd {
@@ -267,7 +265,7 @@ pub fn test_desc_satisfy(
267265 assert ! ( secp. verify_ecdsa( & msg, & sig, & pk. inner) . is_ok( ) ) ;
268266 psbt. inputs [ 0 ] . partial_sigs . insert (
269267 pk,
270- bitcoin :: EcdsaSig {
268+ ecdsa :: Signature {
271269 sig,
272270 hash_ty : hash_ty,
273271 } ,
@@ -281,7 +279,7 @@ pub fn test_desc_satisfy(
281279 testdata. secretdata . sha256_pre . to_vec ( ) ,
282280 ) ;
283281 psbt. inputs [ 0 ] . hash256_preimages . insert (
284- sha256d:: Hash :: from_inner ( testdata. pubdata . hash256 . into_inner ( ) ) ,
282+ sha256d:: Hash :: from_byte_array ( testdata. pubdata . hash256 . to_byte_array ( ) ) ,
285283 testdata. secretdata . hash256_pre . to_vec ( ) ,
286284 ) ;
287285 psbt. inputs [ 0 ] . hash160_preimages . insert (
@@ -309,7 +307,7 @@ pub fn test_desc_satisfy(
309307
310308 // Finally mine the blocks and await confirmations
311309 let _blocks = cl
312- . generate_to_address ( 1 , & cl. get_new_address ( None , None ) . unwrap ( ) )
310+ . generate_to_address ( 1 , & cl. get_new_address ( None , None ) . unwrap ( ) . assume_checked ( ) )
313311 . unwrap ( ) ;
314312 // Get the required transactions from the node mined in the blocks.
315313 // Check whether the transaction is mined in blocks
0 commit comments