Skip to content

Commit 3070c2e

Browse files
committed
examples: polish iterator
Use read only context where appropriate, shorten notifications, fix comment.
1 parent 1d1b4d4 commit 3070c2e

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

examples/iterator/iterator.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ import (
88

99
// _deploy primes contract's storage with some data to be used later.
1010
func _deploy(_ interface{}, _ bool) {
11-
ctx := storage.GetContext()
11+
ctx := storage.GetContext() // RW context.
1212
storage.Put(ctx, "foo1", "1")
1313
storage.Put(ctx, "foo2", "2")
1414
storage.Put(ctx, "foo3", "3")
1515
}
1616

17-
// NotifyKeysAndValues sends notification with `foo` storage keys and values
17+
// NotifyKeysAndValues sends notification with `foo` storage keys and values.
1818
func NotifyKeysAndValues() bool {
19-
iter := storage.Find(storage.GetContext(), []byte("foo"), storage.None)
19+
iter := storage.Find(storage.GetReadOnlyContext(), []byte("foo"), storage.None)
2020
for iterator.Next(iter) {
21-
runtime.Notify("found storage key-value pair", iterator.Value(iter))
21+
runtime.Notify("Key-Value", iterator.Value(iter))
2222
}
2323
return true
2424
}
2525

2626
// NotifyValues sends notification with `foo` storage values.
2727
func NotifyValues() bool {
28-
iter := storage.Find(storage.GetContext(), []byte("foo"), storage.ValuesOnly)
28+
iter := storage.Find(storage.GetReadOnlyContext(), []byte("foo"), storage.ValuesOnly)
2929
for iterator.Next(iter) {
3030
runtime.Notify("Value", iterator.Value(iter))
3131
}

examples/iterator/iterator.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: "Iterator example"
22
sourceurl: https://github.com/nspcc-dev/neo-go/
33
supportedstandards: []
44
events:
5-
- name: found storage key-value pair
5+
- name: Key-Value
66
parameters:
77
- name: value
88
type: Any

0 commit comments

Comments
 (0)