neo-go/pkg/vm/interop_iterators.go

72 lines
1.1 KiB
Go
Raw Normal View History

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
}
2019-11-13 12:29:27 +00:00
mapWrapper struct {
index int
m []stackitem.MapElement
2019-11-13 12:29:27 +00:00
}
)
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])))
}
2019-11-13 12:29:27 +00:00
func (m *mapWrapper) Next() bool {
if next := m.index + 1; next < len(m.m) {
2019-11-13 12:29:27 +00:00
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,
})
2019-11-13 12:29:27 +00:00
}