vm: drop duplicating stackItem structure, build JSON from Parameters

smartcontract.Parameter has everything needed now.
This commit is contained in:
Roman Khimov 2020-03-03 13:05:57 +03:00
parent 9b4fd99fbc
commit 56e37ad6ba
4 changed files with 20 additions and 50 deletions

View file

@ -6,6 +6,7 @@ import (
"fmt"
"math/big"
"github.com/CityOfZion/neo-go/pkg/smartcontract"
"github.com/CityOfZion/neo-go/pkg/vm/emit"
)
@ -469,7 +470,18 @@ func (s *Stack) popSigElements() ([][]byte, error) {
return elems, nil
}
// ToContractParameters converts Stack to slice of smartcontract.Parameter.
func (s *Stack) ToContractParameters() []smartcontract.Parameter {
items := make([]smartcontract.Parameter, 0, s.Len())
s.IterBack(func(e *Element) {
// Each item is independent.
seen := make(map[StackItem]bool)
items = append(items, e.value.ToContractParameter(seen))
})
return items
}
// MarshalJSON implements JSON marshalling interface.
func (s *Stack) MarshalJSON() ([]byte, error) {
return json.Marshal(stackToArray(s))
return json.Marshal(s.ToContractParameters())
}