2020//!
2121
2222use bitcoin:: util:: sighash:: Prevouts ;
23+ use std:: borrow:: Borrow ;
2324use util:: witness_size;
2425
2526use super :: { sanity_check, Psbt } ;
@@ -28,7 +29,7 @@ use bitcoin::blockdata::witness::Witness;
2829use bitcoin:: secp256k1:: { self , Secp256k1 } ;
2930use bitcoin:: util:: key:: XOnlyPublicKey ;
3031use bitcoin:: util:: taproot:: LeafVersion ;
31- use bitcoin:: { self , PublicKey , Script } ;
32+ use bitcoin:: { self , PublicKey , Script , TxOut } ;
3233use descriptor:: DescriptorTrait ;
3334use interpreter;
3435use Descriptor ;
@@ -116,11 +117,11 @@ pub(super) fn get_utxo(psbt: &Psbt, index: usize) -> Result<&bitcoin::TxOut, Inp
116117}
117118
118119/// 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 > {
120121 let mut utxos = vec ! [ ] ;
121122 for i in 0 ..psbt. inputs . len ( ) {
122123 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) ;
124125 }
125126 Ok ( utxos)
126127}
@@ -157,13 +158,12 @@ fn get_descriptor(psbt: &Psbt, index: usize) -> Result<Descriptor<PublicKey>, In
157158 // Partial sigs loses the compressed flag that is necessary
158159 // TODO: See https://github.com/rust-bitcoin/rust-bitcoin/pull/836
159160 // The type checker will fail again after we update to 0.28 and this can be removed
160- let pk = bitcoin:: PublicKey :: new ( pk) ;
161161 let addr = bitcoin:: Address :: p2pkh ( & pk, bitcoin:: Network :: Bitcoin ) ;
162162 * script_pubkey == addr. script_pubkey ( )
163163 } )
164164 . next ( ) ;
165165 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) ) ,
167167 None => Err ( InputError :: MissingPubkey ) ,
168168 }
169169 } else if script_pubkey. is_v0_p2wpkh ( ) {
@@ -174,14 +174,13 @@ fn get_descriptor(psbt: &Psbt, index: usize) -> Result<Descriptor<PublicKey>, In
174174 . filter ( |& ( & pk, _sig) | {
175175 // Indirect way to check the equivalence of pubkey-hashes.
176176 // Create a pubkey hash and check if they are the same.
177- let pk = bitcoin:: PublicKey :: new ( pk) ;
178177 let addr = bitcoin:: Address :: p2wpkh ( & pk, bitcoin:: Network :: Bitcoin )
179178 . expect ( "Address corresponding to valid pubkey" ) ;
180179 * script_pubkey == addr. script_pubkey ( )
181180 } )
182181 . next ( ) ;
183182 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) ?) ,
185184 None => Err ( InputError :: MissingPubkey ) ,
186185 }
187186 } else if script_pubkey. is_v0_p2wsh ( ) {
@@ -233,16 +232,13 @@ fn get_descriptor(psbt: &Psbt, index: usize) -> Result<Descriptor<PublicKey>, In
233232 . partial_sigs
234233 . iter ( )
235234 . filter ( |& ( & pk, _sig) | {
236- let pk = bitcoin:: PublicKey :: new ( pk) ;
237235 let addr = bitcoin:: Address :: p2wpkh ( & pk, bitcoin:: Network :: Bitcoin )
238236 . expect ( "Address corresponding to valid pubkey" ) ;
239237 * redeem_script == addr. script_pubkey ( )
240238 } )
241239 . next ( ) ;
242240 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) ?) ,
246242 None => Err ( InputError :: MissingPubkey ) ,
247243 }
248244 } else {
@@ -300,11 +296,11 @@ pub fn interpreter_check<C: secp256k1::Verification>(
300296}
301297
302298// 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 > > (
304300 psbt : & Psbt ,
305301 secp : & Secp256k1 < C > ,
306302 index : usize ,
307- utxos : & Prevouts ,
303+ utxos : & Prevouts < T > ,
308304 witness : & Witness ,
309305 script_sig : & Script ,
310306) -> Result < ( ) , Error > {
0 commit comments