github.com/Finschia/finschia-sdk@v0.49.1/x/auth/ante/ante.go (about)

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