simple-contract/FirstContract/contract/contract.go
Lebedeva Ekaterina 0c99f24850 [#XX] Added Put-Get contracts with test
Tried to implement PutNumber and GetNumber funcs based on contracts in frostfsid_contract.go
Added just one test for now, it's not failing

Signed-off-by: Lebedeva Ekaterina <ekaterina.lebedeva@yadro.com>
2023-07-17 12:31:09 +03:00

34 lines
840 B
Go

package contract
import (
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
)
var notificationName string
// init initializes notificationName before calling any other smart-contract method
func init() {
notificationName = "Hello world!"
}
// RuntimeNotify sends runtime notification with "Hello world!" name
func RuntimeNotify(args []interface{}) {
runtime.Notify(notificationName, args)
}
// the answer to the “Great Question” of “Life, the Universe and Everything”
func GetNumber() int {
ctx := storage.GetContext()
// it := storage.Find(ctx, 123, storage.None)
// for iterator.Next(it) {
// num = iterator.Value(it).(int)
// }
num := storage.Get(ctx, 123).(int)
return num
}
func PutNumber(num int) {
ctx := storage.GetContext()
storage.Put(ctx, 123, num)
}