diff --git a/src/policy/concrete.rs b/src/policy/concrete.rs index 8bf1b85..ab89af7 100644 --- a/src/policy/concrete.rs +++ b/src/policy/concrete.rs @@ -662,7 +662,12 @@ impl ForEachKey for Policy { where Pk: 'a, { - let mut pred = |x| pred(x); + self.for_each_key_internal(&mut pred) + } +} + +impl Policy { + fn for_each_key_internal<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: &mut F) -> bool { match *self { Policy::Unsatisfiable | Policy::Trivial => true, Policy::Key(ref pk) => pred(pk), @@ -673,14 +678,12 @@ impl ForEachKey for Policy { | Policy::After(..) | Policy::Older(..) => true, Policy::Threshold(_, ref subs) | Policy::And(ref subs) => { - subs.iter().all(|sub| sub.for_each_key(&mut pred)) + subs.iter().all(|sub| sub.for_each_key_internal(pred)) } - Policy::Or(ref subs) => subs.iter().all(|(_, sub)| sub.for_each_key(&mut pred)), + Policy::Or(ref subs) => subs.iter().all(|(_, sub)| sub.for_each_key_internal(pred)), } } -} -impl Policy { /// Convert a policy using one kind of public key to another /// type of public key /// diff --git a/src/policy/semantic.rs b/src/policy/semantic.rs index 1dbb30a..3e7e532 100644 --- a/src/policy/semantic.rs +++ b/src/policy/semantic.rs @@ -10,7 +10,7 @@ use elements::{LockTime, Sequence}; use super::concrete::PolicyError; use super::ENTAILMENT_MAX_TERMINALS; -use crate::{errstr, expression, AbsLockTime, Error, ForEachKey, MiniscriptKey, Translator}; +use crate::{errstr, expression, AbsLockTime, Error, MiniscriptKey, Translator}; /// Abstract policy which corresponds to the semantics of a Miniscript /// and which allows complex forms of analysis, e.g. filtering and @@ -59,26 +59,6 @@ where } } -impl ForEachKey for Policy { - fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, mut pred: F) -> bool - where - Pk: 'a, - { - let mut pred = |x| pred(x); - match *self { - Policy::Unsatisfiable | Policy::Trivial => true, - Policy::Key(ref _pkh) => todo!("Semantic Policy KeyHash must store Pk"), - Policy::Sha256(..) - | Policy::Hash256(..) - | Policy::Ripemd160(..) - | Policy::Hash160(..) - | Policy::After(..) - | Policy::Older(..) => true, - Policy::Threshold(_, ref subs) => subs.iter().all(|sub| sub.for_each_key(&mut pred)), - } - } -} - impl Policy { /// Convert a policy using one kind of public key to another /// type of public key