-
Notifications
You must be signed in to change notification settings - Fork 0
/
adapter.go
40 lines (32 loc) · 1.06 KB
/
adapter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package kvdb2ethdb
import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/skyhighblockchain/push-base/kvdb"
)
type Adapter struct {
kvdb.Store
}
var _ ethdb.KeyValueStore = (*Adapter)(nil)
func Wrap(v kvdb.Store) *Adapter {
return &Adapter{v}
}
// batch is a write-only memory batch that commits changes to its host
// database when Write is called. A batch cannot be used concurrently.
type batch struct {
kvdb.Batch
}
// Replay replays the batch contents.
func (b *batch) Replay(w ethdb.KeyValueWriter) error {
return b.Batch.Replay(w)
}
// NewBatch creates a write-only key-value store that buffers changes to its host
// database until a final write is called.
func (db *Adapter) NewBatch() ethdb.Batch {
return &batch{db.Store.NewBatch()}
}
// NewIterator creates a binary-alphabetical iterator over a subset
// of database content with a particular key prefix, starting at a particular
// initial key (or after, if it does not exist).
func (db *Adapter) NewIterator(prefix []byte, start []byte) ethdb.Iterator {
return db.Store.NewIterator(prefix, start)
}