2020-10-02 11:16:25 +00:00
|
|
|
package deploy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neo-go/cli/testdata/deploy/sub"
|
2020-12-13 15:26:35 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop"
|
2020-10-02 11:16:25 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
2021-01-12 12:52:08 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/iterator"
|
2020-12-13 15:26:35 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
2020-10-02 11:16:25 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
|
|
|
)
|
|
|
|
|
|
|
|
var key = "key"
|
|
|
|
|
2020-12-13 15:26:35 +00:00
|
|
|
const mgmtKey = "mgmt"
|
|
|
|
|
2021-01-28 13:31:50 +00:00
|
|
|
func _deploy(data interface{}, isUpdate bool) {
|
2020-12-13 15:26:35 +00:00
|
|
|
var value string
|
|
|
|
|
2020-10-02 11:16:25 +00:00
|
|
|
ctx := storage.GetContext()
|
|
|
|
if isUpdate {
|
|
|
|
value = "on update"
|
2020-12-13 15:26:35 +00:00
|
|
|
} else {
|
|
|
|
value = "on create"
|
|
|
|
sh := runtime.GetCallingScriptHash()
|
|
|
|
storage.Put(ctx, mgmtKey, sh)
|
2021-04-16 15:04:19 +00:00
|
|
|
|
|
|
|
if data != nil {
|
|
|
|
arr := data.([]interface{})
|
|
|
|
for i := 0; i < len(arr)-1; i += 2 {
|
|
|
|
storage.Put(ctx, arr[i], arr[i+1])
|
|
|
|
}
|
|
|
|
}
|
2020-10-02 11:16:25 +00:00
|
|
|
}
|
2020-12-13 15:26:35 +00:00
|
|
|
|
2020-10-02 11:16:25 +00:00
|
|
|
storage.Put(ctx, key, value)
|
|
|
|
}
|
|
|
|
|
2020-12-03 11:57:45 +00:00
|
|
|
// Fail just fails.
|
|
|
|
func Fail() {
|
|
|
|
panic("as expected")
|
|
|
|
}
|
|
|
|
|
2020-10-02 11:16:25 +00:00
|
|
|
// Update updates contract with the new one.
|
|
|
|
func Update(script, manifest []byte) {
|
2020-12-13 15:26:35 +00:00
|
|
|
ctx := storage.GetReadOnlyContext()
|
|
|
|
mgmt := storage.Get(ctx, mgmtKey).(interop.Hash160)
|
2020-12-29 10:44:07 +00:00
|
|
|
contract.Call(mgmt, "update", contract.All, script, manifest)
|
2020-10-02 11:16:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetValue returns stored value.
|
|
|
|
func GetValue() string {
|
|
|
|
ctx := storage.GetReadOnlyContext()
|
|
|
|
val1 := storage.Get(ctx, key)
|
|
|
|
val2 := storage.Get(ctx, sub.Key)
|
|
|
|
return val1.(string) + "|" + val2.(string)
|
|
|
|
}
|
2021-01-12 12:52:08 +00:00
|
|
|
|
2021-04-16 15:04:19 +00:00
|
|
|
// GetValueWithKey returns stored value with the specified key.
|
|
|
|
func GetValueWithKey(key string) string {
|
|
|
|
ctx := storage.GetReadOnlyContext()
|
|
|
|
return storage.Get(ctx, key).(string)
|
|
|
|
}
|
|
|
|
|
2021-01-12 12:52:08 +00:00
|
|
|
// TestFind finds items with the specified prefix.
|
|
|
|
func TestFind(f storage.FindFlags) []interface{} {
|
|
|
|
ctx := storage.GetContext()
|
|
|
|
storage.Put(ctx, "findkey1", "value1")
|
|
|
|
storage.Put(ctx, "findkey2", "value2")
|
|
|
|
|
|
|
|
var result []interface{}
|
|
|
|
iter := storage.Find(ctx, "findkey", f)
|
|
|
|
for iterator.Next(iter) {
|
|
|
|
result = append(result, iterator.Value(iter))
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|