github.com/dim4egster/coreth@v0.10.2/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/dim4egster/qmallgo/database"
     8  	"github.com/dim4egster/coreth/ethdb"
     9  )
    10  
    11  var _ ethdb.Database = &Database{}
    12  
    13  // Database implements ethdb.Database
    14  type Database struct{ database.Database }
    15  
    16  // Stat implements ethdb.Database
    17  func (db Database) Stat(string) (string, error) { return "", database.ErrNotFound }
    18  
    19  // NewBatch implements ethdb.Database
    20  func (db Database) NewBatch() ethdb.Batch { return Batch{db.Database.NewBatch()} }
    21  
    22  // NewBatchWithSize implements ethdb.Database
    23  // TODO: propagate size through qmallgo Database interface
    24  func (db Database) NewBatchWithSize(size int) ethdb.Batch { return Batch{db.Database.NewBatch()} }
    25  
    26  // NewIterator implements ethdb.Database
    27  //
    28  // Note: This method assumes that the prefix is NOT part of the start, so there's
    29  // no need for the caller to prepend the prefix to the start.
    30  func (db Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator {
    31  	// qmallgo's database implementation assumes that the prefix is part of the
    32  	// start, so it is added here (if it is provided).
    33  	if len(prefix) > 0 {
    34  		newStart := make([]byte, len(prefix)+len(start))
    35  		copy(newStart, prefix)
    36  		copy(newStart[len(prefix):], start)
    37  		start = newStart
    38  	}
    39  	return db.Database.NewIteratorWithStartAndPrefix(start, prefix)
    40  }
    41  
    42  // NewIteratorWithStart implements ethdb.Database
    43  func (db Database) NewIteratorWithStart(start []byte) ethdb.Iterator {
    44  	return db.Database.NewIteratorWithStart(start)
    45  }
    46  
    47  // Batch implements ethdb.Batch
    48  type Batch struct{ database.Batch }
    49  
    50  // ValueSize implements ethdb.Batch
    51  func (batch Batch) ValueSize() int { return batch.Batch.Size() }
    52  
    53  // Replay implements ethdb.Batch
    54  func (batch Batch) Replay(w ethdb.KeyValueWriter) error { return batch.Batch.Replay(w) }