evm: improve error message for invalid account (#883)
* evm: improve error message for invalid account * fix
This commit is contained in:
parent
8eaffe88a5
commit
eea80d50c3
@ -1,12 +1,12 @@
|
|||||||
package keeper
|
package keeper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
"github.com/cosmos/cosmos-sdk/store/prefix"
|
"github.com/cosmos/cosmos-sdk/store/prefix"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"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)
|
ethAcct, ok := acct.(*ethermint.EthAccount)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("not EthAccount")
|
return nil, sdkerrors.Wrapf(types.ErrInvalidAccount, "type %T, address %s", acct, addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &statedb.Account{
|
return &statedb.Account{
|
||||||
|
@ -2,12 +2,12 @@ package keeper
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/store/prefix"
|
"github.com/cosmos/cosmos-sdk/store/prefix"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
ethermint "github.com/tharsis/ethermint/types"
|
ethermint "github.com/tharsis/ethermint/types"
|
||||||
"github.com/tharsis/ethermint/x/evm/statedb"
|
"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)
|
ethAcct, ok := acct.(*ethermint.EthAccount)
|
||||||
if !ok {
|
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 {
|
if err := ethAcct.SetSequence(account.Nonce); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -179,7 +179,7 @@ func (k *Keeper) DeleteAccount(ctx sdk.Context, addr common.Address) error {
|
|||||||
|
|
||||||
ethAcct, ok := acct.(*ethermint.EthAccount)
|
ethAcct, ok := acct.(*ethermint.EthAccount)
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("not EthAccount")
|
return sdkerrors.Wrapf(types.ErrInvalidAccount, "type %T, address %s", acct, addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear balance
|
// clear balance
|
||||||
@ -194,7 +194,7 @@ func (k *Keeper) DeleteAccount(ctx sdk.Context, addr common.Address) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// clear storage
|
// 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)
|
k.SetState(ctx, addr, key, nil)
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
@ -32,6 +32,7 @@ const (
|
|||||||
codeErrInvalidGasCap
|
codeErrInvalidGasCap
|
||||||
codeErrInvalidBaseFee
|
codeErrInvalidBaseFee
|
||||||
codeErrGasOverflow
|
codeErrGasOverflow
|
||||||
|
codeErrInvalidAccount
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrPostTxProcessing = errors.New("failed to execute post processing")
|
var ErrPostTxProcessing = errors.New("failed to execute post processing")
|
||||||
@ -93,6 +94,9 @@ var (
|
|||||||
|
|
||||||
// ErrGasOverflow returns an error if gas computation overlow/underflow
|
// ErrGasOverflow returns an error if gas computation overlow/underflow
|
||||||
ErrGasOverflow = sdkerrors.Register(ModuleName, codeErrGasOverflow, "gas computation overflow/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
|
// NewExecErrorWithReason unpacks the revert return bytes and returns a wrapped error
|
||||||
|
Loading…
Reference in New Issue
Block a user