Add a db wrapper to enable iteration

This commit is contained in:
Austin Roberts 2021-09-28 14:01:01 -05:00
parent 65f00aad1c
commit 1b06b9762a
2 changed files with 37 additions and 1 deletions

View File

@ -0,0 +1,36 @@
package wrappers
import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/openrelayxyz/plugeth-utils/restricted"
)
type dbWrapper struct{
db ethdb.Database
}
func (d *dbWrapper) Has(key []byte) (bool, error) { return d.db.Has(key) }
func (d *dbWrapper) Get(key []byte) ([]byte, error) { return d.db.Get(key) }
func (d *dbWrapper) Put(key []byte, value []byte) error { return d.db.Put(key, value) }
func (d *dbWrapper) Delete(key []byte) error { return d.db.Delete(key) }
func (d *dbWrapper) Stat(property string) (string, error) { return d.db.Stat(property) }
func (d *dbWrapper) Compact(start []byte, limit []byte) error { return d.db.Compact(start, limit) }
func (d *dbWrapper) HasAncient(kind string, number uint64) (bool, error) { return d.db.HasAncient(kind, number) }
func (d *dbWrapper) Ancient(kind string, number uint64) ([]byte, error) { return d.db.Ancient(kind, number) }
func (d *dbWrapper) Ancients() (uint64, error) { return d.db.Ancients() }
func (d *dbWrapper) AncientSize(kind string) (uint64, error) { return d.db.AncientSize(kind) }
func (d *dbWrapper) AppendAncient(number uint64, hash, header, body, receipt, td []byte) error { return d.db.AppendAncient(number, hash, header, body, receipt, td) }
func (d *dbWrapper) TruncateAncients(n uint64) error { return d.db.TruncateAncients(n) }
func (d *dbWrapper) Sync() error { return d.db.Sync() }
func (d *dbWrapper) Close() error { return d.db.Close() }
func (d *dbWrapper) NewIterator(prefix []byte, start []byte) restricted.Iterator { return &iterWrapper{d.db.NewIterator(prefix, start)} }
type iterWrapper struct {
iter ethdb.Iterator
}
func (it *iterWrapper) Next() bool { return it.iter.Next() }
func (it *iterWrapper) Error() error { return it.iter.Error() }
func (it *iterWrapper) Key() []byte { return it.iter.Key() }
func (it *iterWrapper) Value() []byte { return it.iter.Value() }
func (it *iterWrapper) Release() { it.iter.Release() }

View File

@ -240,7 +240,7 @@ func (b *Backend) SuggestGasTipCap(ctx context.Context) (*big.Int, error) {
return b.b.SuggestGasTipCap(ctx) return b.b.SuggestGasTipCap(ctx)
} }
func (b *Backend) ChainDb() restricted.Database { func (b *Backend) ChainDb() restricted.Database {
return b.b.ChainDb() return &dbWrapper{b.b.ChainDb()}
} }
func (b *Backend) ExtRPCEnabled() bool { func (b *Backend) ExtRPCEnabled() bool {
return b.b.ExtRPCEnabled() return b.b.ExtRPCEnabled()