From 3070c2e7fceec95fbc6b00d8b99c58ac3ad6d4ce Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 23 Mar 2022 22:05:40 +0300 Subject: [PATCH] examples: polish iterator Use read only context where appropriate, shorten notifications, fix comment. --- examples/iterator/iterator.go | 10 +++++----- examples/iterator/iterator.yml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/iterator/iterator.go b/examples/iterator/iterator.go index a30233fb5..fe53881b8 100644 --- a/examples/iterator/iterator.go +++ b/examples/iterator/iterator.go @@ -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)) } diff --git a/examples/iterator/iterator.yml b/examples/iterator/iterator.yml index ddd62c869..61170428c 100644 --- a/examples/iterator/iterator.yml +++ b/examples/iterator/iterator.yml @@ -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