mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-13 05:45:02 +00:00
776bd85ded
Reproduce behavior of the reference realization: - if item was Put in cache after it was encountered during Storage.Find, it must appear twice - checking if item is in cache must be performed in real-time during `Iterator.Next()`
44 lines
906 B
Go
44 lines
906 B
Go
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
|
|
}
|
|
|
|
// newStorageIterator returns new storage iterator from the `next()` callback.
|
|
func newStorageIterator(next dao.StorageIteratorFunc) *storageWrapper {
|
|
return &storageWrapper{
|
|
next: next,
|
|
}
|
|
}
|
|
|
|
// Next implements iterator interface.
|
|
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
|
|
}
|
|
|
|
// Value implements iterator interface.
|
|
func (s *storageWrapper) Value() vm.StackItem {
|
|
return s.value
|
|
}
|
|
|
|
// Key implements iterator interface.
|
|
func (s *storageWrapper) Key() vm.StackItem {
|
|
return s.key
|
|
}
|