2020-03-09 13:17:23 +00:00
|
|
|
package keeper
|
2019-07-24 22:14:12 +00:00
|
|
|
|
|
|
|
import (
|
2020-04-01 18:49:21 +00:00
|
|
|
"encoding/binary"
|
|
|
|
"errors"
|
2019-09-27 14:08:45 +00:00
|
|
|
"fmt"
|
|
|
|
|
2020-04-30 03:36:30 +00:00
|
|
|
"github.com/tendermint/tendermint/libs/log"
|
|
|
|
|
2019-07-25 20:38:55 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2019-07-24 22:14:12 +00:00
|
|
|
ethcmn "github.com/ethereum/go-ethereum/common"
|
|
|
|
ethvm "github.com/ethereum/go-ethereum/core/vm"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-03-09 13:17:23 +00:00
|
|
|
"github.com/cosmos/ethermint/x/evm/types"
|
2019-07-24 22:14:12 +00:00
|
|
|
ethstate "github.com/ethereum/go-ethereum/core/state"
|
|
|
|
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
|
|
|
|
|
|
|
"math/big"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Keeper wraps the CommitStateDB, allowing us to pass in SDK context while adhering
|
2020-03-09 13:17:23 +00:00
|
|
|
// to the StateDB interface.
|
2019-07-24 22:14:12 +00:00
|
|
|
type Keeper struct {
|
2020-03-09 13:17:23 +00:00
|
|
|
// Amino codec
|
|
|
|
cdc *codec.Codec
|
|
|
|
// Store key required to update the block bloom filter mappings needed for the
|
|
|
|
// Web3 API
|
2020-04-01 18:49:21 +00:00
|
|
|
blockKey sdk.StoreKey
|
2020-03-09 13:17:23 +00:00
|
|
|
CommitStateDB *types.CommitStateDB
|
2020-04-01 18:49:21 +00:00
|
|
|
TxCount int
|
2020-03-09 13:17:23 +00:00
|
|
|
Bloom *big.Int
|
2019-10-03 16:46:02 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// NewKeeper generates new evm module keeper
|
2020-04-01 18:49:21 +00:00
|
|
|
func NewKeeper(
|
|
|
|
cdc *codec.Codec, blockKey, codeKey, storeKey sdk.StoreKey,
|
2020-04-22 19:26:01 +00:00
|
|
|
ak types.AccountKeeper, bk types.BankKeeper,
|
2020-04-01 18:49:21 +00:00
|
|
|
) Keeper {
|
2019-07-24 22:14:12 +00:00
|
|
|
return Keeper{
|
2020-03-09 13:17:23 +00:00
|
|
|
cdc: cdc,
|
2020-04-01 18:49:21 +00:00
|
|
|
blockKey: blockKey,
|
2020-04-22 19:26:01 +00:00
|
|
|
CommitStateDB: types.NewCommitStateDB(sdk.Context{}, codeKey, storeKey, ak, bk),
|
2020-04-01 18:49:21 +00:00
|
|
|
TxCount: 0,
|
2020-03-09 13:17:23 +00:00
|
|
|
Bloom: big.NewInt(0),
|
2019-09-27 14:08:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-30 03:36:30 +00:00
|
|
|
// Logger returns a module-specific logger.
|
|
|
|
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
|
|
|
|
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
|
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Block hash mapping functions
|
|
|
|
// May be removed when using only as module (only required by rpc api)
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// GetBlockHashMapping gets block height from block consensus hash
|
2020-04-23 15:49:25 +00:00
|
|
|
func (k Keeper) GetBlockHashMapping(ctx sdk.Context, hash []byte) (int64, error) {
|
2020-04-01 18:49:21 +00:00
|
|
|
store := ctx.KVStore(k.blockKey)
|
2019-09-27 14:08:45 +00:00
|
|
|
bz := store.Get(hash)
|
2020-04-23 15:49:25 +00:00
|
|
|
if len(bz) == 0 {
|
2020-05-15 02:08:13 +00:00
|
|
|
return 0, fmt.Errorf("block with hash '%s' not found", ethcmn.BytesToHash(hash).Hex())
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
2020-04-01 18:49:21 +00:00
|
|
|
|
2020-04-23 15:49:25 +00:00
|
|
|
height := binary.BigEndian.Uint64(bz)
|
|
|
|
return int64(height), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetBlockHashMapping sets the mapping from block consensus hash to block height
|
|
|
|
func (k Keeper) SetBlockHashMapping(ctx sdk.Context, hash []byte, height int64) {
|
|
|
|
store := ctx.KVStore(k.blockKey)
|
|
|
|
bz := sdk.Uint64ToBigEndian(uint64(height))
|
|
|
|
store.Set(hash, bz)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-10-04 19:32:56 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Block bloom bits mapping functions
|
|
|
|
// May be removed when using only as module (only required by rpc api)
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2020-04-23 15:49:25 +00:00
|
|
|
// GetBlockBloomMapping gets bloombits from block height
|
|
|
|
func (k Keeper) GetBlockBloomMapping(ctx sdk.Context, height int64) (ethtypes.Bloom, error) {
|
2020-04-01 18:49:21 +00:00
|
|
|
store := ctx.KVStore(k.blockKey)
|
2020-04-23 15:49:25 +00:00
|
|
|
heightBz := sdk.Uint64ToBigEndian(uint64(height))
|
|
|
|
bz := store.Get(types.BloomKey(heightBz))
|
2020-04-01 18:49:21 +00:00
|
|
|
if len(bz) == 0 {
|
2020-04-23 15:49:25 +00:00
|
|
|
return ethtypes.Bloom{}, fmt.Errorf("block at height %d not found", height)
|
2019-10-04 19:32:56 +00:00
|
|
|
}
|
2020-04-01 18:49:21 +00:00
|
|
|
|
2020-04-23 15:49:25 +00:00
|
|
|
return ethtypes.BytesToBloom(bz), nil
|
2019-10-04 19:32:56 +00:00
|
|
|
}
|
|
|
|
|
2020-04-23 15:49:25 +00:00
|
|
|
// SetBlockBloomMapping sets the mapping from block height to bloom bits
|
|
|
|
func (k Keeper) SetBlockBloomMapping(ctx sdk.Context, bloom ethtypes.Bloom, height int64) {
|
2020-04-01 18:49:21 +00:00
|
|
|
store := ctx.KVStore(k.blockKey)
|
2020-04-23 15:49:25 +00:00
|
|
|
heightBz := sdk.Uint64ToBigEndian(uint64(height))
|
|
|
|
store.Set(types.BloomKey(heightBz), bloom.Bytes())
|
2020-04-01 18:49:21 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 15:47:39 +00:00
|
|
|
// SetTransactionLogs sets the transaction's logs in the KVStore
|
2020-04-01 18:49:21 +00:00
|
|
|
func (k *Keeper) SetTransactionLogs(ctx sdk.Context, logs []*ethtypes.Log, hash []byte) error {
|
|
|
|
store := ctx.KVStore(k.blockKey)
|
|
|
|
encLogs, err := types.EncodeLogs(logs)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-23 15:49:25 +00:00
|
|
|
store.Set(types.LogsKey(hash), encLogs)
|
2020-04-01 18:49:21 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-04-16 15:47:39 +00:00
|
|
|
// GetTransactionLogs gets the logs for a transaction from the KVStore
|
2020-04-01 18:49:21 +00:00
|
|
|
func (k *Keeper) GetTransactionLogs(ctx sdk.Context, hash []byte) ([]*ethtypes.Log, error) {
|
|
|
|
store := ctx.KVStore(k.blockKey)
|
|
|
|
encLogs := store.Get(types.LogsKey(hash))
|
|
|
|
if len(encLogs) == 0 {
|
|
|
|
return nil, errors.New("cannot get transaction logs")
|
|
|
|
}
|
|
|
|
|
|
|
|
return types.DecodeLogs(encLogs)
|
2019-10-04 19:32:56 +00:00
|
|
|
}
|
|
|
|
|
2019-07-25 20:38:55 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Genesis
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// CreateGenesisAccount initializes an account and its balance, code, and storage
|
2020-03-09 13:17:23 +00:00
|
|
|
func (k *Keeper) CreateGenesisAccount(ctx sdk.Context, account types.GenesisAccount) {
|
|
|
|
csdb := k.CommitStateDB.WithContext(ctx)
|
2019-07-25 20:38:55 +00:00
|
|
|
csdb.SetBalance(account.Address, account.Balance)
|
|
|
|
csdb.SetCode(account.Address, account.Code)
|
|
|
|
for _, key := range account.Storage {
|
|
|
|
csdb.SetState(account.Address, key, account.Storage[key])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-24 22:14:12 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Setters
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// SetBalance calls CommitStateDB.SetBalance using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) SetBalance(ctx sdk.Context, addr ethcmn.Address, amount *big.Int) {
|
2020-03-09 13:17:23 +00:00
|
|
|
k.CommitStateDB.WithContext(ctx).SetBalance(addr, amount)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// AddBalance calls CommitStateDB.AddBalance using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) AddBalance(ctx sdk.Context, addr ethcmn.Address, amount *big.Int) {
|
2020-03-09 13:17:23 +00:00
|
|
|
k.CommitStateDB.WithContext(ctx).AddBalance(addr, amount)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// SubBalance calls CommitStateDB.SubBalance using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) SubBalance(ctx sdk.Context, addr ethcmn.Address, amount *big.Int) {
|
2020-03-09 13:17:23 +00:00
|
|
|
k.CommitStateDB.WithContext(ctx).SubBalance(addr, amount)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// SetNonce calls CommitStateDB.SetNonce using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) SetNonce(ctx sdk.Context, addr ethcmn.Address, nonce uint64) {
|
2020-03-09 13:17:23 +00:00
|
|
|
k.CommitStateDB.WithContext(ctx).SetNonce(addr, nonce)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// SetState calls CommitStateDB.SetState using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) SetState(ctx sdk.Context, addr ethcmn.Address, key, value ethcmn.Hash) {
|
2020-03-09 13:17:23 +00:00
|
|
|
k.CommitStateDB.WithContext(ctx).SetState(addr, key, value)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// SetCode calls CommitStateDB.SetCode using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) SetCode(ctx sdk.Context, addr ethcmn.Address, code []byte) {
|
2020-03-09 13:17:23 +00:00
|
|
|
k.CommitStateDB.WithContext(ctx).SetCode(addr, code)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// AddLog calls CommitStateDB.AddLog using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) AddLog(ctx sdk.Context, log *ethtypes.Log) {
|
2020-03-09 13:17:23 +00:00
|
|
|
k.CommitStateDB.WithContext(ctx).AddLog(log)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// AddPreimage calls CommitStateDB.AddPreimage using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) AddPreimage(ctx sdk.Context, hash ethcmn.Hash, preimage []byte) {
|
2020-03-09 13:17:23 +00:00
|
|
|
k.CommitStateDB.WithContext(ctx).AddPreimage(hash, preimage)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// AddRefund calls CommitStateDB.AddRefund using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) AddRefund(ctx sdk.Context, gas uint64) {
|
2020-03-09 13:17:23 +00:00
|
|
|
k.CommitStateDB.WithContext(ctx).AddRefund(gas)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// SubRefund calls CommitStateDB.SubRefund using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) SubRefund(ctx sdk.Context, gas uint64) {
|
2020-03-09 13:17:23 +00:00
|
|
|
k.CommitStateDB.WithContext(ctx).SubRefund(gas)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Getters
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// GetBalance calls CommitStateDB.GetBalance using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) GetBalance(ctx sdk.Context, addr ethcmn.Address) *big.Int {
|
2020-03-09 13:17:23 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).GetBalance(addr)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// GetNonce calls CommitStateDB.GetNonce using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) GetNonce(ctx sdk.Context, addr ethcmn.Address) uint64 {
|
2020-03-09 13:17:23 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).GetNonce(addr)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// TxIndex calls CommitStateDB.TxIndex using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) TxIndex(ctx sdk.Context) int {
|
2020-03-09 13:17:23 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).TxIndex()
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// BlockHash calls CommitStateDB.BlockHash using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) BlockHash(ctx sdk.Context) ethcmn.Hash {
|
2020-03-09 13:17:23 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).BlockHash()
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// GetCode calls CommitStateDB.GetCode using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) GetCode(ctx sdk.Context, addr ethcmn.Address) []byte {
|
2020-03-09 13:17:23 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).GetCode(addr)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// GetCodeSize calls CommitStateDB.GetCodeSize using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) GetCodeSize(ctx sdk.Context, addr ethcmn.Address) int {
|
2020-03-09 13:17:23 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).GetCodeSize(addr)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// GetCodeHash calls CommitStateDB.GetCodeHash using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) GetCodeHash(ctx sdk.Context, addr ethcmn.Address) ethcmn.Hash {
|
2020-03-09 13:17:23 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).GetCodeHash(addr)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// GetState calls CommitStateDB.GetState using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) GetState(ctx sdk.Context, addr ethcmn.Address, hash ethcmn.Hash) ethcmn.Hash {
|
2020-03-09 13:17:23 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).GetState(addr, hash)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// GetCommittedState calls CommitStateDB.GetCommittedState using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) GetCommittedState(ctx sdk.Context, addr ethcmn.Address, hash ethcmn.Hash) ethcmn.Hash {
|
2020-03-09 13:17:23 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).GetCommittedState(addr, hash)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// GetLogs calls CommitStateDB.GetLogs using the passed in context
|
2020-04-01 18:49:21 +00:00
|
|
|
func (k *Keeper) GetLogs(ctx sdk.Context, hash ethcmn.Hash) ([]*ethtypes.Log, error) {
|
2020-04-16 15:47:39 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).GetLogs(hash)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2020-04-01 18:49:21 +00:00
|
|
|
// AllLogs calls CommitStateDB.AllLogs using the passed in context
|
|
|
|
func (k *Keeper) AllLogs(ctx sdk.Context) []*ethtypes.Log {
|
|
|
|
return k.CommitStateDB.WithContext(ctx).AllLogs()
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// GetRefund calls CommitStateDB.GetRefund using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) GetRefund(ctx sdk.Context) uint64 {
|
2020-03-09 13:17:23 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).GetRefund()
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// Preimages calls CommitStateDB.Preimages using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) Preimages(ctx sdk.Context) map[ethcmn.Hash][]byte {
|
2020-03-09 13:17:23 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).Preimages()
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// HasSuicided calls CommitStateDB.HasSuicided using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) HasSuicided(ctx sdk.Context, addr ethcmn.Address) bool {
|
2020-03-09 13:17:23 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).HasSuicided(addr)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// StorageTrie calls CommitStateDB.StorageTrie using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) StorageTrie(ctx sdk.Context, addr ethcmn.Address) ethstate.Trie {
|
2020-03-09 13:17:23 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).StorageTrie(addr)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Persistence
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// Commit calls CommitStateDB.Commit using the passed { in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) Commit(ctx sdk.Context, deleteEmptyObjects bool) (root ethcmn.Hash, err error) {
|
2020-03-09 13:17:23 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).Commit(deleteEmptyObjects)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// Finalise calls CommitStateDB.Finalise using the passed in context
|
2020-04-01 18:49:21 +00:00
|
|
|
func (k *Keeper) Finalise(ctx sdk.Context, deleteEmptyObjects bool) error {
|
|
|
|
return k.CommitStateDB.WithContext(ctx).Finalise(deleteEmptyObjects)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// IntermediateRoot calls CommitStateDB.IntermediateRoot using the passed in context
|
2020-04-01 18:49:21 +00:00
|
|
|
func (k *Keeper) IntermediateRoot(ctx sdk.Context, deleteEmptyObjects bool) error {
|
|
|
|
_, err := k.CommitStateDB.WithContext(ctx).IntermediateRoot(deleteEmptyObjects)
|
2020-04-16 15:47:39 +00:00
|
|
|
return err
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Snapshotting
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// Snapshot calls CommitStateDB.Snapshot using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) Snapshot(ctx sdk.Context) int {
|
2020-03-09 13:17:23 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).Snapshot()
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// RevertToSnapshot calls CommitStateDB.RevertToSnapshot using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) RevertToSnapshot(ctx sdk.Context, revID int) {
|
2020-03-09 13:17:23 +00:00
|
|
|
k.CommitStateDB.WithContext(ctx).RevertToSnapshot(revID)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Auxiliary
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// Database calls CommitStateDB.Database using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) Database(ctx sdk.Context) ethstate.Database {
|
2020-03-09 13:17:23 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).Database()
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// Empty calls CommitStateDB.Empty using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) Empty(ctx sdk.Context, addr ethcmn.Address) bool {
|
2020-03-09 13:17:23 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).Empty(addr)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// Exist calls CommitStateDB.Exist using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) Exist(ctx sdk.Context, addr ethcmn.Address) bool {
|
2020-03-09 13:17:23 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).Exist(addr)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// Error calls CommitStateDB.Error using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) Error(ctx sdk.Context) error {
|
2020-03-09 13:17:23 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).Error()
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// Suicide calls CommitStateDB.Suicide using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) Suicide(ctx sdk.Context, addr ethcmn.Address) bool {
|
2020-03-09 13:17:23 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).Suicide(addr)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// Reset calls CommitStateDB.Reset using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) Reset(ctx sdk.Context, root ethcmn.Hash) error {
|
2020-03-09 13:17:23 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).Reset(root)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// Prepare calls CommitStateDB.Prepare using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) Prepare(ctx sdk.Context, thash, bhash ethcmn.Hash, txi int) {
|
2020-03-09 13:17:23 +00:00
|
|
|
k.CommitStateDB.WithContext(ctx).Prepare(thash, bhash, txi)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// CreateAccount calls CommitStateDB.CreateAccount using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) CreateAccount(ctx sdk.Context, addr ethcmn.Address) {
|
2020-03-09 13:17:23 +00:00
|
|
|
k.CommitStateDB.WithContext(ctx).CreateAccount(addr)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// Copy calls CommitStateDB.Copy using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) Copy(ctx sdk.Context) ethvm.StateDB {
|
2020-03-09 13:17:23 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).Copy()
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// ForEachStorage calls CommitStateDB.ForEachStorage using passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) ForEachStorage(ctx sdk.Context, addr ethcmn.Address, cb func(key, value ethcmn.Hash) bool) error {
|
2020-03-09 13:17:23 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).ForEachStorage(addr, cb)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 14:08:45 +00:00
|
|
|
// GetOrNewStateObject calls CommitStateDB.GetOrNetStateObject using the passed in context
|
2019-07-24 22:14:12 +00:00
|
|
|
func (k *Keeper) GetOrNewStateObject(ctx sdk.Context, addr ethcmn.Address) types.StateObject {
|
2020-03-09 13:17:23 +00:00
|
|
|
return k.CommitStateDB.WithContext(ctx).GetOrNewStateObject(addr)
|
2019-07-24 22:14:12 +00:00
|
|
|
}
|