Add Storage Counter SC
Signed-off-by: Stanislav Bogatyrev <s.bogatyrev@yadro.com>
This commit is contained in:
parent
c47b667d9b
commit
230921d7ee
4 changed files with 46 additions and 0 deletions
31
l3/storage/counter.go
Normal file
31
l3/storage/counter.go
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
package counter
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
||||||
|
)
|
||||||
|
|
||||||
|
const itemKey = "Counter"
|
||||||
|
|
||||||
|
func _deploy(_ interface{}, isUpdate bool) {
|
||||||
|
if !isUpdate {
|
||||||
|
ctx := storage.GetContext()
|
||||||
|
runtime.Notify("info", []byte("Counter not set in Storage. Setting to 0"))
|
||||||
|
itemValue := 0
|
||||||
|
storage.Put(ctx, itemKey, itemValue)
|
||||||
|
runtime.Notify("info", []byte("Counter in Storage is now initialised"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Main() interface{} {
|
||||||
|
ctx := storage.GetContext()
|
||||||
|
itemValue := storage.Get(ctx, itemKey)
|
||||||
|
runtime.Notify("info", []byte("Value read from Storage"))
|
||||||
|
|
||||||
|
runtime.Notify("info", []byte("Incrementing Counter by 1"))
|
||||||
|
itemValue = itemValue.(int) + 1
|
||||||
|
|
||||||
|
storage.Put(ctx, itemKey, itemValue)
|
||||||
|
runtime.Notify("info", []byte("New counter value written into Storage"))
|
||||||
|
return itemValue
|
||||||
|
}
|
8
l3/storage/counter.yml
Normal file
8
l3/storage/counter.yml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
name: "Storage Counter contract"
|
||||||
|
sourceurl: https://git.frostfs.info/Web3N3/web3-course
|
||||||
|
supportedstandards: []
|
||||||
|
events:
|
||||||
|
- name: info
|
||||||
|
parameters:
|
||||||
|
- name: message
|
||||||
|
type: ByteString
|
5
l3/storage/go.mod
Normal file
5
l3/storage/go.mod
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
module counter
|
||||||
|
|
||||||
|
go 1.20
|
||||||
|
|
||||||
|
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231020160724-c3955f87d1b5
|
2
l3/storage/go.sum
Normal file
2
l3/storage/go.sum
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231020160724-c3955f87d1b5 h1:09CpI5uwsxb1EeFPIKQRwwWlfCmDD/Dwwh01lPiQScM=
|
||||||
|
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231020160724-c3955f87d1b5/go.mod h1:J/Mk6+nKeKSW4wygkZQFLQ6SkLOSGX5Ga0RuuuktEag=
|
Loading…
Reference in a new issue