Skip to content

Commit 4db13df

Browse files
committed
Implement Satisfier for map (hash, tapleafhash) to (key, taproot sig)
Add a macro and call it to duplicate the current implementation of `Satisfier<Pk> for HashMap<(hash160::Hash, TapLeafHash), (Pk, bitcoin::taproot::Signature)> for a `BTreeMap`.
1 parent d732813 commit 4db13df

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

src/miniscript/satisfy.rs

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -228,29 +228,37 @@ macro_rules! impl_satisfier_for_map_hash_to_key_ecdsa_sig {
228228
}
229229
#[rustfmt::skip]
230230
impl_satisfier_for_map_hash_to_key_ecdsa_sig!(BTreeMap, #[cfg(feature = "std")] HashMap);
231+
macro_rules! impl_satisfier_for_map_hash_tapleafhash_to_key_taproot_sig {
232+
($($(#[cfg($attr:meta)])* $map:ident),*) => {
233+
$(
234+
$(#[cfg($attr)])*
235+
impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk>
236+
for $map<(hash160::Hash, TapLeafHash), (Pk, bitcoin::taproot::Signature)>
237+
where
238+
Pk: MiniscriptKey + ToPublicKey,
239+
{
240+
fn lookup_tap_leaf_script_sig(
241+
&self,
242+
key: &Pk,
243+
h: &TapLeafHash,
244+
) -> Option<bitcoin::taproot::Signature> {
245+
self.get(&(key.to_pubkeyhash(SigType::Schnorr), *h))
246+
.map(|x| x.1)
247+
}
231248

232-
impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk>
233-
for HashMap<(hash160::Hash, TapLeafHash), (Pk, bitcoin::taproot::Signature)>
234-
where
235-
Pk: MiniscriptKey + ToPublicKey,
236-
{
237-
fn lookup_tap_leaf_script_sig(
238-
&self,
239-
key: &Pk,
240-
h: &TapLeafHash,
241-
) -> Option<bitcoin::taproot::Signature> {
242-
self.get(&(key.to_pubkeyhash(SigType::Schnorr), *h))
243-
.map(|x| x.1)
244-
}
245-
246-
fn lookup_raw_pkh_tap_leaf_script_sig(
247-
&self,
248-
pk_hash: &(hash160::Hash, TapLeafHash),
249-
) -> Option<(XOnlyPublicKey, bitcoin::taproot::Signature)> {
250-
self.get(pk_hash)
251-
.map(|&(ref pk, sig)| (pk.to_x_only_pubkey(), sig))
249+
fn lookup_raw_pkh_tap_leaf_script_sig(
250+
&self,
251+
pk_hash: &(hash160::Hash, TapLeafHash),
252+
) -> Option<(XOnlyPublicKey, bitcoin::taproot::Signature)> {
253+
self.get(pk_hash)
254+
.map(|&(ref pk, sig)| (pk.to_x_only_pubkey(), sig))
255+
}
256+
}
257+
)*
252258
}
253259
}
260+
#[rustfmt::skip]
261+
impl_satisfier_for_map_hash_tapleafhash_to_key_taproot_sig!(BTreeMap, #[cfg(feature = "std")] HashMap);
254262

255263
impl<'a, Pk: MiniscriptKey + ToPublicKey, S: Satisfier<Pk>> Satisfier<Pk> for &'a S {
256264
fn lookup_ecdsa_sig(&self, p: &Pk) -> Option<bitcoin::ecdsa::Signature> {

0 commit comments

Comments
 (0)