2020-12-02 17:37:11 +00:00
|
|
|
package ante
|
|
|
|
|
|
|
|
import (
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2022-01-08 00:39:27 +00:00
|
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
2020-12-02 17:37:11 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth/ante"
|
2022-01-08 00:39:27 +00:00
|
|
|
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
|
2020-12-02 17:37:11 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
2022-01-08 00:39:27 +00:00
|
|
|
|
|
|
|
channelkeeper "github.com/cosmos/ibc-go/modules/core/04-channel/keeper"
|
|
|
|
ibcante "github.com/cosmos/ibc-go/modules/core/ante"
|
2020-12-02 17:37:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// NewAnteHandler returns an 'AnteHandler' that will run actions before a tx is sent to a module's handler.
|
2022-01-08 00:39:27 +00:00
|
|
|
func NewAnteHandler(
|
|
|
|
accountKeeper ante.AccountKeeper,
|
|
|
|
bankKeeper types.BankKeeper,
|
|
|
|
feegrantKeeper ante.FeegrantKeeper,
|
|
|
|
ibcChannelKeeper channelkeeper.Keeper,
|
|
|
|
signModeHandler authsigning.SignModeHandler, sigGasConsumer ante.SignatureVerificationGasConsumer, addressFetchers ...AddressFetcher) (sdk.AnteHandler, error) {
|
|
|
|
if accountKeeper == nil {
|
|
|
|
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder")
|
|
|
|
}
|
|
|
|
|
|
|
|
if bankKeeper == nil {
|
|
|
|
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder")
|
|
|
|
}
|
|
|
|
|
|
|
|
if signModeHandler == nil {
|
|
|
|
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
|
|
|
|
}
|
|
|
|
|
|
|
|
if sigGasConsumer == nil {
|
|
|
|
sigGasConsumer = ante.DefaultSigVerificationGasConsumer
|
|
|
|
}
|
2020-12-02 17:37:11 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
decorators := []sdk.AnteDecorator{}
|
2020-12-02 17:37:11 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
decorators = append(decorators,
|
|
|
|
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
|
|
|
|
ante.NewRejectExtensionOptionsDecorator(),
|
|
|
|
)
|
2020-12-02 17:37:11 +00:00
|
|
|
if len(addressFetchers) > 0 {
|
|
|
|
decorators = append(decorators, NewAuthenticatedMempoolDecorator(addressFetchers...))
|
|
|
|
}
|
|
|
|
decorators = append(decorators,
|
|
|
|
ante.NewMempoolFeeDecorator(),
|
2022-01-08 00:39:27 +00:00
|
|
|
NewVestingAccountDecorator(),
|
2020-12-02 17:37:11 +00:00
|
|
|
ante.NewValidateBasicDecorator(),
|
2022-01-08 00:39:27 +00:00
|
|
|
ante.NewTxTimeoutHeightDecorator(),
|
|
|
|
ante.NewValidateMemoDecorator(accountKeeper),
|
|
|
|
ante.NewConsumeGasForTxSizeDecorator(accountKeeper),
|
|
|
|
ante.NewDeductFeeDecorator(accountKeeper, bankKeeper, feegrantKeeper),
|
|
|
|
ante.NewSetPubKeyDecorator(accountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
|
|
|
|
ante.NewValidateSigCountDecorator(accountKeeper),
|
|
|
|
ante.NewSigGasConsumeDecorator(accountKeeper, sigGasConsumer),
|
|
|
|
ante.NewSigVerificationDecorator(accountKeeper, signModeHandler),
|
|
|
|
ante.NewIncrementSequenceDecorator(accountKeeper), // innermost AnteDecorator
|
|
|
|
ibcante.NewAnteDecorator(ibcChannelKeeper),
|
2020-12-02 17:37:11 +00:00
|
|
|
)
|
2022-01-08 00:39:27 +00:00
|
|
|
return sdk.ChainAnteDecorators(decorators...), nil
|
2020-12-02 17:37:11 +00:00
|
|
|
}
|