Skip to content

Commit 6298c69

Browse files
committed
Implement Satisfier for map of hash to (key, ecdsa sig)
Add a macro and call it to duplicate the current implementation of `Satisfier<Pk> for HashMap<Hash, (Pk, bitcoin::ecdsa::Signature)>` for `BTreeMap`.
1 parent e130882 commit 6298c69

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

src/miniscript/satisfy.rs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -198,27 +198,36 @@ macro_rules! impl_satisfier_for_map_key_hash_to_taproot_sig {
198198
#[rustfmt::skip]
199199
impl_satisfier_for_map_key_hash_to_taproot_sig!(BTreeMap, #[cfg(feature = "std")] HashMap);
200200

201-
impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk>
202-
for HashMap<hash160::Hash, (Pk, bitcoin::ecdsa::Signature)>
203-
where
204-
Pk: MiniscriptKey + ToPublicKey,
205-
{
206-
fn lookup_ecdsa_sig(&self, key: &Pk) -> Option<bitcoin::ecdsa::Signature> {
207-
self.get(&key.to_pubkeyhash(SigType::Ecdsa)).map(|x| x.1)
208-
}
201+
macro_rules! impl_satisfier_for_map_hash_to_key_ecdsa_sig {
202+
($($(#[cfg($attr:meta)])* $map:ident),*) => {
203+
$(
204+
$(#[cfg($attr)])*
205+
impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk>
206+
for $map<hash160::Hash, (Pk, bitcoin::ecdsa::Signature)>
207+
where
208+
Pk: MiniscriptKey + ToPublicKey,
209+
{
210+
fn lookup_ecdsa_sig(&self, key: &Pk) -> Option<bitcoin::ecdsa::Signature> {
211+
self.get(&key.to_pubkeyhash(SigType::Ecdsa)).map(|x| x.1)
212+
}
209213

210-
fn lookup_raw_pkh_pk(&self, pk_hash: &hash160::Hash) -> Option<bitcoin::PublicKey> {
211-
self.get(pk_hash).map(|x| x.0.to_public_key())
212-
}
214+
fn lookup_raw_pkh_pk(&self, pk_hash: &hash160::Hash) -> Option<bitcoin::PublicKey> {
215+
self.get(pk_hash).map(|x| x.0.to_public_key())
216+
}
213217

214-
fn lookup_raw_pkh_ecdsa_sig(
215-
&self,
216-
pk_hash: &hash160::Hash,
217-
) -> Option<(bitcoin::PublicKey, bitcoin::ecdsa::Signature)> {
218-
self.get(pk_hash)
219-
.map(|&(ref pk, sig)| (pk.to_public_key(), sig))
218+
fn lookup_raw_pkh_ecdsa_sig(
219+
&self,
220+
pk_hash: &hash160::Hash,
221+
) -> Option<(bitcoin::PublicKey, bitcoin::ecdsa::Signature)> {
222+
self.get(pk_hash)
223+
.map(|&(ref pk, sig)| (pk.to_public_key(), sig))
224+
}
225+
}
226+
)*
220227
}
221228
}
229+
#[rustfmt::skip]
230+
impl_satisfier_for_map_hash_to_key_ecdsa_sig!(BTreeMap, #[cfg(feature = "std")] HashMap);
222231

223232
impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk>
224233
for HashMap<(hash160::Hash, TapLeafHash), (Pk, bitcoin::taproot::Signature)>

0 commit comments

Comments
 (0)