neoneo-go/examples/storage/storage.go
Roman Khimov a9b9c9226d *: add/fix godoc comments to satisfy golint
Fixes things like:
 * exported type/method/function X should have comment or be unexported
 * comment on exported type/method/function X should be of the form "X ..."
   (with optional leading article)

Refs. #213.
2019-09-03 17:57:51 +03:00

47 lines
846 B
Go

package storage_contract
import (
"github.com/CityOfZion/neo-go/pkg/interop/storage"
)
// Main is a very useful function.
func Main(operation string, args []interface{}) interface{} {
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
}