mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 03:41:34 +00:00
29f05c0edb
Imported from CityOfZion/neo-storm (7eb644415d4083572c4e74590da056319c3a54fb).
46 lines
813 B
Go
46 lines
813 B
Go
package storage_contract
|
|
|
|
import (
|
|
"github.com/CityOfZion/neo-go-sc/interop/storage"
|
|
)
|
|
|
|
func Main(operation string, args []interface{}) interface{} {
|
|
var ctx = storage.GetContext()
|
|
|
|
// Puts value at key
|
|
if operation == "put" {
|
|
if checkArgs(args, 2) {
|
|
key := args[0].([]byte)
|
|
value := args[1].([]byte)
|
|
storage.Put(ctx, key, value)
|
|
return key
|
|
}
|
|
}
|
|
|
|
// Returns the value at passed key
|
|
if operation == "get" {
|
|
if checkArgs(args, 1) {
|
|
key := args[0].([]byte)
|
|
return storage.Get(ctx, key)
|
|
}
|
|
}
|
|
|
|
// Deletes the value at passed key
|
|
if operation == "delete" {
|
|
key := args[0].([]byte)
|
|
storage.Delete(ctx, key)
|
|
return true
|
|
}
|
|
|
|
// TODO: storage.Find()
|
|
|
|
return false
|
|
}
|
|
|
|
func checkArgs(args []interface{}, length int) bool {
|
|
if len(args) == length {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|