mirror of
https://github.com/arnaucube/go-merkletree-iden3.git
synced 2026-02-07 11:36:47 +01:00
Rm db.Info, rm go-iden3-core dependency
Rm db.Info, rm go-iden3-core dependency, update version of go-iden3-crypto
This commit is contained in:
1
db/db.go
1
db/db.go
@@ -19,7 +19,6 @@ type Storage interface {
|
||||
Get([]byte) ([]byte, error)
|
||||
List(int) ([]KV, error)
|
||||
Close()
|
||||
Info() string
|
||||
Iterate(func([]byte, []byte) (bool, error)) error
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package leveldb
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/iden3/go-merkletree/db"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/syndtr/goleveldb/leveldb"
|
||||
@@ -35,42 +33,6 @@ func NewLevelDbStorage(path string, errorIfMissing bool) (*Storage, error) {
|
||||
return &Storage{ldb, []byte{}}, nil
|
||||
}
|
||||
|
||||
type storageInfo struct {
|
||||
KeyCount int
|
||||
ClaimCount int
|
||||
}
|
||||
|
||||
// Info implements the method Info of the interface db.Storage
|
||||
func (l *Storage) Info() string {
|
||||
snapshot, err := l.ldb.GetSnapshot()
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
|
||||
keycount := 0
|
||||
claimcount := 0
|
||||
iter := snapshot.NewIterator(nil, nil)
|
||||
for iter.Next() {
|
||||
if iter.Value()[0] == byte(1) {
|
||||
claimcount++
|
||||
}
|
||||
|
||||
keycount++
|
||||
}
|
||||
iter.Release()
|
||||
if err := iter.Error(); err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
json, _ := json.MarshalIndent(
|
||||
storageInfo{
|
||||
KeyCount: keycount,
|
||||
ClaimCount: claimcount,
|
||||
},
|
||||
"", " ",
|
||||
)
|
||||
return string(json)
|
||||
}
|
||||
|
||||
// WithPrefix implements the method WithPrefix of the interface db.Storage
|
||||
func (l *Storage) WithPrefix(prefix []byte) db.Storage {
|
||||
return &Storage{l.ldb, db.Concat(l.prefix, prefix)}
|
||||
|
||||
@@ -25,11 +25,6 @@ func NewMemoryStorage() *Storage {
|
||||
return &Storage{[]byte{}, kvmap}
|
||||
}
|
||||
|
||||
// Info implements the method Info of the interface db.Storage
|
||||
func (m *Storage) Info() string {
|
||||
return "in-memory"
|
||||
}
|
||||
|
||||
// WithPrefix implements the method WithPrefix of the interface db.Storage
|
||||
func (m *Storage) WithPrefix(prefix []byte) db.Storage {
|
||||
return &Storage{db.Concat(m.prefix, prefix), m.kv}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package pebble
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/cockroachdb/pebble"
|
||||
"github.com/iden3/go-merkletree/db"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -32,36 +30,6 @@ func NewPebbleStorage(path string, errorIfMissing bool) (*Storage, error) {
|
||||
return &Storage{rdb, []byte{}}, nil
|
||||
}
|
||||
|
||||
type storageInfo struct {
|
||||
KeyCount int
|
||||
ClaimCount int
|
||||
}
|
||||
|
||||
// Info implements the method Info of the interface db.Storage
|
||||
func (p *Storage) Info() string {
|
||||
keycount := 0
|
||||
claimcount := 0
|
||||
err := p.Iterate(func(key []byte, value []byte) (bool, error) {
|
||||
if value[0] == byte(1) {
|
||||
claimcount++
|
||||
}
|
||||
|
||||
keycount++
|
||||
return true, nil
|
||||
})
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
json, _ := json.MarshalIndent(
|
||||
storageInfo{
|
||||
KeyCount: keycount,
|
||||
ClaimCount: claimcount,
|
||||
},
|
||||
"", " ",
|
||||
)
|
||||
return string(json)
|
||||
}
|
||||
|
||||
// WithPrefix implements the method WithPrefix of the interface db.Storage
|
||||
func (p *Storage) WithPrefix(prefix []byte) db.Storage {
|
||||
return &Storage{p.pdb, db.Concat(p.prefix, prefix)}
|
||||
|
||||
Reference in New Issue
Block a user