@@ -54,11 +54,7 @@ fn btc<F: Into<f64>>(btc: F) -> Amount { Amount::from_btc(btc.into()).unwrap() }
54
54
// Ideally, we should find by scriptPubkey, but this
55
55
// works for temp test case
56
56
fn get_vout ( cl : & Client , txid : Txid , value : u64 ) -> ( OutPoint , TxOut ) {
57
- let tx = cl
58
- . get_transaction ( & txid, None )
59
- . unwrap ( )
60
- . transaction ( )
61
- . unwrap ( ) ;
57
+ let tx = cl. get_transaction ( & txid, None ) . unwrap ( ) . transaction ( ) . unwrap ( ) ;
62
58
for ( i, txout) in tx. output . into_iter ( ) . enumerate ( ) {
63
59
if txout. value == value {
64
60
return ( OutPoint :: new ( txid, i as u32 ) , txout) ;
@@ -74,10 +70,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
74
70
let pks = & testdata. pubdata . pks ;
75
71
// Generate some blocks
76
72
let blocks = cl
77
- . generate_to_address (
78
- 500 ,
79
- & cl. get_new_address ( None , None ) . unwrap ( ) . assume_checked ( ) ,
80
- )
73
+ . generate_to_address ( 500 , & cl. get_new_address ( None , None ) . unwrap ( ) . assume_checked ( ) )
81
74
. unwrap ( ) ;
82
75
assert_eq ! ( blocks. len( ) , 500 ) ;
83
76
@@ -100,10 +93,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
100
93
}
101
94
// Wait for the funds to mature.
102
95
let blocks = cl
103
- . generate_to_address (
104
- 50 ,
105
- & cl. get_new_address ( None , None ) . unwrap ( ) . assume_checked ( ) ,
106
- )
96
+ . generate_to_address ( 50 , & cl. get_new_address ( None , None ) . unwrap ( ) . assume_checked ( ) )
107
97
. unwrap ( ) ;
108
98
assert_eq ! ( blocks. len( ) , 50 ) ;
109
99
// Create a PSBT for each transaction.
@@ -138,14 +128,11 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
138
128
// Get a new script pubkey from the node so that
139
129
// the node wallet tracks the receiving transaction
140
130
// and we can check it by gettransaction RPC.
141
- let addr = cl
142
- . get_new_address ( None , Some ( json:: AddressType :: Bech32 ) )
143
- . unwrap ( )
144
- . assume_checked ( ) ;
145
- psbt. unsigned_tx . output . push ( TxOut {
146
- value : 99_999_000 ,
147
- script_pubkey : addr. script_pubkey ( ) ,
148
- } ) ;
131
+ let addr =
132
+ cl. get_new_address ( None , Some ( json:: AddressType :: Bech32 ) ) . unwrap ( ) . assume_checked ( ) ;
133
+ psbt. unsigned_tx
134
+ . output
135
+ . push ( TxOut { value : 99_999_000 , script_pubkey : addr. script_pubkey ( ) } ) ;
149
136
let mut input = psbt:: Input :: default ( ) ;
150
137
input. witness_utxo = Some ( witness_utxo) ;
151
138
input. witness_script = Some ( desc. explicit_script ( ) . unwrap ( ) ) ;
@@ -167,17 +154,14 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
167
154
unreachable ! ( "Only Wsh descriptors are supported" ) ;
168
155
} ;
169
156
170
- let sks_reqd: Vec < _ > = ms
171
- . iter_pk ( )
172
- . map ( |pk| sks[ pks. iter ( ) . position ( |& x| x == pk) . unwrap ( ) ] )
173
- . collect ( ) ;
157
+ let sks_reqd: Vec < _ > =
158
+ ms. iter_pk ( ) . map ( |pk| sks[ pks. iter ( ) . position ( |& x| x == pk) . unwrap ( ) ] ) . collect ( ) ;
174
159
// Get the required sighash message
175
160
let amt = btc ( 1 ) . to_sat ( ) ;
176
161
let mut sighash_cache = bitcoin:: sighash:: SighashCache :: new ( & psbts[ i] . unsigned_tx ) ;
177
162
let sighash_ty = bitcoin:: sighash:: EcdsaSighashType :: All ;
178
- let sighash = sighash_cache
179
- . segwit_signature_hash ( 0 , & ms. encode ( ) , amt, sighash_ty)
180
- . unwrap ( ) ;
163
+ let sighash =
164
+ sighash_cache. segwit_signature_hash ( 0 , & ms. encode ( ) , amt, sighash_ty) . unwrap ( ) ;
181
165
182
166
// requires both signing and verification because we check the tx
183
167
// after we psbt extract it
@@ -187,32 +171,25 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
187
171
for sk in sks_reqd {
188
172
let sig = secp. sign_ecdsa ( & msg, & sk) ;
189
173
let pk = pks[ sks. iter ( ) . position ( |& x| x == sk) . unwrap ( ) ] ;
190
- psbts[ i] . inputs [ 0 ] . partial_sigs . insert (
191
- pk,
192
- bitcoin:: ecdsa:: Signature {
193
- sig,
194
- hash_ty : sighash_ty,
195
- } ,
196
- ) ;
174
+ psbts[ i] . inputs [ 0 ]
175
+ . partial_sigs
176
+ . insert ( pk, bitcoin:: ecdsa:: Signature { sig, hash_ty : sighash_ty } ) ;
197
177
}
198
178
// Add the hash preimages to the psbt
199
- psbts[ i] . inputs [ 0 ] . sha256_preimages . insert (
200
- testdata. pubdata . sha256 ,
201
- testdata. secretdata . sha256_pre . to_vec ( ) ,
202
- ) ;
179
+ psbts[ i] . inputs [ 0 ]
180
+ . sha256_preimages
181
+ . insert ( testdata. pubdata . sha256 , testdata. secretdata . sha256_pre . to_vec ( ) ) ;
203
182
psbts[ i] . inputs [ 0 ] . hash256_preimages . insert (
204
183
sha256d:: Hash :: from_byte_array ( testdata. pubdata . hash256 . to_byte_array ( ) ) ,
205
184
testdata. secretdata . hash256_pre . to_vec ( ) ,
206
185
) ;
207
186
println ! ( "{}" , ms) ;
208
- psbts[ i] . inputs [ 0 ] . hash160_preimages . insert (
209
- testdata. pubdata . hash160 ,
210
- testdata. secretdata . hash160_pre . to_vec ( ) ,
211
- ) ;
212
- psbts[ i] . inputs [ 0 ] . ripemd160_preimages . insert (
213
- testdata. pubdata . ripemd160 ,
214
- testdata. secretdata . ripemd160_pre . to_vec ( ) ,
215
- ) ;
187
+ psbts[ i] . inputs [ 0 ]
188
+ . hash160_preimages
189
+ . insert ( testdata. pubdata . hash160 , testdata. secretdata . hash160_pre . to_vec ( ) ) ;
190
+ psbts[ i] . inputs [ 0 ]
191
+ . ripemd160_preimages
192
+ . insert ( testdata. pubdata . ripemd160 , testdata. secretdata . ripemd160_pre . to_vec ( ) ) ;
216
193
// Finalize the transaction using psbt
217
194
// Let miniscript do it's magic!
218
195
if let Err ( e) = psbts[ i] . finalize_mall_mut ( & secp) {
@@ -224,18 +201,14 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
224
201
// Send the transactions to bitcoin node for mining.
225
202
// Regtest mode has standardness checks
226
203
// Check whether the node accepts the transactions
227
- let txid = cl
228
- . send_raw_transaction ( & tx)
229
- . expect ( & format ! ( "{} send tx failed for ms {}" , i, ms) ) ;
204
+ let txid =
205
+ cl. send_raw_transaction ( & tx) . expect ( & format ! ( "{} send tx failed for ms {}" , i, ms) ) ;
230
206
spend_txids. push ( txid) ;
231
207
}
232
208
}
233
209
// Finally mine the blocks and await confirmations
234
210
let _blocks = cl
235
- . generate_to_address (
236
- 10 ,
237
- & cl. get_new_address ( None , None ) . unwrap ( ) . assume_checked ( ) ,
238
- )
211
+ . generate_to_address ( 10 , & cl. get_new_address ( None , None ) . unwrap ( ) . assume_checked ( ) )
239
212
. unwrap ( ) ;
240
213
// Get the required transactions from the node mined in the blocks.
241
214
for txid in spend_txids {
0 commit comments