[#1] Create an example contract

Contract has PutNumber and GetNumber methods

Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
This commit is contained in:
Ekaterina Lebedeva 2023-07-31 13:25:43 +03:00
parent b6325fe254
commit 93d1cbf208
2 changed files with 38 additions and 0 deletions

3
impulse/config.yml Normal file
View file

@ -0,0 +1,3 @@
name: "Example"
safemethods: []
supportedstandards: []

35
impulse/contract.go Normal file
View file

@ -0,0 +1,35 @@
package contract
import (
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
)
// Prefixes used for contract data storage.
const (
// prefixNumber contains map from the key to stored number.
prefixNumber byte = 0x00
)
const (
keySize = 5
)
func GetNumber(key []byte) int {
if len(key) != keySize {
panic("Invalid key size")
}
ctx := storage.GetContext()
num := storage.Get(ctx, append([]byte{prefixNumber}, key...))
if num == nil {
panic("Cannot get number")
}
return num.(int)
}
func PutNumber(key []byte, num int) {
if len(key) != keySize {
panic("Invalid key size")
}
ctx := storage.GetContext()
storage.Put(ctx, append([]byte{prefixNumber}, key...), num)
}