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.
This commit is contained in:
parent
47eadcdf2a
commit
84bf87df52
3 changed files with 20 additions and 1 deletions
|
@ -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},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue