cosmos-sdk/internal/db/iterator_adapter.go
Likhita Polavarapu 7559d9ecd3
refactor: create go.mod for store (#14746)
Co-authored-by: Marko <marbar3778@yahoo.com>
2023-01-25 13:31:56 +00:00

26 lines
695 B
Go

package db
import (
storetypes "cosmossdk.io/store/types"
dbm "github.com/cosmos/cosmos-sdk/db"
)
var _ = (*storetypes.Iterator)(nil)
type AsStoreIter struct {
dbm.Iterator
valid bool
}
// DBToStoreIterator returns an iterator wrapping the given iterator so that it satisfies the
// (store/types).Iterator interface.
func ToStoreIterator(source dbm.Iterator) *AsStoreIter {
ret := &AsStoreIter{Iterator: source}
ret.Next() // The DB iterator must be primed before it can access the first element, because Next also returns the validity status
return ret
}
func (it *AsStoreIter) Next() { it.valid = it.Iterator.Next() }
func (it *AsStoreIter) Valid() bool { return it.valid }