github.com/unicornultrafoundation/go-u2u@v1.0.0-rc1.0.20240205080301-e74a83d3fadc/utils/adapters/ethdb2udb/adapter.go (about) 1 package ethdb2udb 2 3 import ( 4 "github.com/unicornultrafoundation/go-helios/u2udb" 5 "github.com/unicornultrafoundation/go-u2u/ethdb" 6 ) 7 8 type Adapter struct { 9 ethdb.KeyValueStore 10 } 11 12 var _ u2udb.Store = (*Adapter)(nil) 13 14 func Wrap(v ethdb.KeyValueStore) *Adapter { 15 return &Adapter{v} 16 } 17 18 func (db *Adapter) Drop() { 19 panic("called Drop on ethdb") 20 } 21 22 // batch is a write-only memory batch that commits changes to its host 23 // database when Write is called. A batch cannot be used concurrently. 24 type batch struct { 25 ethdb.Batch 26 } 27 28 // Replay replays the batch contents. 29 func (b *batch) Replay(w u2udb.Writer) error { 30 return b.Batch.Replay(w) 31 } 32 33 // NewBatch creates a write-only key-value store that buffers changes to its host 34 // database until a final write is called. 35 func (db *Adapter) NewBatch() u2udb.Batch { 36 return &batch{db.KeyValueStore.NewBatch()} 37 } 38 39 func (db *Adapter) GetSnapshot() (u2udb.Snapshot, error) { 40 panic("called GetSnapshot on ethdb") 41 return nil, nil 42 } 43 44 // NewIterator creates a binary-alphabetical iterator over a subset 45 // of database content with a particular key prefix, starting at a particular 46 // initial key (or after, if it does not exist). 47 func (db *Adapter) NewIterator(prefix []byte, start []byte) u2udb.Iterator { 48 return db.KeyValueStore.NewIterator(prefix, start) 49 }