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;
28
27
use bitcoin:: Script ;
29
- use miniscript:: satisfy:: bitcoinsig_from_rawsig;
28
+ use miniscript:: satisfy:: { bitcoinsig_from_rawsig, After , Older } ;
30
29
use BitcoinSig ;
31
30
use Satisfier ;
32
31
use { MiniscriptKey , ToPublicKey } ;
@@ -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) )
@@ -209,6 +234,16 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for psbt::Input {
209
234
None
210
235
}
211
236
}
237
+
238
+ fn check_after ( & self , n : u32 ) -> bool {
239
+ let cltv = self . psbt . global . unsigned_tx . lock_time ;
240
+ <Satisfier < Pk > >:: check_after ( & After ( cltv) , n)
241
+ }
242
+
243
+ fn check_older ( & self , n : u32 ) -> bool {
244
+ let csv = self . psbt . global . unsigned_tx . input [ self . index ] . sequence ;
245
+ <Satisfier < Pk > >:: check_older ( & Older ( csv) , n)
246
+ }
212
247
}
213
248
214
249
fn sanity_check ( psbt : & Psbt ) -> Result < ( ) , Error > {
0 commit comments