Skip to content

Commit bdf6ecc

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 bdf6ecc

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

src/policy/concrete.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -668,19 +668,12 @@ 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<_>>()
675-
}
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![],
683-
}
671+
self.pre_order_iter()
672+
.filter_map(|policy| match policy {
673+
Policy::Key(ref pk) => Some(pk),
674+
_ => None,
675+
})
676+
.collect()
684677
}
685678

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

0 commit comments

Comments
 (0)