neo-go/internal/basicchain/testdata/storage/storage_contract.go
Roman Khimov 1b83dc2476 *: improve for loop syntax
Mostly it's about Go 1.22+ syntax with ranging over integers, but it also
prefers ranging over slices where possible (it makes code a little better to
read).

Notice that we have a number of dangerous loops where slices are mutated
during loop execution, many of these can't be converted since we need proper
length evalutation at every iteration.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-30 21:45:18 +03:00

34 lines
934 B
Go

/*
Package storage contains contract that puts a set of values inside the storage on
deploy. The contract has a single method returning iterator over these values.
The contract is aimed to test iterator sessions RPC API.
*/
package storage
import (
"github.com/nspcc-dev/neo-go/pkg/interop/iterator"
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
)
// valuesCount is the amount of stored values.
const valuesCount = 255
// valuesPrefix is the prefix values are stored by.
var valuesPrefix = []byte{0x01}
func _deploy(data any, isUpdate bool) {
if !isUpdate {
ctx := storage.GetContext()
for i := range valuesCount {
key := append(valuesPrefix, byte(i))
storage.Put(ctx, key, i)
}
}
}
// IterateOverValues returns iterator over contract storage values stored during deploy.
func IterateOverValues() iterator.Iterator {
ctx := storage.GetContext()
return storage.Find(ctx, valuesPrefix, storage.ValuesOnly)
}