Skip to content

Commit 20ca6a5

Browse files
committed
Implement Satisfier for map<Pk, bitcoin::ecdsa::Signature>
Define a marco that when called looks reasonably similar to the original code to implement `Satisfier<Pk> for map<Pk, bitcoin::ecdsa::Signature` and call it with `BTreeMap` and `HashMap`. This is an API addition, `HashMap` is imported from `hashbrown` for no-std builds.
1 parent d1c61e4 commit 20ca6a5

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/miniscript/satisfy.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,26 @@ impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for absolute::LockTime {
153153
}
154154
}
155155
}
156-
impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for HashMap<Pk, bitcoin::ecdsa::Signature> {
157-
fn lookup_ecdsa_sig(&self, key: &Pk) -> Option<bitcoin::ecdsa::Signature> {
158-
self.get(key).copied()
159-
}
156+
157+
macro_rules! impl_satisfier_for_map_key_to_ecdsa_sig {
158+
($(#[$($attr:meta)*])* impl Satisfier<Pk> for $map:ident<$key:ty, $val:ty>) => {
159+
$(#[$($attr)*])*
160+
impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk>
161+
for $map<Pk, bitcoin::ecdsa::Signature>
162+
{
163+
fn lookup_ecdsa_sig(&self, key: &Pk) -> Option<bitcoin::ecdsa::Signature> {
164+
self.get(key).copied()
165+
}
166+
}
167+
};
168+
}
169+
170+
impl_satisfier_for_map_key_to_ecdsa_sig! {
171+
impl Satisfier<Pk> for BTreeMap<Pk, bitcoin::ecdsa::Signature>
172+
}
173+
174+
impl_satisfier_for_map_key_to_ecdsa_sig! {
175+
impl Satisfier<Pk> for HashMap<Pk, bitcoin::ecdsa::Signature>
160176
}
161177

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

0 commit comments

Comments
 (0)