vm: allow to convert stack to a slice

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2020-07-29 12:59:19 +03:00
parent 805f746f15
commit 7b4acd5a7f
2 changed files with 25 additions and 0 deletions

View file

@ -396,6 +396,15 @@ func (s *Stack) PopSigElements() ([][]byte, error) {
return elems, nil
}
// ToArray converts stack to an array of stackitems with top item being the last.
func (s *Stack) ToArray() []stackitem.Item {
items := make([]stackitem.Item, 0, s.len)
s.IterBack(func(e *Element) {
items = append(items, e.Item())
})
return items
}
// ToContractParameters converts Stack to slice of smartcontract.Parameter.
func (s *Stack) ToContractParameters() []smartcontract.Parameter {
items := make([]smartcontract.Parameter, 0, s.Len())