2121
2222use std:: { error, fmt} ;
2323
24- use bitcoin:: util:: psbt;
2524use bitcoin:: util:: psbt:: PartiallySignedTransaction as Psbt ;
2625
2726use bitcoin;
2827use bitcoin:: Script ;
29- use miniscript:: satisfy:: bitcoinsig_from_rawsig;
28+ use miniscript:: satisfy:: { bitcoinsig_from_rawsig, After , Older } ;
3029use BitcoinSig ;
3130use Satisfier ;
3231use { MiniscriptKey , ToPublicKey } ;
@@ -183,9 +182,35 @@ impl fmt::Display for Error {
183182 }
184183}
185184
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 > {
187209 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+ {
189214 // We have already previously checked that all signatures have the
190215 // correct sighash flag.
191216 bitcoinsig_from_rawsig ( rawsig) . ok ( )
@@ -195,7 +220,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for psbt::Input {
195220 }
196221
197222 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 ]
199224 . partial_sigs
200225 . iter ( )
201226 . filter ( |& ( pubkey, _sig) | pubkey. to_pubkeyhash ( ) == Pk :: hash_to_hash160 ( pkh) )
@@ -209,6 +234,16 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for psbt::Input {
209234 None
210235 }
211236 }
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+ }
212247}
213248
214249fn sanity_check ( psbt : & Psbt ) -> Result < ( ) , Error > {
0 commit comments