forked from TrueCloudLab/neoneo-go
vm: use raw stack items when printing stack
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
e5d538ed21
commit
54590062e6
2 changed files with 10 additions and 14 deletions
|
@ -6,7 +6,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -405,18 +404,15 @@ func (s *Stack) ToArray() []stackitem.Item {
|
||||||
return items
|
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.
|
// MarshalJSON implements JSON marshalling interface.
|
||||||
func (s *Stack) MarshalJSON() ([]byte, error) {
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -321,7 +321,7 @@ func (v *VM) Stack(n string) string {
|
||||||
if n == "estack" {
|
if n == "estack" {
|
||||||
s = v.estack
|
s = v.estack
|
||||||
}
|
}
|
||||||
b, _ := json.MarshalIndent(s.ToContractParameters(), "", " ")
|
b, _ := json.MarshalIndent(s, "", " ")
|
||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue