examples: polish iterator

Use read only context where appropriate, shorten notifications, fix comment.
This commit is contained in:
Roman Khimov 2022-03-23 22:05:40 +03:00
parent 1d1b4d4c18
commit 3070c2e7fc
2 changed files with 6 additions and 6 deletions

View file

@ -8,24 +8,24 @@ import (
// _deploy primes contract's storage with some data to be used later.
func _deploy(_ interface{}, _ bool) {
ctx := storage.GetContext()
ctx := storage.GetContext() // RW context.
storage.Put(ctx, "foo1", "1")
storage.Put(ctx, "foo2", "2")
storage.Put(ctx, "foo3", "3")
}
// NotifyKeysAndValues sends notification with `foo` storage keys and values
// NotifyKeysAndValues sends notification with `foo` storage keys and values.
func NotifyKeysAndValues() bool {
iter := storage.Find(storage.GetContext(), []byte("foo"), storage.None)
iter := storage.Find(storage.GetReadOnlyContext(), []byte("foo"), storage.None)
for iterator.Next(iter) {
runtime.Notify("found storage key-value pair", iterator.Value(iter))
runtime.Notify("Key-Value", iterator.Value(iter))
}
return true
}
// NotifyValues sends notification with `foo` storage values.
func NotifyValues() bool {
iter := storage.Find(storage.GetContext(), []byte("foo"), storage.ValuesOnly)
iter := storage.Find(storage.GetReadOnlyContext(), []byte("foo"), storage.ValuesOnly)
for iterator.Next(iter) {
runtime.Notify("Value", iterator.Value(iter))
}

View file

@ -2,7 +2,7 @@ name: "Iterator example"
sourceurl: https://github.com/nspcc-dev/neo-go/
supportedstandards: []
events:
- name: found storage key-value pair
- name: Key-Value
parameters:
- name: value
type: Any