2020-05-27 06:27:43 +00:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm"
|
|
|
|
)
|
|
|
|
|
|
|
|
type storageWrapper struct {
|
|
|
|
next dao.StorageIteratorFunc
|
|
|
|
key, value vm.StackItem
|
|
|
|
finished bool
|
|
|
|
}
|
|
|
|
|
2020-05-27 08:09:23 +00:00
|
|
|
var _ vm.Iterator = (*storageWrapper)(nil)
|
|
|
|
|
2020-05-27 06:27:43 +00:00
|
|
|
// newStorageIterator returns new storage iterator from the `next()` callback.
|
|
|
|
func newStorageIterator(next dao.StorageIteratorFunc) *storageWrapper {
|
|
|
|
return &storageWrapper{
|
|
|
|
next: next,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-27 08:09:23 +00:00
|
|
|
// Next implements vm.Iterator interface.
|
2020-05-27 06:27:43 +00:00
|
|
|
func (s *storageWrapper) Next() bool {
|
|
|
|
if s.finished {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
key, value, err := s.next()
|
|
|
|
if err != nil {
|
|
|
|
s.finished = true
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
s.key = vm.NewByteArrayItem(key)
|
|
|
|
s.value = vm.NewByteArrayItem(value)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-05-27 08:09:23 +00:00
|
|
|
// Value implements vm.Iterator interface.
|
2020-05-27 06:27:43 +00:00
|
|
|
func (s *storageWrapper) Value() vm.StackItem {
|
|
|
|
return s.value
|
|
|
|
}
|
|
|
|
|
2020-05-27 08:09:23 +00:00
|
|
|
// Key implements vm.Iterator interface.
|
2020-05-27 06:27:43 +00:00
|
|
|
func (s *storageWrapper) Key() vm.StackItem {
|
|
|
|
return s.key
|
|
|
|
}
|