diff --git a/x/evm/keeper/grpc_query.go b/x/evm/keeper/grpc_query.go index fd71412a1..b96cd5ddb 100644 --- a/x/evm/keeper/grpc_query.go +++ b/x/evm/keeper/grpc_query.go @@ -64,7 +64,10 @@ func (k Keeper) EthAccount( } ctx := sdk.UnwrapSDKContext(goCtx) - acct := k.GetAccountOrEmpty(ctx, addrEth) + acct := k.getAccountWithoutBalance(ctx, addrEth) + if acct == nil { + return nil, fmt.Errorf("account not found for %s", addrEth.Hex()) + } balNative := k.Bank.GetBalance(ctx, addrBech32, evm.EVMBankDenom).Amount.BigInt() return &evm.QueryEthAccountResponse{ @@ -205,7 +208,7 @@ func (k Keeper) Code( ctx := sdk.UnwrapSDKContext(goCtx) address := gethcommon.HexToAddress(req.Address) - acct := k.GetAccountWithoutBalance(ctx, address) + acct := k.getAccountWithoutBalance(ctx, address) var code []byte if acct != nil && acct.IsContract() { diff --git a/x/evm/keeper/statedb.go b/x/evm/keeper/statedb.go index b85a595a5..f46c491e6 100644 --- a/x/evm/keeper/statedb.go +++ b/x/evm/keeper/statedb.go @@ -25,7 +25,7 @@ var _ statedb.Keeper = &Keeper{} // Implements the `statedb.Keeper` interface. // Returns nil if the account does not exist or has the wrong type. func (k *Keeper) GetAccount(ctx sdk.Context, addr gethcommon.Address) *statedb.Account { - acct := k.GetAccountWithoutBalance(ctx, addr) + acct := k.getAccountWithoutBalance(ctx, addr) if acct == nil { return nil } @@ -184,11 +184,10 @@ func (k *Keeper) DeleteAccount(ctx sdk.Context, addr gethcommon.Address) error { return nil } -// GetAccountWithoutBalance load nonce and codehash without balance, +// getAccountWithoutBalance load nonce and codehash without balance, // more efficient in cases where balance is not needed. -func (k *Keeper) GetAccountWithoutBalance(ctx sdk.Context, addr gethcommon.Address) *statedb.Account { - nibiruAddr := sdk.AccAddress(addr.Bytes()) - acct := k.accountKeeper.GetAccount(ctx, nibiruAddr) +func (k *Keeper) getAccountWithoutBalance(ctx sdk.Context, addr gethcommon.Address) *statedb.Account { + acct := k.accountKeeper.GetAccount(ctx, eth.EthAddrToNibiruAddr(addr)) if acct == nil { return nil } @@ -204,19 +203,3 @@ func (k *Keeper) GetAccountWithoutBalance(ctx sdk.Context, addr gethcommon.Addre CodeHash: codeHash, } } - -// GetAccountOrEmpty returns empty account if not exist, returns error if it's not `EthAccount` -func (k *Keeper) GetAccountOrEmpty( - ctx sdk.Context, addr gethcommon.Address, -) statedb.Account { - acct := k.GetAccount(ctx, addr) - if acct != nil { - return *acct - } - - // empty account - return statedb.Account{ - BalanceNative: new(big.Int), - CodeHash: evm.EmptyCodeHash, - } -}