diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go index 85fabac8..c2f87221 100644 --- a/x/evm/keeper/keeper.go +++ b/x/evm/keeper/keeper.go @@ -1,12 +1,12 @@ package keeper import ( - "errors" "math/big" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" @@ -244,7 +244,7 @@ func (k *Keeper) GetAccountWithoutBalance(ctx sdk.Context, addr common.Address) ethAcct, ok := acct.(*ethermint.EthAccount) if !ok { - return nil, errors.New("not EthAccount") + return nil, sdkerrors.Wrapf(types.ErrInvalidAccount, "type %T, address %s", acct, addr) } return &statedb.Account{ diff --git a/x/evm/keeper/statedb.go b/x/evm/keeper/statedb.go index ae908057..bf0aa0a9 100644 --- a/x/evm/keeper/statedb.go +++ b/x/evm/keeper/statedb.go @@ -2,12 +2,12 @@ package keeper import ( "bytes" - "errors" "fmt" "math/big" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/ethereum/go-ethereum/common" ethermint "github.com/tharsis/ethermint/types" "github.com/tharsis/ethermint/x/evm/statedb" @@ -111,7 +111,7 @@ func (k *Keeper) SetAccount(ctx sdk.Context, addr common.Address, account stated } ethAcct, ok := acct.(*ethermint.EthAccount) if !ok { - return errors.New("not EthAccount") + return sdkerrors.Wrapf(types.ErrInvalidAccount, "type %T, address %s", acct, addr) } if err := ethAcct.SetSequence(account.Nonce); err != nil { return err @@ -179,7 +179,7 @@ func (k *Keeper) DeleteAccount(ctx sdk.Context, addr common.Address) error { ethAcct, ok := acct.(*ethermint.EthAccount) if !ok { - return errors.New("not EthAccount") + return sdkerrors.Wrapf(types.ErrInvalidAccount, "type %T, address %s", acct, addr) } // clear balance @@ -194,7 +194,7 @@ func (k *Keeper) DeleteAccount(ctx sdk.Context, addr common.Address) error { } // clear storage - k.ForEachStorage(ctx, addr, func(key, value common.Hash) bool { + k.ForEachStorage(ctx, addr, func(key, _ common.Hash) bool { k.SetState(ctx, addr, key, nil) return true }) diff --git a/x/evm/types/errors.go b/x/evm/types/errors.go index 811f506d..4d6d1250 100644 --- a/x/evm/types/errors.go +++ b/x/evm/types/errors.go @@ -32,6 +32,7 @@ const ( codeErrInvalidGasCap codeErrInvalidBaseFee codeErrGasOverflow + codeErrInvalidAccount ) var ErrPostTxProcessing = errors.New("failed to execute post processing") @@ -93,6 +94,9 @@ var ( // ErrGasOverflow returns an error if gas computation overlow/underflow ErrGasOverflow = sdkerrors.Register(ModuleName, codeErrGasOverflow, "gas computation overflow/underflow") + + // ErrInvalidAccount returns an error if the account is not an EVM compatible account + ErrInvalidAccount = sdkerrors.Register(ModuleName, codeErrInvalidAccount, "account type is not a valid ethereum account") ) // NewExecErrorWithReason unpacks the revert return bytes and returns a wrapped error