Skip to content

Commit 42f559f

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

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

src/miniscript/satisfy.rs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,33 @@ impl_satisfier_for_map_key_to_ecdsa_sig! {
175175
impl Satisfier<Pk> for HashMap<Pk, bitcoin::ecdsa::Signature>
176176
}
177177

178-
impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk>
179-
for HashMap<(Pk, TapLeafHash), bitcoin::taproot::Signature>
180-
{
181-
fn lookup_tap_leaf_script_sig(
182-
&self,
183-
key: &Pk,
184-
h: &TapLeafHash,
185-
) -> Option<bitcoin::taproot::Signature> {
186-
// Unfortunately, there is no way to get a &(a, b) from &a and &b without allocating
187-
// If we change the signature the of lookup_tap_leaf_script_sig to accept a tuple. We would
188-
// face the same problem while satisfying PkK.
189-
// We use this signature to optimize for the psbt common use case.
190-
self.get(&(key.clone(), *h)).copied()
191-
}
178+
macro_rules! impl_satisfier_for_map_key_hash_to_taproot_sig {
179+
($(#[$($attr:meta)*])* impl Satisfier<Pk> for $map:ident<$key:ty, $val:ty>) => {
180+
$(#[$($attr)*])*
181+
impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk>
182+
for $map<(Pk, TapLeafHash), bitcoin::taproot::Signature>
183+
{
184+
fn lookup_tap_leaf_script_sig(
185+
&self,
186+
key: &Pk,
187+
h: &TapLeafHash,
188+
) -> Option<bitcoin::taproot::Signature> {
189+
// Unfortunately, there is no way to get a &(a, b) from &a and &b without allocating
190+
// If we change the signature the of lookup_tap_leaf_script_sig to accept a tuple. We would
191+
// face the same problem while satisfying PkK.
192+
// We use this signature to optimize for the psbt common use case.
193+
self.get(&(key.clone(), *h)).copied()
194+
}
195+
}
196+
};
197+
}
198+
199+
impl_satisfier_for_map_key_hash_to_taproot_sig! {
200+
impl Satisfier<Pk> for BTreeMap<(Pk, TapLeafHash), bitcoin::taproot::Signature>
201+
}
202+
203+
impl_satisfier_for_map_key_hash_to_taproot_sig! {
204+
impl Satisfier<Pk> for HashMap<(Pk, TapLeafHash), bitcoin::taproot::Signature>
192205
}
193206

194207
impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk>

0 commit comments

Comments
 (0)