2018-10-03 00:22:15 +00:00
|
|
|
package state
|
2018-07-04 23:38:20 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
ethdb "github.com/ethereum/go-ethereum/ethdb"
|
2018-07-18 18:14:14 +00:00
|
|
|
|
2018-07-04 23:38:20 +00:00
|
|
|
dbm "github.com/tendermint/tendermint/libs/db"
|
|
|
|
)
|
|
|
|
|
|
|
|
// EthereumDB implements Ethereum's ethdb.Database and ethdb.Batch interfaces.
|
|
|
|
// It will be used to facilitate persistence of codeHash => code mappings.
|
|
|
|
type EthereumDB struct {
|
2018-07-05 01:00:29 +00:00
|
|
|
CodeDB dbm.DB
|
2018-07-04 23:38:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Put implements Ethereum's ethdb.Putter interface. It wraps the database
|
|
|
|
// write operation supported by both batches and regular databases.
|
|
|
|
func (edb *EthereumDB) Put(key []byte, value []byte) error {
|
2018-07-05 01:00:29 +00:00
|
|
|
edb.CodeDB.Set(key, value)
|
2018-07-04 23:38:20 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get implements Ethereum's ethdb.Database interface. It returns a value for a
|
|
|
|
// given key.
|
|
|
|
func (edb *EthereumDB) Get(key []byte) ([]byte, error) {
|
2018-07-05 01:00:29 +00:00
|
|
|
return edb.CodeDB.Get(key), nil
|
2018-07-04 23:38:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Has implements Ethereum's ethdb.Database interface. It returns a boolean
|
|
|
|
// determining if the underlying database has the given key or not.
|
|
|
|
func (edb *EthereumDB) Has(key []byte) (bool, error) {
|
2018-07-05 01:00:29 +00:00
|
|
|
return edb.CodeDB.Has(key), nil
|
2018-07-04 23:38:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Delete implements Ethereum's ethdb.Database interface. It removes a given
|
|
|
|
// key from the underlying database.
|
|
|
|
func (edb *EthereumDB) Delete(key []byte) error {
|
2018-07-05 01:00:29 +00:00
|
|
|
edb.CodeDB.Delete(key)
|
2018-07-04 23:38:20 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close implements Ethereum's ethdb.Database interface. It closes the
|
|
|
|
// underlying database.
|
|
|
|
func (edb *EthereumDB) Close() {
|
2018-07-05 01:00:29 +00:00
|
|
|
edb.CodeDB.Close()
|
2018-07-04 23:38:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewBatch implements Ethereum's ethdb.Database interface. It returns a new
|
|
|
|
// Batch object used for batch database operations.
|
|
|
|
func (edb *EthereumDB) NewBatch() ethdb.Batch {
|
|
|
|
return edb
|
|
|
|
}
|
|
|
|
|
|
|
|
// ValueSize implements Ethereum's ethdb.Database interface. It performs a
|
|
|
|
// no-op.
|
|
|
|
func (edb *EthereumDB) ValueSize() int {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write implements Ethereum's ethdb.Database interface. It performs a no-op.
|
|
|
|
func (edb *EthereumDB) Write() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset implements Ethereum's ethdb.Database interface. It performs a no-op.
|
|
|
|
func (edb *EthereumDB) Reset() {
|
|
|
|
}
|