Skip to content

Commit

Permalink
Compute feeRequired base on gasPrice and gasRemaining
Browse files Browse the repository at this point in the history
  • Loading branch information
phamminh0811 committed Jul 16, 2024
1 parent d57e4ce commit 3c9b03a
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions x/tax2gas/post/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,19 @@ func (dd Tax2gasPostDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simulate b

// Deduct the gas consumed amount spent on ante handler
gasRemaining := gasConsumed - anteConsumedGas
gasRemainingFees, err := tax2gasutils.ComputeFeesOnGasConsumed(ctx, tx, gasPrices, gasRemaining)
if err != nil {
return ctx, err
}

if simulate {
return next(ctx, tx, simulate, success)
}

for _, feeCoin := range feeCoins {
found, feeRequired := gasRemainingFees.Find(feeCoin.Denom)
feePayer := dd.accountKeeper.GetAccount(ctx, feeTx.FeePayer())
gasPrice, found := tax2gasutils.GetGasPriceByDenom(ctx, gasPrices, feeCoin.Denom)
if !found {
continue
}

feePayer := dd.accountKeeper.GetAccount(ctx, feeTx.FeePayer())
feeRequired := sdk.NewCoin(feeCoin.Denom, gasPrice.MulInt64(int64(gasRemaining)).Ceil().RoundInt())

Check failure on line 85 in x/tax2gas/post/post.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)
if feeCoin.IsGTE(feeRequired) {
err := dd.bankKeeper.SendCoinsFromAccountToModule(ctx, feePayer.GetAddress(), authtypes.FeeCollectorName, sdk.NewCoins(feeRequired))
if err != nil {
Expand All @@ -94,11 +91,6 @@ func (dd Tax2gasPostDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simulate b
gasRemaining = 0
break
} else {
gasPrice, found := tax2gasutils.GetGasPriceByDenom(ctx, gasPrices, feeCoin.Denom)
if !found {
continue
}

err := dd.bankKeeper.SendCoinsFromAccountToModule(ctx, feePayer.GetAddress(), authtypes.FeeCollectorName, sdk.NewCoins(feeCoin))
if err != nil {
return ctx, errorsmod.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error())
Expand Down

0 comments on commit 3c9b03a

Please sign in to comment.