github.com/MetalBlockchain/subnet-evm@v0.4.9/plugin/evm/database.go (about) 1 // (c) 2019-2020, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package evm 5 6 import ( 7 "github.com/MetalBlockchain/subnet-evm/ethdb" 8 9 "github.com/MetalBlockchain/metalgo/database" 10 ) 11 12 var _ ethdb.Database = &Database{} 13 14 // Database implements ethdb.Database 15 type Database struct{ database.Database } 16 17 // Stat implements ethdb.Database 18 func (db Database) Stat(string) (string, error) { return "", database.ErrNotFound } 19 20 // NewBatch implements ethdb.Database 21 func (db Database) NewBatch() ethdb.Batch { return Batch{db.Database.NewBatch()} } 22 23 // NewBatchWithSize implements ethdb.Database 24 // TODO: propagate size through metalgo Database interface 25 func (db Database) NewBatchWithSize(size int) ethdb.Batch { return Batch{db.Database.NewBatch()} } 26 27 // NewIterator implements ethdb.Database 28 // 29 // Note: This method assumes that the prefix is NOT part of the start, so there's 30 // no need for the caller to prepend the prefix to the start. 31 func (db Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator { 32 // metalgo's database implementation assumes that the prefix is part of the 33 // start, so it is added here (if it is provided). 34 if len(prefix) > 0 { 35 newStart := make([]byte, len(prefix)+len(start)) 36 copy(newStart, prefix) 37 copy(newStart[len(prefix):], start) 38 start = newStart 39 } 40 return db.Database.NewIteratorWithStartAndPrefix(start, prefix) 41 } 42 43 // NewIteratorWithStart implements ethdb.Database 44 func (db Database) NewIteratorWithStart(start []byte) ethdb.Iterator { 45 return db.Database.NewIteratorWithStart(start) 46 } 47 48 // Batch implements ethdb.Batch 49 type Batch struct{ database.Batch } 50 51 // ValueSize implements ethdb.Batch 52 func (batch Batch) ValueSize() int { return batch.Batch.Size() } 53 54 // Replay implements ethdb.Batch 55 func (batch Batch) Replay(w ethdb.KeyValueWriter) error { return batch.Batch.Replay(w) }