@@ -11,19 +11,41 @@ import (
1111
1212 evmtypes "github.com/evmos/ethermint/x/evm/types"
1313
14+ "github.com/ethereum/go-ethereum/common"
1415 "github.com/ethereum/go-ethereum/core"
1516 ethtypes "github.com/ethereum/go-ethereum/core/types"
1617)
1718
18- // DeductTxCostsFromUserBalance it calculates the tx costs and deducts the fees
19- func (k Keeper ) DeductTxCostsFromUserBalance (
19+ // DeductTxCostsFromUserBalance deducts the fees from the user balance. Returns an
20+ // error if the specified sender address does not exist or the account balance is not sufficient.
21+ func (k * Keeper ) DeductTxCostsFromUserBalance (
2022 ctx sdk.Context ,
21- msgEthTx evmtypes.MsgEthereumTx ,
23+ fees sdk.Coins ,
24+ from common.Address ,
25+ ) error {
26+ // fetch sender account
27+ signerAcc , err := authante .GetSignerAcc (ctx , k .accountKeeper , from .Bytes ())
28+ if err != nil {
29+ return errorsmod .Wrapf (err , "account not found for sender %s" , from )
30+ }
31+
32+ // deduct the full gas cost from the user balance
33+ if err := authante .DeductFees (k .bankKeeper , ctx , signerAcc , fees ); err != nil {
34+ return errorsmod .Wrapf (err , "failed to deduct full gas cost %s from the user %s balance" , fees , from )
35+ }
36+
37+ return nil
38+ }
39+
40+ // VerifyFee is used to return the fee for the given transaction data in sdk.Coins. It checks that the
41+ // gas limit is not reached, the gas limit is higher than the intrinsic gas and that the
42+ // base fee is higher than the gas fee cap.
43+ func VerifyFee (
2244 txData evmtypes.TxData ,
2345 denom string ,
2446 baseFee * big.Int ,
25- homestead , istanbul , london bool ,
26- ) (fees sdk.Coins , err error ) {
47+ homestead , istanbul , isCheckTx bool ,
48+ ) (sdk.Coins , error ) {
2749 isContractCreation := txData .GetTo () == nil
2850
2951 gasLimit := txData .GetGas ()
@@ -43,7 +65,7 @@ func (k Keeper) DeductTxCostsFromUserBalance(
4365 }
4466
4567 // intrinsic gas verification during CheckTx
46- if ctx . IsCheckTx () && gasLimit < intrinsicGas {
68+ if isCheckTx && gasLimit < intrinsicGas {
4769 return nil , errorsmod .Wrapf (
4870 errortypes .ErrOutOfGas ,
4971 "gas limit too low: %d (gas limit) < %d (intrinsic gas)" , gasLimit , intrinsicGas ,
@@ -63,24 +85,7 @@ func (k Keeper) DeductTxCostsFromUserBalance(
6385 return sdk.Coins {}, nil
6486 }
6587
66- fees = sdk.Coins {{Denom : denom , Amount : sdkmath .NewIntFromBigInt (feeAmt )}}
67-
68- // fetch sender account from signature
69- signerAcc , err := authante .GetSignerAcc (ctx , k .accountKeeper , msgEthTx .GetFrom ())
70- if err != nil {
71- return nil , errorsmod .Wrapf (err , "account not found for sender %s" , msgEthTx .From )
72- }
73-
74- // deduct the full gas cost from the user balance
75- if err := authante .DeductFees (k .bankKeeper , ctx , signerAcc , fees ); err != nil {
76- return nil , errorsmod .Wrapf (
77- err ,
78- "failed to deduct full gas cost %s from the user %s balance" ,
79- fees , msgEthTx .From ,
80- )
81- }
82-
83- return fees , nil
88+ return sdk.Coins {{Denom : denom , Amount : sdkmath .NewIntFromBigInt (feeAmt )}}, nil
8489}
8590
8691// CheckSenderBalance validates that the tx cost value is positive and that the
0 commit comments