neoneo-go/pkg/core/interop/json/json.go

29 lines
626 B
Go
Raw Normal View History

2020-06-11 14:17:15 +00:00
package json
import (
"github.com/nspcc-dev/neo-go/pkg/core/interop"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
)
// Serialize handles System.JSON.Serialize syscall.
2020-08-07 11:37:49 +00:00
func Serialize(ic *interop.Context) error {
item := ic.VM.Estack().Pop().Item()
2020-06-11 14:17:15 +00:00
data, err := stackitem.ToJSON(item)
if err != nil {
return err
}
2020-08-07 11:37:49 +00:00
ic.VM.Estack().PushVal(data)
2020-06-11 14:17:15 +00:00
return nil
}
// Deserialize handles System.JSON.Deserialize syscall.
2020-08-07 11:37:49 +00:00
func Deserialize(ic *interop.Context) error {
data := ic.VM.Estack().Pop().Bytes()
2020-06-11 14:17:15 +00:00
item, err := stackitem.FromJSON(data)
if err != nil {
return err
}
2020-08-07 11:37:49 +00:00
ic.VM.Estack().PushVal(item)
2020-06-11 14:17:15 +00:00
return nil
}