github.com/cosmos/cosmos-sdk@v0.50.10/x/auth/ante/ante.go (about)

     1  package ante
     2  
     3  import (
     4  	errorsmod "cosmossdk.io/errors"
     5  	storetypes "cosmossdk.io/store/types"
     6  	txsigning "cosmossdk.io/x/tx/signing"
     7  
     8  	sdk "github.com/cosmos/cosmos-sdk/types"
     9  	sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
    10  	"github.com/cosmos/cosmos-sdk/types/tx/signing"
    11  	"github.com/cosmos/cosmos-sdk/x/auth/types"
    12  )
    13  
    14  // HandlerOptions are the options required for constructing a default SDK AnteHandler.
    15  type HandlerOptions struct {
    16  	AccountKeeper          AccountKeeper
    17  	BankKeeper             types.BankKeeper
    18  	ExtensionOptionChecker ExtensionOptionChecker
    19  	FeegrantKeeper         FeegrantKeeper
    20  	SignModeHandler        *txsigning.HandlerMap
    21  	SigGasConsumer         func(meter storetypes.GasMeter, sig signing.SignatureV2, params types.Params) error
    22  	TxFeeChecker           TxFeeChecker
    23  }
    24  
    25  // NewAnteHandler returns an AnteHandler that checks and increments sequence
    26  // numbers, checks signatures & account numbers, and deducts fees from the first
    27  // signer.
    28  func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
    29  	if options.AccountKeeper == nil {
    30  		return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder")
    31  	}
    32  
    33  	if options.BankKeeper == nil {
    34  		return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder")
    35  	}
    36  
    37  	if options.SignModeHandler == nil {
    38  		return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
    39  	}
    40  
    41  	anteDecorators := []sdk.AnteDecorator{
    42  		NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
    43  		NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
    44  		NewValidateBasicDecorator(),
    45  		NewTxTimeoutHeightDecorator(),
    46  		NewValidateMemoDecorator(options.AccountKeeper),
    47  		NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
    48  		NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
    49  		NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
    50  		NewValidateSigCountDecorator(options.AccountKeeper),
    51  		NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
    52  		NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
    53  		NewIncrementSequenceDecorator(options.AccountKeeper),
    54  	}
    55  
    56  	return sdk.ChainAnteDecorators(anteDecorators...), nil
    57  }