From 230921d7ee43c70b001b08a6d43b2cd62a4a8caf Mon Sep 17 00:00:00 2001 From: Stanislav Bogatyrev Date: Wed, 8 Nov 2023 12:57:55 +0300 Subject: [PATCH] Add Storage Counter SC Signed-off-by: Stanislav Bogatyrev --- l3/storage/counter.go | 31 +++++++++++++++++++++++++++++++ l3/storage/counter.yml | 8 ++++++++ l3/storage/go.mod | 5 +++++ l3/storage/go.sum | 2 ++ 4 files changed, 46 insertions(+) create mode 100644 l3/storage/counter.go create mode 100644 l3/storage/counter.yml create mode 100644 l3/storage/go.mod create mode 100644 l3/storage/go.sum diff --git a/l3/storage/counter.go b/l3/storage/counter.go new file mode 100644 index 0000000..93ae918 --- /dev/null +++ b/l3/storage/counter.go @@ -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 +} diff --git a/l3/storage/counter.yml b/l3/storage/counter.yml new file mode 100644 index 0000000..5c98fb3 --- /dev/null +++ b/l3/storage/counter.yml @@ -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 diff --git a/l3/storage/go.mod b/l3/storage/go.mod new file mode 100644 index 0000000..f835d51 --- /dev/null +++ b/l3/storage/go.mod @@ -0,0 +1,5 @@ +module counter + +go 1.20 + +require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231020160724-c3955f87d1b5 diff --git a/l3/storage/go.sum b/l3/storage/go.sum new file mode 100644 index 0000000..05f981f --- /dev/null +++ b/l3/storage/go.sum @@ -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=