2020-03-09 13:17:23 +00:00
|
|
|
package keeper
|
2019-07-24 22:14:12 +00:00
|
|
|
|
|
|
|
import (
|
2021-05-25 12:56:36 +00:00
|
|
|
"bytes"
|
2020-06-04 10:40:21 +00:00
|
|
|
"math/big"
|
2019-09-27 14:08:45 +00:00
|
|
|
|
2019-07-25 20:38:55 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2021-05-25 12:56:36 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/store/prefix"
|
2019-07-24 22:14:12 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2021-04-17 10:00:07 +00:00
|
|
|
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
2020-08-23 21:41:54 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2019-07-24 22:14:12 +00:00
|
|
|
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
2021-06-29 17:02:21 +00:00
|
|
|
"github.com/palantir/stacktrace"
|
2021-04-18 15:54:18 +00:00
|
|
|
"github.com/tendermint/tendermint/libs/log"
|
|
|
|
|
2021-06-22 10:49:18 +00:00
|
|
|
ethermint "github.com/tharsis/ethermint/types"
|
|
|
|
"github.com/tharsis/ethermint/x/evm/types"
|
2019-07-24 22:14:12 +00:00
|
|
|
)
|
|
|
|
|
2021-08-05 16:24:06 +00:00
|
|
|
// Keeper grants access to the EVM module state and implements the go-ethereum StateDB interface.
|
2019-07-24 22:14:12 +00:00
|
|
|
type Keeper struct {
|
2021-04-17 10:00:07 +00:00
|
|
|
// Protobuf codec
|
2021-06-30 09:35:11 +00:00
|
|
|
cdc codec.BinaryCodec
|
2020-06-04 10:40:21 +00:00
|
|
|
// Store key required for the EVM Prefix KVStore. It is required by:
|
2021-08-05 16:24:06 +00:00
|
|
|
// - storing account's Storage State
|
|
|
|
// - storing account's Code
|
2020-06-04 10:40:21 +00:00
|
|
|
// - storing transaction Logs
|
2021-08-05 16:24:06 +00:00
|
|
|
// - storing Bloom filters by block height. Needed for the Web3 API.
|
2020-09-02 19:41:05 +00:00
|
|
|
storeKey sdk.StoreKey
|
2021-04-18 15:54:18 +00:00
|
|
|
|
2021-05-25 12:56:36 +00:00
|
|
|
// key to access the transient store, which is reset on every block during Commit
|
|
|
|
transientKey sdk.StoreKey
|
|
|
|
|
2021-08-05 16:24:06 +00:00
|
|
|
// module specific parameter space that can be configured through governance
|
|
|
|
paramSpace paramtypes.Subspace
|
|
|
|
// access to account state
|
2020-12-15 18:43:06 +00:00
|
|
|
accountKeeper types.AccountKeeper
|
2021-08-05 16:24:06 +00:00
|
|
|
// update balance and accounting operations with coins
|
|
|
|
bankKeeper types.BankKeeper
|
|
|
|
// access historical headers for EVM state transition execution
|
2021-06-07 11:00:14 +00:00
|
|
|
stakingKeeper types.StakingKeeper
|
2021-04-18 15:54:18 +00:00
|
|
|
|
2021-08-10 07:22:46 +00:00
|
|
|
// Manage the initial context and cache context stack for accessing the store,
|
|
|
|
// emit events and log info.
|
2021-08-05 16:24:06 +00:00
|
|
|
// It is kept as a field to make is accessible by the StateDb
|
|
|
|
// functions. Resets on every transaction/block.
|
2021-08-10 07:22:46 +00:00
|
|
|
ctxStack ContextStack
|
2021-06-29 10:54:29 +00:00
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
// chain ID number obtained from the context's chain id
|
|
|
|
eip155ChainID *big.Int
|
2021-08-16 09:45:10 +00:00
|
|
|
|
|
|
|
// Tracer used to collect execution traces from the EVM transaction execution
|
|
|
|
tracer string
|
2021-08-05 16:24:06 +00:00
|
|
|
// trace EVM state transition execution. This value is obtained from the `--trace` flag.
|
|
|
|
// For more info check https://geth.ethereum.org/docs/dapp/tracing
|
|
|
|
debug bool
|
2021-09-02 12:36:33 +00:00
|
|
|
|
|
|
|
// EVM Hooks for tx post-processing
|
|
|
|
hooks types.EvmHooks
|
2021-09-17 06:22:52 +00:00
|
|
|
|
|
|
|
// error from previous state operation
|
|
|
|
stateErr error
|
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(
|
2021-06-30 09:35:11 +00:00
|
|
|
cdc codec.BinaryCodec,
|
2021-06-29 17:02:21 +00:00
|
|
|
storeKey, transientKey sdk.StoreKey, paramSpace paramtypes.Subspace,
|
2021-06-07 11:00:14 +00:00
|
|
|
ak types.AccountKeeper, bankKeeper types.BankKeeper, sk types.StakingKeeper,
|
2021-08-16 09:45:10 +00:00
|
|
|
tracer string, debug bool,
|
2021-01-07 11:55:01 +00:00
|
|
|
) *Keeper {
|
2021-06-29 17:02:21 +00:00
|
|
|
// ensure evm module account is set
|
|
|
|
if addr := ak.GetModuleAddress(types.ModuleName); addr == nil {
|
|
|
|
panic("the EVM module account has not been set")
|
|
|
|
}
|
|
|
|
|
2020-09-02 19:41:05 +00:00
|
|
|
// set KeyTable if it has not already been set
|
|
|
|
if !paramSpace.HasKeyTable() {
|
|
|
|
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: we pass in the parameter space to the CommitStateDB in order to use custom denominations for the EVM operations
|
2021-01-07 11:55:01 +00:00
|
|
|
return &Keeper{
|
2020-03-09 13:17:23 +00:00
|
|
|
cdc: cdc,
|
2021-05-25 12:56:36 +00:00
|
|
|
paramSpace: paramSpace,
|
2020-12-15 18:43:06 +00:00
|
|
|
accountKeeper: ak,
|
2021-04-17 10:00:07 +00:00
|
|
|
bankKeeper: bankKeeper,
|
2021-06-07 11:00:14 +00:00
|
|
|
stakingKeeper: sk,
|
2021-04-17 10:00:07 +00:00
|
|
|
storeKey: storeKey,
|
2021-05-25 12:56:36 +00:00
|
|
|
transientKey: transientKey,
|
2021-08-16 09:45:10 +00:00
|
|
|
tracer: tracer,
|
2021-06-29 17:02:21 +00:00
|
|
|
debug: debug,
|
2021-09-17 06:22:52 +00:00
|
|
|
stateErr: nil,
|
2019-09-27 14:08:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-10 07:22:46 +00:00
|
|
|
// Ctx returns the current context from the context stack
|
|
|
|
func (k Keeper) Ctx() sdk.Context {
|
|
|
|
return k.ctxStack.CurrentContext()
|
|
|
|
}
|
|
|
|
|
|
|
|
// CommitCachedContexts commit all the cache contexts created by `StateDB.Snapshot`.
|
|
|
|
func (k *Keeper) CommitCachedContexts() {
|
|
|
|
k.ctxStack.Commit()
|
|
|
|
}
|
|
|
|
|
|
|
|
// CachedContextsEmpty returns true if there's no cache contexts.
|
|
|
|
func (k *Keeper) CachedContextsEmpty() bool {
|
|
|
|
return k.ctxStack.IsEmpty()
|
2021-08-04 07:49:02 +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 {
|
2021-04-18 15:54:18 +00:00
|
|
|
return ctx.Logger().With("module", types.ModuleName)
|
2020-04-30 03:36:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-10 07:22:46 +00:00
|
|
|
// WithContext clears the context stack, and set the initial context.
|
2021-05-25 12:56:36 +00:00
|
|
|
func (k *Keeper) WithContext(ctx sdk.Context) {
|
2021-08-10 07:22:46 +00:00
|
|
|
k.ctxStack.Reset(ctx)
|
2021-05-25 12:56:36 +00:00
|
|
|
}
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
// WithChainID sets the chain id to the local variable in the keeper
|
|
|
|
func (k *Keeper) WithChainID(ctx sdk.Context) {
|
|
|
|
chainID, err := ethermint.ParseChainID(ctx.ChainID())
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if k.eip155ChainID != nil && k.eip155ChainID.Cmp(chainID) != 0 {
|
|
|
|
panic("chain id already set")
|
|
|
|
}
|
|
|
|
|
|
|
|
k.eip155ChainID = chainID
|
|
|
|
}
|
|
|
|
|
|
|
|
// ChainID returns the EIP155 chain ID for the EVM context
|
|
|
|
func (k Keeper) ChainID() *big.Int {
|
|
|
|
return k.eip155ChainID
|
|
|
|
}
|
|
|
|
|
2020-12-07 20:09:09 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2021-05-25 12:56:36 +00:00
|
|
|
// Block Bloom
|
2021-04-18 15:54:18 +00:00
|
|
|
// Required by Web3 API.
|
2020-12-07 20:09:09 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2021-09-15 09:45:03 +00:00
|
|
|
// EmitBlockBloomEvent emit block bloom events
|
|
|
|
func (k Keeper) EmitBlockBloomEvent(ctx sdk.Context, bloom ethtypes.Bloom) {
|
|
|
|
ctx.EventManager().EmitEvent(
|
|
|
|
sdk.NewEvent(
|
|
|
|
types.EventTypeBlockBloom,
|
|
|
|
sdk.NewAttribute(types.AttributeKeyEthereumBloom, string(bloom.Bytes())),
|
|
|
|
),
|
|
|
|
)
|
2021-04-18 15:54:18 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 12:56:36 +00:00
|
|
|
// GetBlockBloomTransient returns bloom bytes for the current block height
|
2021-06-30 07:37:03 +00:00
|
|
|
func (k Keeper) GetBlockBloomTransient() *big.Int {
|
2021-08-10 07:22:46 +00:00
|
|
|
store := prefix.NewStore(k.Ctx().TransientStore(k.transientKey), types.KeyPrefixTransientBloom)
|
|
|
|
heightBz := sdk.Uint64ToBigEndian(uint64(k.Ctx().BlockHeight()))
|
2021-07-12 10:25:15 +00:00
|
|
|
bz := store.Get(heightBz)
|
2021-05-25 12:56:36 +00:00
|
|
|
if len(bz) == 0 {
|
2021-06-30 07:37:03 +00:00
|
|
|
return big.NewInt(0)
|
2021-05-25 12:56:36 +00:00
|
|
|
}
|
|
|
|
|
2021-06-30 07:37:03 +00:00
|
|
|
return new(big.Int).SetBytes(bz)
|
2021-05-25 12:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetBlockBloomTransient sets the given bloom bytes to the transient store. This value is reset on
|
|
|
|
// every block.
|
|
|
|
func (k Keeper) SetBlockBloomTransient(bloom *big.Int) {
|
2021-08-10 07:22:46 +00:00
|
|
|
store := prefix.NewStore(k.Ctx().TransientStore(k.transientKey), types.KeyPrefixTransientBloom)
|
|
|
|
heightBz := sdk.Uint64ToBigEndian(uint64(k.Ctx().BlockHeight()))
|
2021-07-12 10:25:15 +00:00
|
|
|
store.Set(heightBz, bloom.Bytes())
|
2021-05-25 12:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Tx
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2021-06-30 09:35:11 +00:00
|
|
|
// GetTxHashTransient returns the hash of current processing transaction
|
|
|
|
func (k Keeper) GetTxHashTransient() common.Hash {
|
2021-08-10 07:22:46 +00:00
|
|
|
store := k.Ctx().TransientStore(k.transientKey)
|
2021-06-30 09:35:11 +00:00
|
|
|
bz := store.Get(types.KeyPrefixTransientTxHash)
|
|
|
|
if len(bz) == 0 {
|
|
|
|
return common.Hash{}
|
|
|
|
}
|
|
|
|
|
|
|
|
return common.BytesToHash(bz)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetTxHashTransient set the hash of processing transaction
|
|
|
|
func (k Keeper) SetTxHashTransient(hash common.Hash) {
|
2021-08-10 07:22:46 +00:00
|
|
|
store := k.Ctx().TransientStore(k.transientKey)
|
2021-06-30 09:35:11 +00:00
|
|
|
store.Set(types.KeyPrefixTransientTxHash, hash.Bytes())
|
|
|
|
}
|
|
|
|
|
2021-09-04 20:33:06 +00:00
|
|
|
// SetTxIndexTransient set the index of processing transaction
|
|
|
|
func (k Keeper) SetTxIndexTransient(index uint64) {
|
|
|
|
store := k.Ctx().TransientStore(k.transientKey)
|
|
|
|
store.Set(types.KeyPrefixTransientTxIndex, sdk.Uint64ToBigEndian(index))
|
|
|
|
}
|
|
|
|
|
2021-05-25 12:56:36 +00:00
|
|
|
// GetTxIndexTransient returns EVM transaction index on the current block.
|
|
|
|
func (k Keeper) GetTxIndexTransient() uint64 {
|
2021-08-10 07:22:46 +00:00
|
|
|
store := k.Ctx().TransientStore(k.transientKey)
|
2021-06-30 09:35:11 +00:00
|
|
|
bz := store.Get(types.KeyPrefixTransientTxIndex)
|
2021-05-25 12:56:36 +00:00
|
|
|
if len(bz) == 0 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
return sdk.BigEndianToUint64(bz)
|
|
|
|
}
|
|
|
|
|
|
|
|
// IncreaseTxIndexTransient fetches the current EVM tx index from the transient store, increases its
|
|
|
|
// value by one and then sets the new index back to the transient store.
|
|
|
|
func (k Keeper) IncreaseTxIndexTransient() {
|
|
|
|
txIndex := k.GetTxIndexTransient()
|
2021-09-04 20:33:06 +00:00
|
|
|
k.SetTxIndexTransient(txIndex + 1)
|
2021-05-25 12:56:36 +00:00
|
|
|
}
|
|
|
|
|
2021-06-11 14:29:28 +00:00
|
|
|
// ResetRefundTransient resets the available refund amount to 0
|
2021-05-25 12:56:36 +00:00
|
|
|
func (k Keeper) ResetRefundTransient(ctx sdk.Context) {
|
|
|
|
store := ctx.TransientStore(k.transientKey)
|
2021-06-11 14:29:28 +00:00
|
|
|
store.Set(types.KeyPrefixTransientRefund, sdk.Uint64ToBigEndian(0))
|
2021-05-25 12:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Log
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2021-09-15 09:45:03 +00:00
|
|
|
// GetTxLogsTransient returns the current logs for a given transaction hash from the KVStore.
|
2021-05-25 12:56:36 +00:00
|
|
|
// This function returns an empty, non-nil slice if no logs are found.
|
2021-09-15 09:45:03 +00:00
|
|
|
func (k Keeper) GetTxLogsTransient(txHash common.Hash) []*ethtypes.Log {
|
|
|
|
store := prefix.NewStore(k.Ctx().TransientStore(k.transientKey), types.KeyPrefixTransientTxLogs)
|
2021-05-25 12:56:36 +00:00
|
|
|
|
2021-08-31 08:32:11 +00:00
|
|
|
// We store the logs with key equal to txHash.Bytes() | sdk.Uint64ToBigEndian(uint64(log.Index)),
|
|
|
|
// therefore, we set the end boundary(excluded) to txHash.Bytes() | uint64.Max -> []byte
|
2021-09-05 11:03:06 +00:00
|
|
|
end := txHash.Bytes()
|
2021-08-31 08:32:11 +00:00
|
|
|
end = append(end, []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}...)
|
2021-05-25 12:56:36 +00:00
|
|
|
|
2021-08-31 08:32:11 +00:00
|
|
|
iter := store.Iterator(txHash.Bytes(), end)
|
|
|
|
defer iter.Close()
|
2021-05-25 12:56:36 +00:00
|
|
|
|
2021-08-31 08:32:11 +00:00
|
|
|
logs := []*ethtypes.Log{}
|
|
|
|
for ; iter.Valid(); iter.Next() {
|
|
|
|
var log types.Log
|
|
|
|
k.cdc.MustUnmarshal(iter.Value(), &log)
|
|
|
|
logs = append(logs, log.ToEthereum())
|
|
|
|
}
|
|
|
|
|
|
|
|
return logs
|
2021-05-25 12:56:36 +00:00
|
|
|
}
|
|
|
|
|
2021-08-31 08:32:11 +00:00
|
|
|
// SetLog sets the log for a transaction in the KVStore.
|
2021-09-15 09:45:03 +00:00
|
|
|
func (k Keeper) AddLogTransient(log *ethtypes.Log) {
|
|
|
|
store := prefix.NewStore(k.Ctx().TransientStore(k.transientKey), types.KeyPrefixTransientTxLogs)
|
2021-08-31 08:32:11 +00:00
|
|
|
|
2021-09-05 11:03:06 +00:00
|
|
|
key := log.TxHash.Bytes()
|
2021-08-31 08:32:11 +00:00
|
|
|
key = append(key, sdk.Uint64ToBigEndian(uint64(log.Index))...)
|
|
|
|
|
|
|
|
txIndexLog := types.NewLogFromEth(log)
|
|
|
|
bz := k.cdc.MustMarshal(txIndexLog)
|
|
|
|
store.Set(key, bz)
|
2021-05-25 12:56:36 +00:00
|
|
|
}
|
|
|
|
|
2021-07-26 08:40:59 +00:00
|
|
|
// GetLogSizeTransient returns EVM log index on the current block.
|
|
|
|
func (k Keeper) GetLogSizeTransient() uint64 {
|
2021-08-10 07:22:46 +00:00
|
|
|
store := k.Ctx().TransientStore(k.transientKey)
|
2021-07-26 08:40:59 +00:00
|
|
|
bz := store.Get(types.KeyPrefixTransientLogSize)
|
|
|
|
if len(bz) == 0 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
return sdk.BigEndianToUint64(bz)
|
|
|
|
}
|
|
|
|
|
|
|
|
// IncreaseLogSizeTransient fetches the current EVM log index from the transient store, increases its
|
|
|
|
// value by one and then sets the new index back to the transient store.
|
|
|
|
func (k Keeper) IncreaseLogSizeTransient() {
|
|
|
|
logSize := k.GetLogSizeTransient()
|
2021-08-10 07:22:46 +00:00
|
|
|
store := k.Ctx().TransientStore(k.transientKey)
|
2021-07-26 08:40:59 +00:00
|
|
|
store.Set(types.KeyPrefixTransientLogSize, sdk.Uint64ToBigEndian(logSize+1))
|
|
|
|
}
|
|
|
|
|
2021-05-25 12:56:36 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Storage
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2020-08-23 21:41:54 +00:00
|
|
|
// GetAccountStorage return state storage associated with an account
|
|
|
|
func (k Keeper) GetAccountStorage(ctx sdk.Context, address common.Address) (types.Storage, error) {
|
|
|
|
storage := types.Storage{}
|
2021-01-06 20:56:40 +00:00
|
|
|
|
2021-05-25 12:56:36 +00:00
|
|
|
err := k.ForEachStorage(address, func(key, value common.Hash) bool {
|
2020-08-23 21:41:54 +00:00
|
|
|
storage = append(storage, types.NewState(key, value))
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return types.Storage{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return storage, nil
|
|
|
|
}
|
2020-09-02 19:41:05 +00:00
|
|
|
|
2021-05-25 12:56:36 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Account
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
func (k Keeper) DeleteState(addr common.Address, key common.Hash) {
|
2021-08-10 07:22:46 +00:00
|
|
|
store := prefix.NewStore(k.Ctx().KVStore(k.storeKey), types.AddressStoragePrefix(addr))
|
2021-05-25 12:56:36 +00:00
|
|
|
store.Delete(key.Bytes())
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteAccountStorage clears all the storage state associated with the given address.
|
|
|
|
func (k Keeper) DeleteAccountStorage(addr common.Address) {
|
|
|
|
_ = k.ForEachStorage(addr, func(key, _ common.Hash) bool {
|
|
|
|
k.DeleteState(addr, key)
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteCode removes the contract code byte array from the store associated with
|
|
|
|
// the given address.
|
|
|
|
func (k Keeper) DeleteCode(addr common.Address) {
|
|
|
|
hash := k.GetCodeHash(addr)
|
|
|
|
if bytes.Equal(hash.Bytes(), common.BytesToHash(types.EmptyCodeHash).Bytes()) {
|
|
|
|
return
|
2020-09-02 19:41:05 +00:00
|
|
|
}
|
|
|
|
|
2021-08-10 07:22:46 +00:00
|
|
|
store := prefix.NewStore(k.Ctx().KVStore(k.storeKey), types.KeyPrefixCode)
|
2021-05-25 12:56:36 +00:00
|
|
|
store.Delete(hash.Bytes())
|
2020-09-02 19:41:05 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 12:56:36 +00:00
|
|
|
// ClearBalance subtracts the EVM all the balance denomination from the address
|
|
|
|
// balance while also updating the total supply.
|
|
|
|
func (k Keeper) ClearBalance(addr sdk.AccAddress) (prevBalance sdk.Coin, err error) {
|
2021-08-10 07:22:46 +00:00
|
|
|
params := k.GetParams(k.Ctx())
|
2021-05-25 12:56:36 +00:00
|
|
|
|
2021-08-10 07:22:46 +00:00
|
|
|
prevBalance = k.bankKeeper.GetBalance(k.Ctx(), addr, params.EvmDenom)
|
2021-05-25 12:56:36 +00:00
|
|
|
if prevBalance.IsPositive() {
|
2021-08-10 07:22:46 +00:00
|
|
|
if err := k.bankKeeper.SendCoinsFromAccountToModule(k.Ctx(), addr, types.ModuleName, sdk.Coins{prevBalance}); err != nil {
|
2021-06-29 17:02:21 +00:00
|
|
|
return sdk.Coin{}, stacktrace.Propagate(err, "failed to transfer to module account")
|
|
|
|
}
|
|
|
|
|
2021-08-10 07:22:46 +00:00
|
|
|
if err := k.bankKeeper.BurnCoins(k.Ctx(), types.ModuleName, sdk.Coins{prevBalance}); err != nil {
|
2021-06-29 17:02:21 +00:00
|
|
|
return sdk.Coin{}, stacktrace.Propagate(err, "failed to burn coins from evm module account")
|
2021-05-25 12:56:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return prevBalance, nil
|
|
|
|
}
|
|
|
|
|
2021-07-26 08:15:59 +00:00
|
|
|
// ResetAccount removes the code, storage state, but keep all the native tokens stored
|
2021-05-25 12:56:36 +00:00
|
|
|
// with the given address.
|
|
|
|
func (k Keeper) ResetAccount(addr common.Address) {
|
|
|
|
k.DeleteCode(addr)
|
|
|
|
k.DeleteAccountStorage(addr)
|
2020-09-02 19:41:05 +00:00
|
|
|
}
|
2021-09-02 12:36:33 +00:00
|
|
|
|
|
|
|
// SetHooks sets the hooks for the EVM module
|
|
|
|
func (k *Keeper) SetHooks(eh types.EvmHooks) *Keeper {
|
|
|
|
if k.hooks != nil {
|
|
|
|
panic("cannot set evm hooks twice")
|
|
|
|
}
|
|
|
|
|
|
|
|
k.hooks = eh
|
|
|
|
return k
|
|
|
|
}
|
|
|
|
|
|
|
|
// PostTxProcessing delegate the call to the hooks. If no hook has been registered, this function returns with a `nil` error
|
|
|
|
func (k *Keeper) PostTxProcessing(txHash common.Hash, logs []*ethtypes.Log) error {
|
|
|
|
if k.hooks == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return k.hooks.PostTxProcessing(k.Ctx(), txHash, logs)
|
|
|
|
}
|