Skip to content

Commit df11203

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

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

src/miniscript/satisfy.rs

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -204,26 +204,39 @@ impl_satisfier_for_map_key_hash_to_taproot_sig! {
204204
impl Satisfier<Pk> for HashMap<(Pk, TapLeafHash), bitcoin::taproot::Signature>
205205
}
206206

207-
impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk>
208-
for HashMap<hash160::Hash, (Pk, bitcoin::ecdsa::Signature)>
209-
where
210-
Pk: MiniscriptKey + ToPublicKey,
211-
{
212-
fn lookup_ecdsa_sig(&self, key: &Pk) -> Option<bitcoin::ecdsa::Signature> {
213-
self.get(&key.to_pubkeyhash(SigType::Ecdsa)).map(|x| x.1)
214-
}
207+
macro_rules! impl_satisfier_for_map_hash_to_key_ecdsa_sig {
208+
($(#[$($attr:meta)*])* impl Satisfier<Pk> for $map:ident<$key:ty, $val:ty>) => {
209+
$(#[$($attr)*])*
210+
impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk>
211+
for $map<hash160::Hash, (Pk, bitcoin::ecdsa::Signature)>
212+
where
213+
Pk: MiniscriptKey + ToPublicKey,
214+
{
215+
fn lookup_ecdsa_sig(&self, key: &Pk) -> Option<bitcoin::ecdsa::Signature> {
216+
self.get(&key.to_pubkeyhash(SigType::Ecdsa)).map(|x| x.1)
217+
}
215218

216-
fn lookup_raw_pkh_pk(&self, pk_hash: &hash160::Hash) -> Option<bitcoin::PublicKey> {
217-
self.get(pk_hash).map(|x| x.0.to_public_key())
218-
}
219+
fn lookup_raw_pkh_pk(&self, pk_hash: &hash160::Hash) -> Option<bitcoin::PublicKey> {
220+
self.get(pk_hash).map(|x| x.0.to_public_key())
221+
}
219222

220-
fn lookup_raw_pkh_ecdsa_sig(
221-
&self,
222-
pk_hash: &hash160::Hash,
223-
) -> Option<(bitcoin::PublicKey, bitcoin::ecdsa::Signature)> {
224-
self.get(pk_hash)
225-
.map(|&(ref pk, sig)| (pk.to_public_key(), sig))
226-
}
223+
fn lookup_raw_pkh_ecdsa_sig(
224+
&self,
225+
pk_hash: &hash160::Hash,
226+
) -> Option<(bitcoin::PublicKey, bitcoin::ecdsa::Signature)> {
227+
self.get(pk_hash)
228+
.map(|&(ref pk, sig)| (pk.to_public_key(), sig))
229+
}
230+
}
231+
};
232+
}
233+
234+
impl_satisfier_for_map_hash_to_key_ecdsa_sig! {
235+
impl Satisfier<Pk> for BTreeMap<hash160::Hash, (Pk, bitcoin::ecdsa::Signature)>
236+
}
237+
238+
impl_satisfier_for_map_hash_to_key_ecdsa_sig! {
239+
impl Satisfier<Pk> for HashMap<hash160::Hash, (Pk, bitcoin::ecdsa::Signature)>
227240
}
228241

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

0 commit comments

Comments
 (0)