From 84bf87df52ded0f20d071c0d1544d0c806e311b0 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 22 Jul 2020 11:22:58 +0300 Subject: [PATCH] core: adjust System.Storage.PutEx interop Part of #1055. Added System.Storage.PutEx to compiler. Added StorageFlag in order to denote whether item is constant or not. --- pkg/compiler/syscall.go | 1 + pkg/core/interop_system.go | 13 ++++++++++++- pkg/interop/storage/storage.go | 7 +++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/compiler/syscall.go b/pkg/compiler/syscall.go index 276acb26b..910847a94 100644 --- a/pkg/compiler/syscall.go +++ b/pkg/compiler/syscall.go @@ -77,5 +77,6 @@ var syscalls = map[string]map[string]Syscall{ "GetContext": {"System.Storage.GetContext", false}, "GetReadOnlyContext": {"System.Storage.GetReadOnlyContext", false}, "Put": {"System.Storage.Put", false}, + "PutEx": {"System.Storage.PutEx", false}, }, } diff --git a/pkg/core/interop_system.go b/pkg/core/interop_system.go index 2b17b2d6f..68b47a97b 100644 --- a/pkg/core/interop_system.go +++ b/pkg/core/interop_system.go @@ -41,6 +41,17 @@ type StorageContext struct { ReadOnly bool } +// StorageFlag represents storage flag which denotes whether the stored value is +// a constant. +type StorageFlag byte + +const ( + // None is a storage flag for non-constant items. + None StorageFlag = 0 + // Constant is a storage flag for constant items. + Constant StorageFlag = 0x01 +) + // getBlockHashFromElement converts given vm.Element to block hash using given // Blockchainer if needed. Interop functions accept both block numbers and // block hashes as parameters, thus this function is needed. @@ -404,7 +415,7 @@ func storagePutInternal(ic *interop.Context, v *vm.VM, getFlag bool) error { if getFlag { flag = int(v.Estack().Pop().BigInt().Int64()) } - return putWithContextAndFlags(ic, v, stc, key, value, flag == 1) + return putWithContextAndFlags(ic, v, stc, key, value, int(Constant)&flag != 0) } // storagePut puts key-value pair into the storage. diff --git a/pkg/interop/storage/storage.go b/pkg/interop/storage/storage.go index eb6e1faa6..8ee4ca0e2 100644 --- a/pkg/interop/storage/storage.go +++ b/pkg/interop/storage/storage.go @@ -37,6 +37,13 @@ func GetReadOnlyContext() Context { return Context{} } // runtime.Serialize. This function uses `System.Storage.Put` syscall. func Put(ctx Context, key interface{}, value interface{}) {} +// PutEx is an advanced version of Put which saves given value with given key +// and given ReadOnly flag in the storage using given Context. `flag` argument +// can either be odd for constant storage items or even for variable storage items. +// Refer to Put function description for details on how to pass the remaining +// arguments. This function uses `System.Storage.PutEx` syscall. +func PutEx(ctx Context, key interface{}, value interface{}, flag int64) {} + // Get retrieves value stored for the given key using given Context. See Put // documentation on possible key and value types. If the value is not present in // the database it returns nil. This function uses `System.Storage.Get` syscall.