mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-23 23:30:36 +00:00
2130e17f0c
Map iterator now returns key-value pair, while array/byte-array iterators work like old enumerators. Follow neo-project/neo#2190.
71 lines
1.1 KiB
Go
71 lines
1.1 KiB
Go
package vm
|
|
|
|
import (
|
|
"math/big"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
|
)
|
|
|
|
type (
|
|
iterator interface {
|
|
Next() bool
|
|
Value() stackitem.Item
|
|
}
|
|
|
|
arrayWrapper struct {
|
|
index int
|
|
value []stackitem.Item
|
|
}
|
|
|
|
byteArrayWrapper struct {
|
|
index int
|
|
value []byte
|
|
}
|
|
|
|
mapWrapper struct {
|
|
index int
|
|
m []stackitem.MapElement
|
|
}
|
|
)
|
|
|
|
func (a *arrayWrapper) Next() bool {
|
|
if next := a.index + 1; next < len(a.value) {
|
|
a.index = next
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func (a *arrayWrapper) Value() stackitem.Item {
|
|
return a.value[a.index]
|
|
}
|
|
|
|
func (a *byteArrayWrapper) Next() bool {
|
|
if next := a.index + 1; next < len(a.value) {
|
|
a.index = next
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func (a *byteArrayWrapper) Value() stackitem.Item {
|
|
return stackitem.NewBigInteger(big.NewInt(int64(a.value[a.index])))
|
|
}
|
|
|
|
func (m *mapWrapper) Next() bool {
|
|
if next := m.index + 1; next < len(m.m) {
|
|
m.index = next
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func (m *mapWrapper) Value() stackitem.Item {
|
|
return stackitem.NewStruct([]stackitem.Item{
|
|
m.m[m.index].Key,
|
|
m.m[m.index].Value,
|
|
})
|
|
}
|