The core protocol of WoopChain
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.
woop/internal/tikv/common/tikv_store.go

47 lines
1.1 KiB

3 years ago
package common
import (
"errors"
3 years ago
"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(prefix []byte, start []byte) ethdb.Iterator {
3 years ago
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 (t *TiKVStoreWrapper) NewSnapshot() (ethdb.Snapshot, error) {
return nil, errors.New("not supported")
}
3 years ago
func ToEthKeyValueStore(store TiKVStore) ethdb.KeyValueStore {
return &TiKVStoreWrapper{TiKVStore: store}
}