Skip to content

Commit 062e400

Browse files
committed
Use TreeLike to implement keys
Remove recursive calls and use `TreeLike`'s post order iterator to get all the keys from a `concrete::Policy`.
1 parent ccacce0 commit 062e400

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/policy/concrete.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -668,19 +668,13 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
668668

669669
/// Gets all keys in the policy.
670670
pub fn keys(&self) -> Vec<&Pk> {
671-
match *self {
672-
Policy::Key(ref pk) => vec![pk],
673-
Policy::Threshold(_k, ref subs) => {
674-
subs.iter().flat_map(|sub| sub.keys()).collect::<Vec<_>>()
671+
let mut keys = vec![];
672+
for data in self.post_order_iter() {
673+
if let Policy::Key(ref pk) = data.node {
674+
keys.push(pk);
675675
}
676-
Policy::And(ref subs) => subs.iter().flat_map(|sub| sub.keys()).collect::<Vec<_>>(),
677-
Policy::Or(ref subs) => subs
678-
.iter()
679-
.flat_map(|(ref _k, ref sub)| sub.keys())
680-
.collect::<Vec<_>>(),
681-
// map all hashes and time
682-
_ => vec![],
683676
}
677+
keys
684678
}
685679

686680
/// Gets the number of [TapLeaf](`TapTree::Leaf`)s considering exhaustive root-level [`Policy::Or`]

0 commit comments

Comments
 (0)