2121
2222use bitcoin:: blockdata:: witness:: Witness ;
2323use bitcoin:: util:: { sighash, taproot} ;
24+ use std:: borrow:: Borrow ;
2425use std:: fmt;
2526use std:: str:: FromStr ;
2627
2728use bitcoin:: hashes:: { hash160, ripemd160, sha256, sha256d} ;
28- use bitcoin:: { self , secp256k1} ;
29+ use bitcoin:: { self , secp256k1, TxOut } ;
2930use miniscript:: context:: NoChecks ;
3031use miniscript:: ScriptContext ;
3132use Miniscript ;
@@ -224,18 +225,18 @@ impl<'txin> Interpreter<'txin> {
224225 /// - Insufficient sighash information is present
225226 /// - sighash single without corresponding output
226227 // TODO: Create a good first isse to change this to error
227- pub fn verify_sig < C : secp256k1:: Verification > (
228+ pub fn verify_sig < C : secp256k1:: Verification , T : Borrow < TxOut > > (
228229 & self ,
229230 secp : & secp256k1:: Secp256k1 < C > ,
230231 tx : & bitcoin:: Transaction ,
231232 input_idx : usize ,
232- prevouts : & sighash:: Prevouts ,
233+ prevouts : & sighash:: Prevouts < T > ,
233234 sig : & KeySigPair ,
234235 ) -> bool {
235- fn get_prevout < ' u > (
236- prevouts : & sighash:: Prevouts < ' u > ,
236+ fn get_prevout < ' u , T : Borrow < TxOut > > (
237+ prevouts : & ' u sighash:: Prevouts < ' u , T > ,
237238 input_index : usize ,
238- ) -> Option < & ' u bitcoin :: TxOut > {
239+ ) -> Option < & ' u T > {
239240 match prevouts {
240241 sighash:: Prevouts :: One ( index, prevout) => {
241242 if input_index == * index {
@@ -252,11 +253,11 @@ impl<'txin> Interpreter<'txin> {
252253 KeySigPair :: Ecdsa ( key, ecdsa_sig) => {
253254 let script_pubkey = self . script_code . as_ref ( ) . expect ( "Legacy have script code" ) ;
254255 let sighash = if self . is_legacy ( ) {
255- let sighash_u32 = ecdsa_sig. hash_ty . as_u32 ( ) ;
256+ let sighash_u32 = ecdsa_sig. hash_ty . to_u32 ( ) ;
256257 cache. legacy_signature_hash ( input_idx, & script_pubkey, sighash_u32)
257258 } else if self . is_segwit_v0 ( ) {
258259 let amt = match get_prevout ( prevouts, input_idx) {
259- Some ( txout) => txout. value ,
260+ Some ( txout) => txout. borrow ( ) . value ,
260261 None => return false ,
261262 } ;
262263 cache. segwit_signature_hash ( input_idx, & script_pubkey, amt, ecdsa_sig. hash_ty )
@@ -318,12 +319,12 @@ impl<'txin> Interpreter<'txin> {
318319 /// - For legacy outputs, no information about prevouts is required
319320 /// - For segwitv0 outputs, prevout at corresponding index with correct amount must be provided
320321 /// - For taproot outputs, information about all prevouts must be supplied
321- pub fn iter < ' iter , C : secp256k1:: Verification > (
322+ pub fn iter < ' iter , C : secp256k1:: Verification , T : Borrow < TxOut > > (
322323 & ' iter self ,
323324 secp : & ' iter secp256k1:: Secp256k1 < C > ,
324325 tx : & ' txin bitcoin:: Transaction ,
325326 input_idx : usize ,
326- prevouts : & ' iter sighash:: Prevouts , // actually a 'prevouts, but 'prevouts: 'iter
327+ prevouts : & ' iter sighash:: Prevouts < T > , // actually a 'prevouts, but 'prevouts: 'iter
327328 ) -> Iter < ' txin , ' iter > {
328329 self . iter_custom ( Box :: new ( move |sig| {
329330 self . verify_sig ( secp, tx, input_idx, prevouts, sig)
0 commit comments