You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
945 B
42 lines
945 B
3 years ago
|
package common
|
||
|
|
||
|
import (
|
||
|
"io"
|
||
|
|
||
|
"github.com/ethereum/go-ethereum/ethdb"
|
||
|
"github.com/syndtr/goleveldb/leveldb/util"
|
||
|
)
|
||
|
|
||
|
type TiKVStore interface {
|
||
|
ethdb.KeyValueReader
|
||
|
ethdb.KeyValueWriter
|
||
|
ethdb.Batcher
|
||
|
ethdb.Stater
|
||
|
ethdb.Compacter
|
||
|
io.Closer
|
||
|
|
||
|
NewIterator(start, end []byte) ethdb.Iterator
|
||
|
}
|
||
|
|
||
|
// TiKVStoreWrapper simple wrapper to covert to ethdb.KeyValueStore
|
||
|
type TiKVStoreWrapper struct {
|
||
|
TiKVStore
|
||
|
}
|
||
|
|
||
|
func (t *TiKVStoreWrapper) NewIterator() ethdb.Iterator {
|
||
|
return t.TiKVStore.NewIterator(nil, nil)
|
||
|
}
|
||
|
|
||
|
func (t *TiKVStoreWrapper) NewIteratorWithStart(start []byte) ethdb.Iterator {
|
||
|
return t.TiKVStore.NewIterator(start, nil)
|
||
|
}
|
||
|
|
||
|
func (t *TiKVStoreWrapper) NewIteratorWithPrefix(prefix []byte) ethdb.Iterator {
|
||
|
bytesPrefix := util.BytesPrefix(prefix)
|
||
|
return t.TiKVStore.NewIterator(bytesPrefix.Start, bytesPrefix.Limit)
|
||
|
}
|
||
|
|
||
|
func ToEthKeyValueStore(store TiKVStore) ethdb.KeyValueStore {
|
||
|
return &TiKVStoreWrapper{TiKVStore: store}
|
||
|
}
|