vm: implement serialization interops in core package
This commit is contained in:
parent
412582dc78
commit
ed758458d5
4 changed files with 22 additions and 12 deletions
|
@ -736,3 +736,13 @@ func (ic *interopContext) assetRenew(v *vm.VM) error {
|
|||
v.Estack().PushVal(expiration)
|
||||
return nil
|
||||
}
|
||||
|
||||
// runtimeSerialize serializes top stack item into a ByteArray.
|
||||
func (ic *interopContext) runtimeSerialize(v *vm.VM) error {
|
||||
return vm.RuntimeSerialize(v)
|
||||
}
|
||||
|
||||
// runtimeDeserialize deserializes ByteArray from a stack into an item.
|
||||
func (ic *interopContext) runtimeDeserialize(v *vm.VM) error {
|
||||
return vm.RuntimeDeserialize(v)
|
||||
}
|
||||
|
|
|
@ -64,8 +64,8 @@ func (ic *interopContext) getSystemInteropMap() map[string]vm.InteropFuncPrice {
|
|||
"System.Storage.PutEx": {Func: ic.storagePutEx, Price: 0},
|
||||
"System.StorageContext.AsReadOnly": {Func: ic.storageContextAsReadOnly, Price: 1},
|
||||
"System.Transaction.GetHash": {Func: ic.txGetHash, Price: 1},
|
||||
// "System.Runtime.Deserialize": {Func: ic.runtimeDeserialize, Price: 1},
|
||||
// "System.Runtime.Serialize": {Func: ic.runtimeSerialize, Price: 1},
|
||||
"System.Runtime.Deserialize": {Func: ic.runtimeDeserialize, Price: 1},
|
||||
"System.Runtime.Serialize": {Func: ic.runtimeSerialize, Price: 1},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,8 +148,8 @@ func (ic *interopContext) getNeoInteropMap() map[string]vm.InteropFuncPrice {
|
|||
// "Neo.Iterator.Key": {Func: ic.iteratorKey, Price: 1},
|
||||
// "Neo.Iterator.Keys": {Func: ic.iteratorKeys, Price: 1},
|
||||
// "Neo.Iterator.Values": {Func: ic.iteratorValues, Price: 1},
|
||||
// "Neo.Runtime.Deserialize": {Func: ic.runtimeDeserialize, Price: 1},
|
||||
// "Neo.Runtime.Serialize": {Func: ic.runtimeSerialize, Price: 1},
|
||||
"Neo.Runtime.Deserialize": {Func: ic.runtimeDeserialize, Price: 1},
|
||||
"Neo.Runtime.Serialize": {Func: ic.runtimeSerialize, Price: 1},
|
||||
// "Neo.Storage.Find": {Func: ic.storageFind, Price: 1},
|
||||
// "Neo.Witness.GetVerificationScript": {Func: ic.witnessGetVerificationScript, Price: 100},
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ func runtimeNotify(vm *VM) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// runtimeSerialize handles syscalls System.Runtime.Serialize and Neo.Runtime.Serialize.
|
||||
func runtimeSerialize(vm *VM) error {
|
||||
// RuntimeSerialize handles syscalls System.Runtime.Serialize and Neo.Runtime.Serialize.
|
||||
func RuntimeSerialize(vm *VM) error {
|
||||
item := vm.Estack().Pop()
|
||||
data, err := serializeItem(item.value)
|
||||
if err != nil {
|
||||
|
@ -37,8 +37,8 @@ func runtimeSerialize(vm *VM) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// runtimeDeserialize handles syscalls System.Runtime.Deserialize and Neo.Runtime.Deserialize.
|
||||
func runtimeDeserialize(vm *VM) error {
|
||||
// RuntimeDeserialize handles syscalls System.Runtime.Deserialize and Neo.Runtime.Deserialize.
|
||||
func RuntimeDeserialize(vm *VM) error {
|
||||
data := vm.Estack().Pop().Bytes()
|
||||
|
||||
item, err := deserializeItem(data)
|
||||
|
|
|
@ -86,10 +86,10 @@ func New() *VM {
|
|||
// Register native interop hooks.
|
||||
vm.RegisterInteropFunc("Neo.Runtime.Log", runtimeLog, 1)
|
||||
vm.RegisterInteropFunc("Neo.Runtime.Notify", runtimeNotify, 1)
|
||||
vm.RegisterInteropFunc("Neo.Runtime.Serialize", runtimeSerialize, 1)
|
||||
vm.RegisterInteropFunc("System.Runtime.Serialize", runtimeSerialize, 1)
|
||||
vm.RegisterInteropFunc("Neo.Runtime.Deserialize", runtimeDeserialize, 1)
|
||||
vm.RegisterInteropFunc("System.Runtime.Deserialize", runtimeDeserialize, 1)
|
||||
vm.RegisterInteropFunc("Neo.Runtime.Serialize", RuntimeSerialize, 1)
|
||||
vm.RegisterInteropFunc("System.Runtime.Serialize", RuntimeSerialize, 1)
|
||||
vm.RegisterInteropFunc("Neo.Runtime.Deserialize", RuntimeDeserialize, 1)
|
||||
vm.RegisterInteropFunc("System.Runtime.Deserialize", RuntimeDeserialize, 1)
|
||||
|
||||
return vm
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue