20
20
//!
21
21
22
22
use bitcoin:: util:: sighash:: Prevouts ;
23
+ use std:: borrow:: Borrow ;
23
24
use util:: witness_size;
24
25
25
26
use super :: { sanity_check, Psbt } ;
@@ -28,7 +29,7 @@ use bitcoin::blockdata::witness::Witness;
28
29
use bitcoin:: secp256k1:: { self , Secp256k1 } ;
29
30
use bitcoin:: util:: key:: XOnlyPublicKey ;
30
31
use bitcoin:: util:: taproot:: LeafVersion ;
31
- use bitcoin:: { self , PublicKey , Script } ;
32
+ use bitcoin:: { self , PublicKey , Script , TxOut } ;
32
33
use descriptor:: DescriptorTrait ;
33
34
use interpreter;
34
35
use Descriptor ;
@@ -116,11 +117,11 @@ pub(super) fn get_utxo(psbt: &Psbt, index: usize) -> Result<&bitcoin::TxOut, Inp
116
117
}
117
118
118
119
/// Get the Prevouts for the psbt
119
- pub ( super ) fn prevouts < ' a > ( psbt : & ' a Psbt ) -> Result < Vec < bitcoin:: TxOut > , super :: Error > {
120
+ pub ( super ) fn prevouts < ' a > ( psbt : & ' a Psbt ) -> Result < Vec < & bitcoin:: TxOut > , super :: Error > {
120
121
let mut utxos = vec ! [ ] ;
121
122
for i in 0 ..psbt. inputs . len ( ) {
122
123
let utxo_ref = get_utxo ( psbt, i) . map_err ( |e| Error :: InputError ( e, i) ) ?;
123
- utxos. push ( utxo_ref. clone ( ) ) ; // RC fix would allow references here instead of clone
124
+ utxos. push ( utxo_ref) ;
124
125
}
125
126
Ok ( utxos)
126
127
}
@@ -157,13 +158,12 @@ fn get_descriptor(psbt: &Psbt, index: usize) -> Result<Descriptor<PublicKey>, In
157
158
// Partial sigs loses the compressed flag that is necessary
158
159
// TODO: See https://github.com/rust-bitcoin/rust-bitcoin/pull/836
159
160
// The type checker will fail again after we update to 0.28 and this can be removed
160
- let pk = bitcoin:: PublicKey :: new ( pk) ;
161
161
let addr = bitcoin:: Address :: p2pkh ( & pk, bitcoin:: Network :: Bitcoin ) ;
162
162
* script_pubkey == addr. script_pubkey ( )
163
163
} )
164
164
. next ( ) ;
165
165
match partial_sig_contains_pk {
166
- Some ( ( pk, _sig) ) => Ok ( Descriptor :: new_pkh ( bitcoin :: PublicKey :: new ( * pk) ) ) ,
166
+ Some ( ( pk, _sig) ) => Ok ( Descriptor :: new_pkh ( * pk) ) ,
167
167
None => Err ( InputError :: MissingPubkey ) ,
168
168
}
169
169
} else if script_pubkey. is_v0_p2wpkh ( ) {
@@ -174,14 +174,13 @@ fn get_descriptor(psbt: &Psbt, index: usize) -> Result<Descriptor<PublicKey>, In
174
174
. filter ( |& ( & pk, _sig) | {
175
175
// Indirect way to check the equivalence of pubkey-hashes.
176
176
// Create a pubkey hash and check if they are the same.
177
- let pk = bitcoin:: PublicKey :: new ( pk) ;
178
177
let addr = bitcoin:: Address :: p2wpkh ( & pk, bitcoin:: Network :: Bitcoin )
179
178
. expect ( "Address corresponding to valid pubkey" ) ;
180
179
* script_pubkey == addr. script_pubkey ( )
181
180
} )
182
181
. next ( ) ;
183
182
match partial_sig_contains_pk {
184
- Some ( ( pk, _sig) ) => Ok ( Descriptor :: new_wpkh ( bitcoin :: PublicKey :: new ( * pk) ) ?) ,
183
+ Some ( ( pk, _sig) ) => Ok ( Descriptor :: new_wpkh ( * pk) ?) ,
185
184
None => Err ( InputError :: MissingPubkey ) ,
186
185
}
187
186
} else if script_pubkey. is_v0_p2wsh ( ) {
@@ -233,16 +232,13 @@ fn get_descriptor(psbt: &Psbt, index: usize) -> Result<Descriptor<PublicKey>, In
233
232
. partial_sigs
234
233
. iter ( )
235
234
. filter ( |& ( & pk, _sig) | {
236
- let pk = bitcoin:: PublicKey :: new ( pk) ;
237
235
let addr = bitcoin:: Address :: p2wpkh ( & pk, bitcoin:: Network :: Bitcoin )
238
236
. expect ( "Address corresponding to valid pubkey" ) ;
239
237
* redeem_script == addr. script_pubkey ( )
240
238
} )
241
239
. next ( ) ;
242
240
match partial_sig_contains_pk {
243
- Some ( ( pk, _sig) ) => {
244
- Ok ( Descriptor :: new_sh_wpkh ( bitcoin:: PublicKey :: new ( * pk) ) ?)
245
- }
241
+ Some ( ( pk, _sig) ) => Ok ( Descriptor :: new_sh_wpkh ( * pk) ?) ,
246
242
None => Err ( InputError :: MissingPubkey ) ,
247
243
}
248
244
} else {
@@ -300,11 +296,11 @@ pub fn interpreter_check<C: secp256k1::Verification>(
300
296
}
301
297
302
298
// Run the miniscript interpreter on a single psbt input
303
- fn interpreter_inp_check < C : secp256k1:: Verification > (
299
+ fn interpreter_inp_check < C : secp256k1:: Verification , T : Borrow < TxOut > > (
304
300
psbt : & Psbt ,
305
301
secp : & Secp256k1 < C > ,
306
302
index : usize ,
307
- utxos : & Prevouts ,
303
+ utxos : & Prevouts < T > ,
308
304
witness : & Witness ,
309
305
script_sig : & Script ,
310
306
) -> Result < ( ) , Error > {
0 commit comments