21
21
22
22
use bitcoin:: blockdata:: witness:: Witness ;
23
23
use bitcoin:: util:: { sighash, taproot} ;
24
+ use std:: borrow:: Borrow ;
24
25
use std:: fmt;
25
26
use std:: str:: FromStr ;
26
27
27
28
use bitcoin:: hashes:: { hash160, ripemd160, sha256, sha256d} ;
28
- use bitcoin:: { self , secp256k1} ;
29
+ use bitcoin:: { self , secp256k1, TxOut } ;
29
30
use miniscript:: context:: NoChecks ;
30
31
use miniscript:: ScriptContext ;
31
32
use Miniscript ;
@@ -224,18 +225,18 @@ impl<'txin> Interpreter<'txin> {
224
225
/// - Insufficient sighash information is present
225
226
/// - sighash single without corresponding output
226
227
// 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 > > (
228
229
& self ,
229
230
secp : & secp256k1:: Secp256k1 < C > ,
230
231
tx : & bitcoin:: Transaction ,
231
232
input_idx : usize ,
232
- prevouts : & sighash:: Prevouts ,
233
+ prevouts : & sighash:: Prevouts < T > ,
233
234
sig : & KeySigPair ,
234
235
) -> 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 > ,
237
238
input_index : usize ,
238
- ) -> Option < & ' u bitcoin :: TxOut > {
239
+ ) -> Option < & ' u T > {
239
240
match prevouts {
240
241
sighash:: Prevouts :: One ( index, prevout) => {
241
242
if input_index == * index {
@@ -252,11 +253,11 @@ impl<'txin> Interpreter<'txin> {
252
253
KeySigPair :: Ecdsa ( key, ecdsa_sig) => {
253
254
let script_pubkey = self . script_code . as_ref ( ) . expect ( "Legacy have script code" ) ;
254
255
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 ( ) ;
256
257
cache. legacy_signature_hash ( input_idx, & script_pubkey, sighash_u32)
257
258
} else if self . is_segwit_v0 ( ) {
258
259
let amt = match get_prevout ( prevouts, input_idx) {
259
- Some ( txout) => txout. value ,
260
+ Some ( txout) => txout. borrow ( ) . value ,
260
261
None => return false ,
261
262
} ;
262
263
cache. segwit_signature_hash ( input_idx, & script_pubkey, amt, ecdsa_sig. hash_ty )
@@ -318,12 +319,12 @@ impl<'txin> Interpreter<'txin> {
318
319
/// - For legacy outputs, no information about prevouts is required
319
320
/// - For segwitv0 outputs, prevout at corresponding index with correct amount must be provided
320
321
/// - 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 > > (
322
323
& ' iter self ,
323
324
secp : & ' iter secp256k1:: Secp256k1 < C > ,
324
325
tx : & ' txin bitcoin:: Transaction ,
325
326
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
327
328
) -> Iter < ' txin , ' iter > {
328
329
self . iter_custom ( Box :: new ( move |sig| {
329
330
self . verify_sig ( secp, tx, input_idx, prevouts, sig)
0 commit comments