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