vm: use raw stack items when printing stack

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2020-07-31 15:57:02 +03:00
parent e5d538ed21
commit 54590062e6
2 changed files with 10 additions and 14 deletions

View file

@ -6,7 +6,6 @@ import (
"fmt"
"math/big"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
)
@ -405,18 +404,15 @@ func (s *Stack) ToArray() []stackitem.Item {
return items
}
// 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.Item]bool)
items = append(items, smartcontract.ParameterFromStackItem(e.value, seen))
})
return items
}
// MarshalJSON implements JSON marshalling interface.
func (s *Stack) MarshalJSON() ([]byte, error) {
return json.Marshal(s.ToContractParameters())
items := s.ToArray()
arr := make([]json.RawMessage, len(items))
for i := range items {
data, err := stackitem.ToJSONWithTypes(items[i])
if err == nil {
arr[i] = data
}
}
return json.Marshal(arr)
}

View file

@ -321,7 +321,7 @@ func (v *VM) Stack(n string) string {
if n == "estack" {
s = v.estack
}
b, _ := json.MarshalIndent(s.ToContractParameters(), "", " ")
b, _ := json.MarshalIndent(s, "", " ")
return string(b)
}