From 38d020d1a279692f48fbc1847207bbfee528d52f Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 10 Jun 2020 11:55:56 +0300 Subject: [PATCH] core: move Neo.Storage.* interops to System.* --- pkg/compiler/syscall.go | 14 +++++++------- pkg/compiler/vm_test.go | 6 +++--- pkg/core/interops.go | 10 ++-------- pkg/interop/storage/storage.go | 14 +++++++------- pkg/rpc/server/server_test.go | 8 ++++---- pkg/rpc/server/testdata/test_contract.avm | Bin 727 -> 727 bytes pkg/rpc/server/testdata/testblocks.acc | Bin 6516 -> 6516 bytes 7 files changed, 23 insertions(+), 29 deletions(-) diff --git a/pkg/compiler/syscall.go b/pkg/compiler/syscall.go index 8109fffa2..f4fad18b5 100644 --- a/pkg/compiler/syscall.go +++ b/pkg/compiler/syscall.go @@ -11,13 +11,13 @@ var syscalls = map[string]map[string]string{ "Value": "System.Enumerator.Value", }, "storage": { - "ConvertContextToReadOnly": "Neo.StorageContext.AsReadOnly", - "Delete": "Neo.Storage.Delete", - "Find": "Neo.Storage.Find", - "Get": "Neo.Storage.Get", - "GetContext": "Neo.Storage.GetContext", - "GetReadOnlyContext": "Neo.Storage.GetReadOnlyContext", - "Put": "Neo.Storage.Put", + "ConvertContextToReadOnly": "System.Storage.AsReadOnly", + "Delete": "System.Storage.Delete", + "Find": "System.Storage.Find", + "Get": "System.Storage.Get", + "GetContext": "System.Storage.GetContext", + "GetReadOnlyContext": "System.Storage.GetReadOnlyContext", + "Put": "System.Storage.Put", }, "runtime": { "GetTrigger": "System.Runtime.GetTrigger", diff --git a/pkg/compiler/vm_test.go b/pkg/compiler/vm_test.go index 9f8f7142a..fab6b6eac 100644 --- a/pkg/compiler/vm_test.go +++ b/pkg/compiler/vm_test.go @@ -82,9 +82,9 @@ func newStoragePlugin() *storagePlugin { mem: make(map[string][]byte), interops: make(map[uint32]vm.InteropFunc), } - s.interops[emit.InteropNameToID([]byte("Neo.Storage.Get"))] = s.Get - s.interops[emit.InteropNameToID([]byte("Neo.Storage.Put"))] = s.Put - s.interops[emit.InteropNameToID([]byte("Neo.Storage.GetContext"))] = s.GetContext + s.interops[emit.InteropNameToID([]byte("System.Storage.Get"))] = s.Get + s.interops[emit.InteropNameToID([]byte("System.Storage.Put"))] = s.Put + s.interops[emit.InteropNameToID([]byte("System.Storage.GetContext"))] = s.GetContext s.interops[emit.InteropNameToID([]byte("System.Runtime.Notify"))] = s.Notify return s diff --git a/pkg/core/interops.go b/pkg/core/interops.go index d96072b52..c73f48105 100644 --- a/pkg/core/interops.go +++ b/pkg/core/interops.go @@ -94,12 +94,13 @@ var systemInterops = []interop.Function{ {Name: "System.Runtime.Platform", Func: runtimePlatform, Price: 1}, {Name: "System.Runtime.Serialize", Func: runtimeSerialize, Price: 1}, {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.GetContext", Func: storageGetContext, 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.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{ @@ -113,13 +114,6 @@ var neoInterops = []interop.Function{ {Name: "Neo.Crypto.ECDsaCheckMultiSig", Func: crypto.ECDSACheckMultisig, Price: 1}, {Name: "Neo.Crypto.SHA256", Func: crypto.Sha256, 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 diff --git a/pkg/interop/storage/storage.go b/pkg/interop/storage/storage.go index a047eebb1..748157ef6 100644 --- a/pkg/interop/storage/storage.go +++ b/pkg/interop/storage/storage.go @@ -17,38 +17,38 @@ type Context struct{} // ConvertContextToReadOnly returns new context from the given one, but with // 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 -// no-op. It uses `Neo.StorageContext.AsReadOnly` syscall. +// no-op. It uses `System.Storage.AsReadOnly` syscall. func ConvertContextToReadOnly(ctx Context) Context { return Context{} } // 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{} } // GetReadOnlyContext returns current contract's (that invokes this function) // 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 -// `Neo.Storage.GetReadOnlyContext` syscall. +// `System.Storage.GetReadOnlyContext` syscall. func GetReadOnlyContext() Context { return 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 // 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 -// 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{}) {} // Get retrieves value stored for the given key using given Context. See Put // 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 } // Delete removes key-value pair from storage by the given key using given // 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{}) {} // 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 // 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{} } diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index 4d30c07d2..c10180304 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -49,18 +49,18 @@ type rpcTestCase struct { check func(t *testing.T, e *executor, result interface{}) } -const testContractHash = "1b061f2295cdf0f4350e12746b8492a364fdd121" +const testContractHash = "279c86355b30d452386c1717e2ffa01c9dac31f3" var rpcTestCases = map[string][]rpcTestCase{ "getapplicationlog": { { name: "positive", - params: `["88da760745bd6cf2c58c7ad1cf206e4cc251c664e65b668fa0df474e68ee5ed3"]`, + params: `["328190e78f1b5b8dcf86e71ec1894d6144f4e4cdb25abc20ea02b618851941dd"]`, result: func(e *executor) interface{} { return &result.ApplicationLog{} }, check: func(t *testing.T, e *executor, acc interface{}) { res, ok := acc.(*result.ApplicationLog) require.True(t, ok) - expectedTxHash, err := util.Uint256DecodeStringLE("88da760745bd6cf2c58c7ad1cf206e4cc251c664e65b668fa0df474e68ee5ed3") + expectedTxHash, err := util.Uint256DecodeStringLE("328190e78f1b5b8dcf86e71ec1894d6144f4e4cdb25abc20ea02b618851941dd") require.NoError(t, err) assert.Equal(t, expectedTxHash, res.TxHash) assert.Equal(t, 1, len(res.Executions)) @@ -484,7 +484,7 @@ var rpcTestCases = map[string][]rpcTestCase{ "gettransactionheight": { { name: "positive", - params: `["88da760745bd6cf2c58c7ad1cf206e4cc251c664e65b668fa0df474e68ee5ed3"]`, + params: `["328190e78f1b5b8dcf86e71ec1894d6144f4e4cdb25abc20ea02b618851941dd"]`, result: func(e *executor) interface{} { h := 0 return &h diff --git a/pkg/rpc/server/testdata/test_contract.avm b/pkg/rpc/server/testdata/test_contract.avm index 3f23cef22206a5399e438774f107307efdc56fbd..459d4e2218a10e24888c309d04009ca6d91f4c67 100755 GIT binary patch delta 158 zcmcc4dYyHGzVPgC>E{%SvML46RSKR9c6??p(K6AghXo`&@sbhCq}UgRlQ|eozygyU z7-vC5?lIaZgOn=f<#Pl$f)pv1bLVsCbIvR01`6eKLrj`%%VeYiwxOIyAk?w_@TC;R ma$Y6}Cw_)j1-h4i&!pTe)Jm;UgPqR{HWnf@%bpQaQ(>d+{ delta 158 zcmcc4dYyHGzHp1gHD1M{tV)4%m4fGj9fKA+ex2yl!vYeXc*%%GUay*cG6$mxSYWaP z<1C2CJw_X4kW$6Ge2xG|kRru$?tJci&UxkBK%snYh)I)enT%AxHk9)SggUk#zLcU^ l&dcQB#LrO9m(P>Wo6iSTIGM?U$Lw+to0T#v0|SGr0|0S*F_i!S diff --git a/pkg/rpc/server/testdata/testblocks.acc b/pkg/rpc/server/testdata/testblocks.acc index 7e7709a288c0990ab53a619d6dfe83d49efea137..bb02750f547480a62d4c1832ad2c833b447d67e3 100644 GIT binary patch delta 2665 zcmaJ?cRbX69Jf1nKh7B$5h5dG?{$*S$d=ieA$wCsSE0)ucQQ{p#3TDcN>(A{L{=Ks z$z6oUxR7|F=g;T$eE)pEKA-pN`+B{{XG>vAA@eeQLu+uBxd^H~a8lp0hII95%&#U4 z=0?z#^&#z!oRj>SURCZ--FG6~-vLeLmShz-+7vDU3j!C-27V|l2?3%wGrpC@Z)^c@ zono`4oNs*??jF)QpPwjyc`m&!xTxO%G2-I~8BkCDXt}iIC_sFLwWL?l4t9I2)Vyjm zfukGpP#z(-p?>h<0J#651O1{}P6D9&Nn5^X@`;R+r13~zx!X;gM!~8BaYftQNrz(f zE$cy9ovFXjdryyp3To-NK!)0cL75$u?iv7xc62xS22zqXcK8CP75IF#uIIN|-n(ZE zdivJ!LQW>TTX!MIRb8X7uGEmQ!d&W4PZuU@m7ihq~o5Lv>tf2Gu;i#%x~BMg-a zvkVM|?U+iNE}zp?=@$)R3)vGBpXK(hq4F4Yo1!5$0i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