mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-12 01:10:36 +00:00
compiler/storage: add read-only related interops
This commit is contained in:
parent
07742bdf46
commit
d0a3ce25ff
2 changed files with 21 additions and 6 deletions
|
@ -18,11 +18,13 @@ var syscalls = map[string]map[string]string{
|
|||
"Value": "Neo.Enumerator.Value",
|
||||
},
|
||||
"storage": {
|
||||
"GetContext": "Neo.Storage.GetContext",
|
||||
"Put": "Neo.Storage.Put",
|
||||
"Get": "Neo.Storage.Get",
|
||||
"Delete": "Neo.Storage.Delete",
|
||||
"Find": "Neo.Storage.Find",
|
||||
"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",
|
||||
},
|
||||
"runtime": {
|
||||
"GetTrigger": "Neo.Runtime.GetTrigger",
|
||||
|
|
|
@ -10,13 +10,26 @@ import "github.com/nspcc-dev/neo-go/pkg/interop/iterator"
|
|||
|
||||
// Context represents storage context that is mandatory for Put/Get/Delete
|
||||
// operations. It's an opaque type that can only be created properly by
|
||||
// GetContext. It's similar to Neo .net framework's StorageContext class.
|
||||
// GetContext, GetReadOnlyContext or ConvertContextToReadOnly. It's similar
|
||||
// to Neo .net framework's StorageContext class.
|
||||
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.
|
||||
func ConvertContextToReadOnly(ctx Context) Context { return Context{} }
|
||||
|
||||
// GetContext returns current contract's (that invokes this function) storage
|
||||
// context. It uses `Neo.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.
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue