github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/cli/smartcontract/testdata/deploy/main.go (about) 1 package deploy 2 3 import ( 4 "github.com/nspcc-dev/neo-go/cli/smartcontract/testdata/deploy/sub" 5 "github.com/nspcc-dev/neo-go/pkg/interop" 6 "github.com/nspcc-dev/neo-go/pkg/interop/contract" 7 "github.com/nspcc-dev/neo-go/pkg/interop/iterator" 8 "github.com/nspcc-dev/neo-go/pkg/interop/runtime" 9 "github.com/nspcc-dev/neo-go/pkg/interop/storage" 10 ) 11 12 var key = "key" 13 14 const mgmtKey = "mgmt" 15 16 func _deploy(data any, isUpdate bool) { 17 var value string 18 19 ctx := storage.GetContext() 20 if isUpdate { 21 value = "on update" 22 } else { 23 value = "on create" 24 sh := runtime.GetCallingScriptHash() 25 storage.Put(ctx, mgmtKey, sh) 26 27 if data != nil { 28 arr := data.([]any) 29 for i := 0; i < len(arr)-1; i += 2 { 30 storage.Put(ctx, arr[i], arr[i+1]) 31 } 32 } 33 } 34 35 storage.Put(ctx, key, value) 36 } 37 38 // Fail just fails. 39 func Fail() { 40 panic("as expected") 41 } 42 43 // CheckSenderWitness checks sender's witness. 44 func CheckSenderWitness() { 45 tx := runtime.GetScriptContainer() 46 if !runtime.CheckWitness(tx.Sender) { 47 panic("not witnessed") 48 } 49 } 50 51 // Update updates the contract with a new one. 52 func Update(script, manifest []byte) { 53 ctx := storage.GetReadOnlyContext() 54 mgmt := storage.Get(ctx, mgmtKey).(interop.Hash160) 55 contract.Call(mgmt, "update", contract.All, script, manifest) 56 } 57 58 // GetValue returns the stored value. 59 func GetValue() string { 60 ctx := storage.GetReadOnlyContext() 61 val1 := storage.Get(ctx, key) 62 val2 := storage.Get(ctx, sub.Key) 63 return val1.(string) + "|" + val2.(string) 64 } 65 66 // GetValueWithKey returns the stored value with the specified key. 67 func GetValueWithKey(key string) string { 68 ctx := storage.GetReadOnlyContext() 69 return storage.Get(ctx, key).(string) 70 } 71 72 // TestFind finds items with the specified prefix. 73 func TestFind(f storage.FindFlags) []any { 74 ctx := storage.GetContext() 75 storage.Put(ctx, "findkey1", "value1") 76 storage.Put(ctx, "findkey2", "value2") 77 78 var result []any 79 iter := storage.Find(ctx, "findkey", f) 80 for iterator.Next(iter) { 81 result = append(result, iterator.Value(iter)) 82 } 83 return result 84 }