forked from TrueCloudLab/neoneo-go
core: move Neo.Storage.* interops to System.*
This commit is contained in:
parent
0472a0b0b1
commit
38d020d1a2
7 changed files with 23 additions and 29 deletions
|
@ -11,13 +11,13 @@ var syscalls = map[string]map[string]string{
|
||||||
"Value": "System.Enumerator.Value",
|
"Value": "System.Enumerator.Value",
|
||||||
},
|
},
|
||||||
"storage": {
|
"storage": {
|
||||||
"ConvertContextToReadOnly": "Neo.StorageContext.AsReadOnly",
|
"ConvertContextToReadOnly": "System.Storage.AsReadOnly",
|
||||||
"Delete": "Neo.Storage.Delete",
|
"Delete": "System.Storage.Delete",
|
||||||
"Find": "Neo.Storage.Find",
|
"Find": "System.Storage.Find",
|
||||||
"Get": "Neo.Storage.Get",
|
"Get": "System.Storage.Get",
|
||||||
"GetContext": "Neo.Storage.GetContext",
|
"GetContext": "System.Storage.GetContext",
|
||||||
"GetReadOnlyContext": "Neo.Storage.GetReadOnlyContext",
|
"GetReadOnlyContext": "System.Storage.GetReadOnlyContext",
|
||||||
"Put": "Neo.Storage.Put",
|
"Put": "System.Storage.Put",
|
||||||
},
|
},
|
||||||
"runtime": {
|
"runtime": {
|
||||||
"GetTrigger": "System.Runtime.GetTrigger",
|
"GetTrigger": "System.Runtime.GetTrigger",
|
||||||
|
|
|
@ -82,9 +82,9 @@ func newStoragePlugin() *storagePlugin {
|
||||||
mem: make(map[string][]byte),
|
mem: make(map[string][]byte),
|
||||||
interops: make(map[uint32]vm.InteropFunc),
|
interops: make(map[uint32]vm.InteropFunc),
|
||||||
}
|
}
|
||||||
s.interops[emit.InteropNameToID([]byte("Neo.Storage.Get"))] = s.Get
|
s.interops[emit.InteropNameToID([]byte("System.Storage.Get"))] = s.Get
|
||||||
s.interops[emit.InteropNameToID([]byte("Neo.Storage.Put"))] = s.Put
|
s.interops[emit.InteropNameToID([]byte("System.Storage.Put"))] = s.Put
|
||||||
s.interops[emit.InteropNameToID([]byte("Neo.Storage.GetContext"))] = s.GetContext
|
s.interops[emit.InteropNameToID([]byte("System.Storage.GetContext"))] = s.GetContext
|
||||||
s.interops[emit.InteropNameToID([]byte("System.Runtime.Notify"))] = s.Notify
|
s.interops[emit.InteropNameToID([]byte("System.Runtime.Notify"))] = s.Notify
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
|
@ -94,12 +94,13 @@ var systemInterops = []interop.Function{
|
||||||
{Name: "System.Runtime.Platform", Func: runtimePlatform, Price: 1},
|
{Name: "System.Runtime.Platform", Func: runtimePlatform, Price: 1},
|
||||||
{Name: "System.Runtime.Serialize", Func: runtimeSerialize, Price: 1},
|
{Name: "System.Runtime.Serialize", Func: runtimeSerialize, Price: 1},
|
||||||
{Name: "System.Storage.Delete", Func: storageDelete, Price: 100},
|
{Name: "System.Storage.Delete", Func: storageDelete, Price: 100},
|
||||||
|
{Name: "System.Storage.Find", Func: storageFind, Price: 1},
|
||||||
{Name: "System.Storage.Get", Func: storageGet, Price: 100},
|
{Name: "System.Storage.Get", Func: storageGet, Price: 100},
|
||||||
{Name: "System.Storage.GetContext", Func: storageGetContext, Price: 1},
|
{Name: "System.Storage.GetContext", Func: storageGetContext, Price: 1},
|
||||||
{Name: "System.Storage.GetReadOnlyContext", Func: storageGetReadOnlyContext, Price: 1},
|
{Name: "System.Storage.GetReadOnlyContext", Func: storageGetReadOnlyContext, Price: 1},
|
||||||
{Name: "System.Storage.Put", Func: storagePut, Price: 0}, // These don't have static price in C# code.
|
{Name: "System.Storage.Put", Func: storagePut, Price: 0}, // These don't have static price in C# code.
|
||||||
{Name: "System.Storage.PutEx", Func: storagePutEx, Price: 0},
|
{Name: "System.Storage.PutEx", Func: storagePutEx, Price: 0},
|
||||||
{Name: "System.StorageContext.AsReadOnly", Func: storageContextAsReadOnly, Price: 1},
|
{Name: "System.Storage.AsReadOnly", Func: storageContextAsReadOnly, Price: 1},
|
||||||
}
|
}
|
||||||
|
|
||||||
var neoInterops = []interop.Function{
|
var neoInterops = []interop.Function{
|
||||||
|
@ -113,13 +114,6 @@ var neoInterops = []interop.Function{
|
||||||
{Name: "Neo.Crypto.ECDsaCheckMultiSig", Func: crypto.ECDSACheckMultisig, Price: 1},
|
{Name: "Neo.Crypto.ECDsaCheckMultiSig", Func: crypto.ECDSACheckMultisig, Price: 1},
|
||||||
{Name: "Neo.Crypto.SHA256", Func: crypto.Sha256, Price: 1},
|
{Name: "Neo.Crypto.SHA256", Func: crypto.Sha256, Price: 1},
|
||||||
{Name: "Neo.Native.Deploy", Func: native.Deploy, Price: 1},
|
{Name: "Neo.Native.Deploy", Func: native.Deploy, Price: 1},
|
||||||
{Name: "Neo.Storage.Delete", Func: storageDelete, Price: 100},
|
|
||||||
{Name: "Neo.Storage.Find", Func: storageFind, Price: 1},
|
|
||||||
{Name: "Neo.Storage.Get", Func: storageGet, Price: 100},
|
|
||||||
{Name: "Neo.Storage.GetContext", Func: storageGetContext, Price: 1},
|
|
||||||
{Name: "Neo.Storage.GetReadOnlyContext", Func: storageGetReadOnlyContext, Price: 1},
|
|
||||||
{Name: "Neo.Storage.Put", Func: storagePut, Price: 0},
|
|
||||||
{Name: "Neo.StorageContext.AsReadOnly", Func: storageContextAsReadOnly, Price: 1},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// initIDinInteropsSlice initializes IDs from names in one given
|
// initIDinInteropsSlice initializes IDs from names in one given
|
||||||
|
|
|
@ -17,38 +17,38 @@ type Context struct{}
|
||||||
// ConvertContextToReadOnly returns new context from the given one, but with
|
// ConvertContextToReadOnly returns new context from the given one, but with
|
||||||
// writing capability turned off, so that you could only invoke Get and Find
|
// writing capability turned off, so that you could only invoke Get and Find
|
||||||
// using this new Context. If Context is already read-only this function is a
|
// using this new Context. If Context is already read-only this function is a
|
||||||
// no-op. It uses `Neo.StorageContext.AsReadOnly` syscall.
|
// no-op. It uses `System.Storage.AsReadOnly` syscall.
|
||||||
func ConvertContextToReadOnly(ctx Context) Context { return Context{} }
|
func ConvertContextToReadOnly(ctx Context) Context { return Context{} }
|
||||||
|
|
||||||
// GetContext returns current contract's (that invokes this function) storage
|
// GetContext returns current contract's (that invokes this function) storage
|
||||||
// context. It uses `Neo.Storage.GetContext` syscall.
|
// context. It uses `System.Storage.GetContext` syscall.
|
||||||
func GetContext() Context { return Context{} }
|
func GetContext() Context { return Context{} }
|
||||||
|
|
||||||
// GetReadOnlyContext returns current contract's (that invokes this function)
|
// GetReadOnlyContext returns current contract's (that invokes this function)
|
||||||
// storage context in read-only mode, you can use this context for Get and Find
|
// storage context in read-only mode, you can use this context for Get and Find
|
||||||
// functions, but using it for Put and Delete will fail. It uses
|
// functions, but using it for Put and Delete will fail. It uses
|
||||||
// `Neo.Storage.GetReadOnlyContext` syscall.
|
// `System.Storage.GetReadOnlyContext` syscall.
|
||||||
func GetReadOnlyContext() Context { return Context{} }
|
func GetReadOnlyContext() Context { return Context{} }
|
||||||
|
|
||||||
// Put saves given value with given key in the storage using given Context.
|
// Put saves given value with given key in the storage using given Context.
|
||||||
// Even though it accepts interface{} for both, you can only pass simple types
|
// Even though it accepts interface{} for both, you can only pass simple types
|
||||||
// there like string, []byte, int or bool (not structures or slices of more
|
// there like string, []byte, int or bool (not structures or slices of more
|
||||||
// complex types). To put more complex types there serialize them first using
|
// complex types). To put more complex types there serialize them first using
|
||||||
// runtime.Serialize. This function uses `Neo.Storage.Put` syscall.
|
// runtime.Serialize. This function uses `System.Storage.Put` syscall.
|
||||||
func Put(ctx Context, key interface{}, value interface{}) {}
|
func Put(ctx Context, key interface{}, value interface{}) {}
|
||||||
|
|
||||||
// Get retrieves value stored for the given key using given Context. See Put
|
// Get retrieves value stored for the given key using given Context. See Put
|
||||||
// documentation on possible key and value types. This function uses
|
// documentation on possible key and value types. This function uses
|
||||||
// `Neo.Storage.Get` syscall.
|
// `System.Storage.Get` syscall.
|
||||||
func Get(ctx Context, key interface{}) interface{} { return 0 }
|
func Get(ctx Context, key interface{}) interface{} { return 0 }
|
||||||
|
|
||||||
// Delete removes key-value pair from storage by the given key using given
|
// Delete removes key-value pair from storage by the given key using given
|
||||||
// Context. See Put documentation on possible key types. This function uses
|
// Context. See Put documentation on possible key types. This function uses
|
||||||
// `Neo.Storage.Delete` syscall.
|
// `System.Storage.Delete` syscall.
|
||||||
func Delete(ctx Context, key interface{}) {}
|
func Delete(ctx Context, key interface{}) {}
|
||||||
|
|
||||||
// Find returns an iterator.Iterator over key-value pairs in the given Context
|
// Find returns an iterator.Iterator over key-value pairs in the given Context
|
||||||
// that match the given key (contain it as a prefix). See Put documentation on
|
// that match the given key (contain it as a prefix). See Put documentation on
|
||||||
// possible key types and iterator package documentation on how to use the
|
// possible key types and iterator package documentation on how to use the
|
||||||
// returned value. This function uses `Neo.Storage.Find` syscall.
|
// returned value. This function uses `System.Storage.Find` syscall.
|
||||||
func Find(ctx Context, key interface{}) iterator.Iterator { return iterator.Iterator{} }
|
func Find(ctx Context, key interface{}) iterator.Iterator { return iterator.Iterator{} }
|
||||||
|
|
|
@ -49,18 +49,18 @@ type rpcTestCase struct {
|
||||||
check func(t *testing.T, e *executor, result interface{})
|
check func(t *testing.T, e *executor, result interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
const testContractHash = "1b061f2295cdf0f4350e12746b8492a364fdd121"
|
const testContractHash = "279c86355b30d452386c1717e2ffa01c9dac31f3"
|
||||||
|
|
||||||
var rpcTestCases = map[string][]rpcTestCase{
|
var rpcTestCases = map[string][]rpcTestCase{
|
||||||
"getapplicationlog": {
|
"getapplicationlog": {
|
||||||
{
|
{
|
||||||
name: "positive",
|
name: "positive",
|
||||||
params: `["88da760745bd6cf2c58c7ad1cf206e4cc251c664e65b668fa0df474e68ee5ed3"]`,
|
params: `["328190e78f1b5b8dcf86e71ec1894d6144f4e4cdb25abc20ea02b618851941dd"]`,
|
||||||
result: func(e *executor) interface{} { return &result.ApplicationLog{} },
|
result: func(e *executor) interface{} { return &result.ApplicationLog{} },
|
||||||
check: func(t *testing.T, e *executor, acc interface{}) {
|
check: func(t *testing.T, e *executor, acc interface{}) {
|
||||||
res, ok := acc.(*result.ApplicationLog)
|
res, ok := acc.(*result.ApplicationLog)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
expectedTxHash, err := util.Uint256DecodeStringLE("88da760745bd6cf2c58c7ad1cf206e4cc251c664e65b668fa0df474e68ee5ed3")
|
expectedTxHash, err := util.Uint256DecodeStringLE("328190e78f1b5b8dcf86e71ec1894d6144f4e4cdb25abc20ea02b618851941dd")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, expectedTxHash, res.TxHash)
|
assert.Equal(t, expectedTxHash, res.TxHash)
|
||||||
assert.Equal(t, 1, len(res.Executions))
|
assert.Equal(t, 1, len(res.Executions))
|
||||||
|
@ -484,7 +484,7 @@ var rpcTestCases = map[string][]rpcTestCase{
|
||||||
"gettransactionheight": {
|
"gettransactionheight": {
|
||||||
{
|
{
|
||||||
name: "positive",
|
name: "positive",
|
||||||
params: `["88da760745bd6cf2c58c7ad1cf206e4cc251c664e65b668fa0df474e68ee5ed3"]`,
|
params: `["328190e78f1b5b8dcf86e71ec1894d6144f4e4cdb25abc20ea02b618851941dd"]`,
|
||||||
result: func(e *executor) interface{} {
|
result: func(e *executor) interface{} {
|
||||||
h := 0
|
h := 0
|
||||||
return &h
|
return &h
|
||||||
|
|
BIN
pkg/rpc/server/testdata/test_contract.avm
vendored
BIN
pkg/rpc/server/testdata/test_contract.avm
vendored
Binary file not shown.
BIN
pkg/rpc/server/testdata/testblocks.acc
vendored
BIN
pkg/rpc/server/testdata/testblocks.acc
vendored
Binary file not shown.
Loading…
Reference in a new issue