forked from ten-protocol/go-ten
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleveldb.go
70 lines (56 loc) · 1.67 KB
/
leveldb.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package db
import (
"errors"
"github.com/ethereum/go-ethereum/ethdb"
ethldb "github.com/ethereum/go-ethereum/ethdb/leveldb"
"github.com/obscuronet/go-obscuro/go/common/errutil"
"github.com/syndtr/goleveldb/leveldb"
)
// ObscuroLevelDB is a very thin wrapper around a level DB database for compatibility with our internal interfaces
// In particular, it overrides the Get method to return the obscuro ErrNotFound
type ObscuroLevelDB struct {
db *ethldb.Database
}
func (o *ObscuroLevelDB) NewBatchWithSize(int) ethdb.Batch {
// TODO implement me
panic("implement me")
}
func (o *ObscuroLevelDB) NewSnapshot() (ethdb.Snapshot, error) {
// TODO implement me
panic("implement me")
}
func (o *ObscuroLevelDB) Has(key []byte) (bool, error) {
return o.db.Has(key)
}
// Get is overridden here to return our internal NotFound error
func (o *ObscuroLevelDB) Get(key []byte) ([]byte, error) {
d, err := o.db.Get(key)
if err != nil {
if errors.Is(err, leveldb.ErrNotFound) {
return nil, errutil.ErrNotFound
}
return nil, err
}
return d, nil
}
func (o *ObscuroLevelDB) Put(key []byte, value []byte) error {
return o.db.Put(key, value)
}
func (o *ObscuroLevelDB) Delete(key []byte) error {
return o.db.Delete(key)
}
func (o *ObscuroLevelDB) NewBatch() ethdb.Batch {
return o.db.NewBatch()
}
func (o *ObscuroLevelDB) NewIterator(prefix []byte, start []byte) ethdb.Iterator {
return o.db.NewIterator(prefix, start)
}
func (o *ObscuroLevelDB) Stat(property string) (string, error) {
return o.db.Stat(property)
}
func (o *ObscuroLevelDB) Compact(start []byte, limit []byte) error {
return o.db.Compact(start, limit)
}
func (o *ObscuroLevelDB) Close() error {
return o.db.Close()
}