21
21
22
22
use std:: { error, fmt} ;
23
23
24
- use bitcoin:: util:: psbt;
25
24
use bitcoin:: util:: psbt:: PartiallySignedTransaction as Psbt ;
26
25
27
26
use bitcoin;
@@ -183,9 +182,35 @@ impl fmt::Display for Error {
183
182
}
184
183
}
185
184
186
- impl < Pk : MiniscriptKey + ToPublicKey > Satisfier < Pk > for psbt:: Input {
185
+ /// Psbt satisfier for at inputs at a particular index
186
+ /// Takes in &psbt because multiple inputs will share
187
+ /// the same psbt structure
188
+ /// All operations on this structure will panic if index
189
+ /// is more than number of inputs in pbst
190
+ pub struct PsbtInputSatisfier < ' psbt > {
191
+ /// pbst
192
+ pub psbt : & ' psbt Psbt ,
193
+ /// input index
194
+ pub index : usize ,
195
+ }
196
+
197
+ impl < ' psbt > PsbtInputSatisfier < ' psbt > {
198
+ /// create a new PsbtInputsatisfier from
199
+ /// psbt and index
200
+ pub fn new ( psbt : & ' psbt Psbt , index : usize ) -> Self {
201
+ Self {
202
+ psbt : psbt,
203
+ index : index,
204
+ }
205
+ }
206
+ }
207
+
208
+ impl < ' psbt , Pk : MiniscriptKey + ToPublicKey > Satisfier < Pk > for PsbtInputSatisfier < ' psbt > {
187
209
fn lookup_sig ( & self , pk : & Pk ) -> Option < BitcoinSig > {
188
- if let Some ( rawsig) = self . partial_sigs . get ( & pk. to_public_key ( ) ) {
210
+ if let Some ( rawsig) = self . psbt . inputs [ self . index ]
211
+ . partial_sigs
212
+ . get ( & pk. to_public_key ( ) )
213
+ {
189
214
// We have already previously checked that all signatures have the
190
215
// correct sighash flag.
191
216
bitcoinsig_from_rawsig ( rawsig) . ok ( )
@@ -195,7 +220,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for psbt::Input {
195
220
}
196
221
197
222
fn lookup_pkh_sig ( & self , pkh : & Pk :: Hash ) -> Option < ( bitcoin:: PublicKey , BitcoinSig ) > {
198
- if let Some ( ( pk, sig) ) = self
223
+ if let Some ( ( pk, sig) ) = self . psbt . inputs [ self . index ]
199
224
. partial_sigs
200
225
. iter ( )
201
226
. filter ( |& ( pubkey, _sig) | pubkey. to_pubkeyhash ( ) == Pk :: hash_to_hash160 ( pkh) )
0 commit comments