fix(iter): translate_pk to iterate in left-to-right order - #1025
Conversation
|
In 66c6c9e: Let's keep |
`Miniscript::translate_pk` and `Descriptor::translate_pk`, along with the concrete and semantic policy equivalents, drove their reconstruction from a right-to-left post-order iterator. That existed only so a node could be rebuilt as `Terminal::AndB(stack.pop().unwrap(), stack.pop().unwrap())`. - iterate with `post_order_iter` everywhere `rtl_post_order_iter` was used - bind popped children explicitly so they are passed in left-to-right order - take n-ary children off the stack with `split_off` rather than repeated pops Fixes rust-bitcoin#1022
Add a crate-private `StackExt` trait on `Vec<T>` with helper methods for reconstructing Thresholds. - `pop2`/`pop3` pop the top two or three elements and pass them, left to right, to a constructor or closure - `pop_n` pops the top `n` elements in order, for the `Vec`-shaped policy nodes - `pop_thresh` pops a threshold's children and rebuilds it with the same `k`
6b3e854 to
b413b93
Compare
restored it and amended into the first commit. |
|
In b413b93: I'd suggest squashing these two commits since the second largely overwrites the first. I like the idea of pulling this into a Then, I don't like the use of |
roger that. i had it separate in case i needed to drop it off |
First commit is the actual conversion. Deleted all the
RtlPostOrderIter stuff, which is a breaking change. Let me know if you
want that in a separate commit.
Second commit with the Ext trait can be dropped, but I didn't want to
ruin the readability of Terminal mappings.
Closes #1022