vm: add IterBack to the Stack to iterate bottom-to-top

And use it to build user-facing stack representation because that's the order
that C# VM uses.
This commit is contained in:
Roman Khimov 2019-11-26 19:53:30 +03:00
parent f3ed91a1f7
commit 05f3329ec0
3 changed files with 43 additions and 5 deletions

View file

@ -360,6 +360,17 @@ func (s *Stack) Iter(f func(*Element)) {
}
}
// IterBack iterates over all the elements of the stack, starting from the bottom
// of the stack.
// s.IterBack(func(elem *Element) {
// // do something with the element.
// })
func (s *Stack) IterBack(f func(*Element)) {
for e := s.Back(); e != nil; e = e.Prev() {
f(e)
}
}
// popSigElements pops keys or signatures from the stack as needed for
// CHECKMULTISIG.
func (s *Stack) popSigElements() ([][]byte, error) {