cosmos-sdk/store/kv/trace/iterator.go
Aleksandr Bezobchuk 20b1da7a2e
refactor(store/v2): Use Core Iterator (#18957)
Co-authored-by: marbar3778 <marbar3778@yahoo.com>
Co-authored-by: cool-developer <51834436+cool-develope@users.noreply.github.com>
2024-01-08 19:26:10 +00:00

59 lines
1.0 KiB
Go

package trace
import (
"io"
corestore "cosmossdk.io/core/store"
"cosmossdk.io/store/v2"
)
var _ corestore.Iterator = (*iterator)(nil)
type iterator struct {
parent corestore.Iterator
writer io.Writer
context store.TraceContext
}
func newIterator(w io.Writer, parent corestore.Iterator, tc store.TraceContext) corestore.Iterator {
return &iterator{
parent: parent,
writer: w,
context: tc,
}
}
func (itr *iterator) Domain() ([]byte, []byte) {
return itr.parent.Domain()
}
func (itr *iterator) Valid() bool {
return itr.parent.Valid()
}
func (itr *iterator) Next() {
itr.parent.Next()
}
func (itr *iterator) Error() error {
return itr.parent.Error()
}
func (itr *iterator) Close() error {
return itr.parent.Close()
}
func (itr *iterator) Key() []byte {
key := itr.parent.Key()
writeOperation(itr.writer, IterKeyOp, itr.context, key, nil)
return key
}
func (itr *iterator) Value() []byte {
value := itr.parent.Value()
writeOperation(itr.writer, IterValueOp, itr.context, nil, value)
return value
}