2019-11-13 11:34:03 +00:00
|
|
|
package vm
|
|
|
|
|
2020-06-03 12:55:06 +00:00
|
|
|
import (
|
2020-07-20 13:30:19 +00:00
|
|
|
"math/big"
|
|
|
|
|
2020-06-03 12:55:06 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
|
|
|
)
|
|
|
|
|
2019-11-13 11:34:03 +00:00
|
|
|
type (
|
2021-01-12 09:30:21 +00:00
|
|
|
iterator interface {
|
2019-11-13 11:34:03 +00:00
|
|
|
Next() bool
|
2020-06-03 12:55:06 +00:00
|
|
|
Value() stackitem.Item
|
2019-11-13 11:34:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
arrayWrapper struct {
|
|
|
|
index int
|
2020-06-03 12:55:06 +00:00
|
|
|
value []stackitem.Item
|
2019-11-13 11:34:03 +00:00
|
|
|
}
|
|
|
|
|
2020-07-20 13:30:19 +00:00
|
|
|
byteArrayWrapper struct {
|
|
|
|
index int
|
|
|
|
value []byte
|
|
|
|
}
|
|
|
|
|
2019-11-13 12:29:27 +00:00
|
|
|
mapWrapper struct {
|
|
|
|
index int
|
2020-06-03 12:55:06 +00:00
|
|
|
m []stackitem.MapElement
|
2019-11-13 12:29:27 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2019-11-13 11:34:03 +00:00
|
|
|
func (a *arrayWrapper) Next() bool {
|
|
|
|
if next := a.index + 1; next < len(a.value) {
|
|
|
|
a.index = next
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-06-03 12:55:06 +00:00
|
|
|
func (a *arrayWrapper) Value() stackitem.Item {
|
2019-11-13 11:34:03 +00:00
|
|
|
return a.value[a.index]
|
|
|
|
}
|
|
|
|
|
2020-07-20 13:30:19 +00:00
|
|
|
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 {
|
2020-03-31 10:30:38 +00:00
|
|
|
if next := m.index + 1; next < len(m.m) {
|
2019-11-13 12:29:27 +00:00
|
|
|
m.index = next
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-06-03 12:55:06 +00:00
|
|
|
func (m *mapWrapper) Value() stackitem.Item {
|
2021-01-12 09:30:21 +00:00
|
|
|
return stackitem.NewStruct([]stackitem.Item{
|
|
|
|
m.m[m.index].Key,
|
|
|
|
m.m[m.index].Value,
|
|
|
|
})
|
2019-11-13 12:29:27 +00:00
|
|
|
}
|