2020-05-18 12:30:44 +00:00
|
|
|
/*
|
|
|
|
Package iterator provides functions to work with Neo iterators.
|
|
|
|
*/
|
2018-08-31 08:23:57 +00:00
|
|
|
package iterator
|
|
|
|
|
2021-02-05 16:02:09 +00:00
|
|
|
import "github.com/nspcc-dev/neo-go/pkg/interop/neogointernal"
|
|
|
|
|
2020-05-18 12:30:44 +00:00
|
|
|
// Iterator represents a Neo iterator, it's an opaque data structure that can
|
2022-09-20 14:09:48 +00:00
|
|
|
// be properly created by storage.Find. Iterators range over key-value pairs,
|
|
|
|
// so it's convenient to use them for maps. This structure is similar in
|
2021-09-08 10:35:03 +00:00
|
|
|
// function to Neo .net framework's Iterator.
|
2018-08-31 08:23:57 +00:00
|
|
|
type Iterator struct{}
|
|
|
|
|
2021-09-08 10:35:03 +00:00
|
|
|
// Next advances the iterator returning true if it was successful (and you
|
|
|
|
// can use Value to get value for slices or key-value pair for maps) and false
|
|
|
|
// otherwise (and there are no more elements in this Iterator). This function
|
|
|
|
// uses `System.Iterator.Next` syscall.
|
2020-03-26 13:34:54 +00:00
|
|
|
func Next(it Iterator) bool {
|
2021-02-05 16:02:09 +00:00
|
|
|
return neogointernal.Syscall1("System.Iterator.Next", it).(bool)
|
2020-03-26 13:34:54 +00:00
|
|
|
}
|
|
|
|
|
2020-05-18 12:30:44 +00:00
|
|
|
// Value returns iterator's current value. It's only valid to call after
|
2022-04-20 18:30:09 +00:00
|
|
|
// a successful Next call. This function uses `System.Iterator.Value` syscall.
|
|
|
|
// For slices, the result is just value.
|
2022-09-20 14:09:48 +00:00
|
|
|
// For maps, the result can be cast to a slice of 2 elements: a key and a value.
|
2022-04-20 18:30:09 +00:00
|
|
|
// For storage iterators, refer to `storage.FindFlags` documentation.
|
2020-03-26 13:34:54 +00:00
|
|
|
func Value(it Iterator) interface{} {
|
2021-02-05 16:02:09 +00:00
|
|
|
return neogointernal.Syscall1("System.Iterator.Value", it)
|
2020-03-26 13:34:54 +00:00
|
|
|
}
|