@@ -154,72 +154,124 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for absolute::LockTime {
154154 }
155155 }
156156}
157- impl < Pk : MiniscriptKey + ToPublicKey > Satisfier < Pk > for HashMap < Pk , bitcoin:: ecdsa:: Signature > {
158- fn lookup_ecdsa_sig ( & self , key : & Pk ) -> Option < bitcoin:: ecdsa:: Signature > {
159- self . get ( key) . copied ( )
160- }
161- }
162157
163- impl < Pk : MiniscriptKey + ToPublicKey > Satisfier < Pk >
164- for HashMap < ( Pk , TapLeafHash ) , bitcoin :: taproot :: Signature >
165- {
166- fn lookup_tap_leaf_script_sig (
167- & self ,
168- key : & Pk ,
169- h : & TapLeafHash ,
170- ) -> Option < bitcoin:: taproot :: Signature > {
171- // Unfortunately, there is no way to get a &(a, b) from &a and &b without allocating
172- // If we change the signature the of lookup_tap_leaf_script_sig to accept a tuple. We would
173- // face the same problem while satisfying PkK.
174- // We use this signature to optimize for the psbt common use case.
175- self . get ( & ( key . clone ( ) , * h ) ) . copied ( )
158+ // You can ignore the complexity of this and similar macros below, all they do is implement
159+ // `Satisfier` on both `BTreeMap` and ` HashMap` feature guarding the `HashMap` impl on "std"
160+ // feature.
161+ macro_rules! impl_satisfier_for_map_key_to_ecdsa_sig {
162+ ( $ ( $ ( # [ cfg ( $attr : meta ) ] ) * $map : ident ) , * ) => {
163+ $ (
164+ $ ( # [ cfg ( $attr ) ] ) *
165+ impl < Pk : MiniscriptKey + ToPublicKey > Satisfier < Pk > for $map< Pk , bitcoin:: ecdsa :: Signature > {
166+ fn lookup_ecdsa_sig ( & self , key : & Pk ) -> Option <bitcoin :: ecdsa :: Signature > {
167+ self . get ( key ) . copied ( )
168+ }
169+ }
170+ ) *
176171 }
177172}
178-
179- impl < Pk : MiniscriptKey + ToPublicKey > Satisfier < Pk >
180- for HashMap < hash160:: Hash , ( Pk , bitcoin:: ecdsa:: Signature ) >
181- where
182- Pk : MiniscriptKey + ToPublicKey ,
183- {
184- fn lookup_ecdsa_sig ( & self , key : & Pk ) -> Option < bitcoin:: ecdsa:: Signature > {
185- self . get ( & key. to_pubkeyhash ( SigType :: Ecdsa ) ) . map ( |x| x. 1 )
173+ impl_satisfier_for_map_key_to_ecdsa_sig ! (
174+ BTreeMap ,
175+ #[ cfg( feature = "std" ) ]
176+ HashMap
177+ ) ;
178+
179+ macro_rules! impl_satisfier_for_map_key_hash_to_taproot_sig {
180+ ( $( $( #[ cfg( $attr: meta) ] ) * $map: ident) ,* ) => {
181+ $(
182+ $( #[ cfg( $attr) ] ) *
183+ impl <Pk : MiniscriptKey + ToPublicKey > Satisfier <Pk >
184+ for $map<( Pk , TapLeafHash ) , bitcoin:: taproot:: Signature >
185+ {
186+ fn lookup_tap_leaf_script_sig(
187+ & self ,
188+ key: & Pk ,
189+ h: & TapLeafHash ,
190+ ) -> Option <bitcoin:: taproot:: Signature > {
191+ // Unfortunately, there is no way to get a &(a, b) from &a and &b without allocating
192+ // If we change the signature the of lookup_tap_leaf_script_sig to accept a tuple. We would
193+ // face the same problem while satisfying PkK.
194+ // We use this signature to optimize for the psbt common use case.
195+ self . get( & ( key. clone( ) , * h) ) . copied( )
196+ }
197+ }
198+ ) *
186199 }
200+ }
201+ impl_satisfier_for_map_key_hash_to_taproot_sig ! (
202+ BTreeMap ,
203+ #[ cfg( feature = "std" ) ]
204+ HashMap
205+ ) ;
206+
207+ macro_rules! impl_satisfier_for_map_hash_to_key_ecdsa_sig {
208+ ( $( $( #[ cfg( $attr: meta) ] ) * $map: ident) ,* ) => {
209+ $(
210+ $( #[ cfg( $attr) ] ) *
211+ impl <Pk : MiniscriptKey + ToPublicKey > Satisfier <Pk >
212+ for $map<hash160:: Hash , ( Pk , bitcoin:: ecdsa:: Signature ) >
213+ where
214+ Pk : MiniscriptKey + ToPublicKey ,
215+ {
216+ fn lookup_ecdsa_sig( & self , key: & Pk ) -> Option <bitcoin:: ecdsa:: Signature > {
217+ self . get( & key. to_pubkeyhash( SigType :: Ecdsa ) ) . map( |x| x. 1 )
218+ }
187219
188- fn lookup_raw_pkh_pk ( & self , pk_hash : & hash160:: Hash ) -> Option < bitcoin:: PublicKey > {
189- self . get ( pk_hash) . map ( |x| x. 0 . to_public_key ( ) )
190- }
220+ fn lookup_raw_pkh_pk( & self , pk_hash: & hash160:: Hash ) -> Option <bitcoin:: PublicKey > {
221+ self . get( pk_hash) . map( |x| x. 0 . to_public_key( ) )
222+ }
191223
192- fn lookup_raw_pkh_ecdsa_sig (
193- & self ,
194- pk_hash : & hash160:: Hash ,
195- ) -> Option < ( bitcoin:: PublicKey , bitcoin:: ecdsa:: Signature ) > {
196- self . get ( pk_hash)
197- . map ( |& ( ref pk, sig) | ( pk. to_public_key ( ) , sig) )
224+ fn lookup_raw_pkh_ecdsa_sig(
225+ & self ,
226+ pk_hash: & hash160:: Hash ,
227+ ) -> Option <( bitcoin:: PublicKey , bitcoin:: ecdsa:: Signature ) > {
228+ self . get( pk_hash)
229+ . map( |& ( ref pk, sig) | ( pk. to_public_key( ) , sig) )
230+ }
231+ }
232+ ) *
198233 }
199234}
235+ impl_satisfier_for_map_hash_to_key_ecdsa_sig ! (
236+ BTreeMap ,
237+ #[ cfg( feature = "std" ) ]
238+ HashMap
239+ ) ;
240+
241+ macro_rules! impl_satisfier_for_map_hash_tapleafhash_to_key_taproot_sig {
242+ ( $( $( #[ cfg( $attr: meta) ] ) * $map: ident) ,* ) => {
243+ $(
244+ $( #[ cfg( $attr) ] ) *
245+ impl <Pk : MiniscriptKey + ToPublicKey > Satisfier <Pk >
246+ for $map<( hash160:: Hash , TapLeafHash ) , ( Pk , bitcoin:: taproot:: Signature ) >
247+ where
248+ Pk : MiniscriptKey + ToPublicKey ,
249+ {
250+ fn lookup_tap_leaf_script_sig(
251+ & self ,
252+ key: & Pk ,
253+ h: & TapLeafHash ,
254+ ) -> Option <bitcoin:: taproot:: Signature > {
255+ self . get( & ( key. to_pubkeyhash( SigType :: Schnorr ) , * h) )
256+ . map( |x| x. 1 )
257+ }
200258
201- impl < Pk : MiniscriptKey + ToPublicKey > Satisfier < Pk >
202- for HashMap < ( hash160:: Hash , TapLeafHash ) , ( Pk , bitcoin:: taproot:: Signature ) >
203- where
204- Pk : MiniscriptKey + ToPublicKey ,
205- {
206- fn lookup_tap_leaf_script_sig (
207- & self ,
208- key : & Pk ,
209- h : & TapLeafHash ,
210- ) -> Option < bitcoin:: taproot:: Signature > {
211- self . get ( & ( key. to_pubkeyhash ( SigType :: Schnorr ) , * h) )
212- . map ( |x| x. 1 )
213- }
214-
215- fn lookup_raw_pkh_tap_leaf_script_sig (
216- & self ,
217- pk_hash : & ( hash160:: Hash , TapLeafHash ) ,
218- ) -> Option < ( XOnlyPublicKey , bitcoin:: taproot:: Signature ) > {
219- self . get ( pk_hash)
220- . map ( |& ( ref pk, sig) | ( pk. to_x_only_pubkey ( ) , sig) )
259+ fn lookup_raw_pkh_tap_leaf_script_sig(
260+ & self ,
261+ pk_hash: & ( hash160:: Hash , TapLeafHash ) ,
262+ ) -> Option <( XOnlyPublicKey , bitcoin:: taproot:: Signature ) > {
263+ self . get( pk_hash)
264+ . map( |& ( ref pk, sig) | ( pk. to_x_only_pubkey( ) , sig) )
265+ }
266+ }
267+ ) *
221268 }
222269}
270+ impl_satisfier_for_map_hash_tapleafhash_to_key_taproot_sig ! (
271+ BTreeMap ,
272+ #[ cfg( feature = "std" ) ]
273+ HashMap
274+ ) ;
223275
224276impl < ' a , Pk : MiniscriptKey + ToPublicKey , S : Satisfier < Pk > > Satisfier < Pk > for & ' a S {
225277 fn lookup_ecdsa_sig ( & self , p : & Pk ) -> Option < bitcoin:: ecdsa:: Signature > {
0 commit comments