-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
4,540 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package ante | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/cosmos/cosmos-sdk/types/tx/signing" | ||
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" | ||
"github.com/cosmos/cosmos-sdk/x/auth/types" | ||
) | ||
|
||
// HandlerOptions are the options required for constructing a default SDK AnteHandler. | ||
type HandlerOptions struct { | ||
AccountKeeper AccountKeeper | ||
BankKeeper types.BankKeeper | ||
ExtensionOptionChecker ExtensionOptionChecker | ||
FeegrantKeeper FeegrantKeeper | ||
SignModeHandler authsigning.SignModeHandler | ||
SigGasConsumer func(meter sdk.GasMeter, sig signing.SignatureV2, params types.Params) error | ||
TxFeeChecker TxFeeChecker | ||
} | ||
|
||
// NewAnteHandler returns an AnteHandler that checks and increments sequence | ||
// numbers, checks signatures & account numbers, and deducts fees from the first | ||
// signer. | ||
func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { | ||
if options.AccountKeeper == nil { | ||
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder") | ||
} | ||
|
||
if options.BankKeeper == nil { | ||
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder") | ||
} | ||
|
||
if options.SignModeHandler == nil { | ||
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") | ||
} | ||
|
||
anteDecorators := []sdk.AnteDecorator{ | ||
NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first | ||
NewExtensionOptionsDecorator(options.ExtensionOptionChecker), | ||
NewValidateBasicDecorator(), | ||
NewTxTimeoutHeightDecorator(), | ||
NewValidateMemoDecorator(options.AccountKeeper), | ||
NewConsumeGasForTxSizeDecorator(options.AccountKeeper), | ||
NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker), | ||
NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators | ||
NewValidateSigCountDecorator(options.AccountKeeper), | ||
NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer), | ||
NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler), | ||
NewIncrementSequenceDecorator(options.AccountKeeper), | ||
} | ||
|
||
return sdk.ChainAnteDecorators(anteDecorators...), nil | ||
} |
Oops, something went wrong.