-
Notifications
You must be signed in to change notification settings - Fork 1
/
fee_decorator.go
39 lines (32 loc) · 1.09 KB
/
fee_decorator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
type MinFeeDecorator struct {
feesKeeper Keeper
}
func NewMinFeeDecorator(feesKeeper Keeper) MinFeeDecorator {
return MinFeeDecorator{
feesKeeper: feesKeeper,
}
}
func (mfd MinFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
// All transactions must be of type feeTx
feeTx, ok := tx.(sdk.FeeTx)
if !ok {
return newCtx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
}
// Skip block with height 0 since this handler will be called before the fee params are initialized,
// which would cause a panic when trying to start the chain
// TODO: When there is a better params handling, remove this and simply rely on empty params instead
if ctx.BlockHeight() == 0 {
return next(ctx, tx, simulate)
}
// Check the minimum fees of the transaction
err = mfd.feesKeeper.CheckFees(ctx, feeTx.GetMsgs(), feeTx.GetFee())
if err != nil {
return ctx, err
}
return next(ctx, tx, simulate)
}