Skip to content

Commit 49a2bdf

Browse files
committed
Add Satisfier macro for ((hash160, leaf hash), (pk, tap sig))
As we did for `map<Pk, bitcoin::ecdsa::Signature>`, define a macro that implements `Satisfier<Pk>` for `map<(hash160::Hash, TapLeafHash), (Pk, bitcoin::taproot::Signature)>` And call it with `BTreeMap` and `HashMap`.
1 parent df11203 commit 49a2bdf

File tree

1 file changed

+33
-20
lines changed

1 file changed

+33
-20
lines changed

src/miniscript/satisfy.rs

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -239,27 +239,40 @@ impl_satisfier_for_map_hash_to_key_ecdsa_sig! {
239239
impl Satisfier<Pk> for HashMap<hash160::Hash, (Pk, bitcoin::ecdsa::Signature)>
240240
}
241241

242-
impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk>
243-
for HashMap<(hash160::Hash, TapLeafHash), (Pk, bitcoin::taproot::Signature)>
244-
where
245-
Pk: MiniscriptKey + ToPublicKey,
246-
{
247-
fn lookup_tap_leaf_script_sig(
248-
&self,
249-
key: &Pk,
250-
h: &TapLeafHash,
251-
) -> Option<bitcoin::taproot::Signature> {
252-
self.get(&(key.to_pubkeyhash(SigType::Schnorr), *h))
253-
.map(|x| x.1)
254-
}
242+
macro_rules! impl_satisfier_for_map_hash_tapleafhash_to_key_taproot_sig {
243+
($(#[$($attr:meta)*])* impl Satisfier<Pk> for $map:ident<$key:ty, $val:ty>) => {
244+
$(#[$($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+
}
255258

256-
fn lookup_raw_pkh_tap_leaf_script_sig(
257-
&self,
258-
pk_hash: &(hash160::Hash, TapLeafHash),
259-
) -> Option<(XOnlyPublicKey, bitcoin::taproot::Signature)> {
260-
self.get(pk_hash)
261-
.map(|&(ref pk, sig)| (pk.to_x_only_pubkey(), sig))
262-
}
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+
};
268+
}
269+
270+
impl_satisfier_for_map_hash_tapleafhash_to_key_taproot_sig! {
271+
impl Satisfier<Pk> for BTreeMap<(hash160::Hash, TapLeafHash), (Pk, bitcoin::taproot::Signature)>
272+
}
273+
274+
impl_satisfier_for_map_hash_tapleafhash_to_key_taproot_sig! {
275+
impl Satisfier<Pk> for HashMap<(hash160::Hash, TapLeafHash), (Pk, bitcoin::taproot::Signature)>
263276
}
264277

265278
impl<'a, Pk: MiniscriptKey + ToPublicKey, S: Satisfier<Pk>> Satisfier<Pk> for &'a S {

0 commit comments

Comments
 (0)