-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into terpay/update-fee-market
- Loading branch information
Showing
3 changed files
with
96 additions
and
0 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,48 @@ | ||
package simapp | ||
|
||
import ( | ||
errorsmod "cosmossdk.io/errors" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
authante "github.com/cosmos/cosmos-sdk/x/auth/ante" | ||
) | ||
|
||
// HandlerOptions are the options required for constructing an SDK AnteHandler with the fee market injected. | ||
type HandlerOptions struct { | ||
BaseOptions authante.HandlerOptions | ||
} | ||
|
||
// 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.BaseOptions.AccountKeeper == nil { | ||
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder") | ||
} | ||
|
||
if options.BaseOptions.BankKeeper == nil { | ||
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder") | ||
} | ||
|
||
if options.BaseOptions.SignModeHandler == nil { | ||
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") | ||
} | ||
|
||
anteDecorators := []sdk.AnteDecorator{ | ||
authante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first | ||
authante.NewExtensionOptionsDecorator(options.BaseOptions.ExtensionOptionChecker), | ||
authante.NewValidateBasicDecorator(), | ||
authante.NewTxTimeoutHeightDecorator(), | ||
authante.NewValidateMemoDecorator(options.BaseOptions.AccountKeeper), | ||
authante.NewConsumeGasForTxSizeDecorator(options.BaseOptions.AccountKeeper), | ||
authante.NewDeductFeeDecorator(options.BaseOptions.AccountKeeper, options.BaseOptions.BankKeeper, options.BaseOptions.FeegrantKeeper, options.BaseOptions.TxFeeChecker), | ||
authante.NewSetPubKeyDecorator(options.BaseOptions.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators | ||
authante.NewValidateSigCountDecorator(options.BaseOptions.AccountKeeper), | ||
authante.NewSigGasConsumeDecorator(options.BaseOptions.AccountKeeper, options.BaseOptions.SigGasConsumer), | ||
authante.NewSigVerificationDecorator(options.BaseOptions.AccountKeeper, options.BaseOptions.SignModeHandler), | ||
authante.NewIncrementSequenceDecorator(options.BaseOptions.AccountKeeper), | ||
} | ||
|
||
return sdk.ChainAnteDecorators(anteDecorators...), nil | ||
} |
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
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,27 @@ | ||
package ante | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/auth/types" | ||
) | ||
|
||
// AccountKeeper defines the contract needed for AccountKeeper related APIs. | ||
// Interface provides support to use non-sdk AccountKeeper for AnteHandler's decorators. | ||
type AccountKeeper interface { | ||
GetParams(ctx sdk.Context) (params types.Params) | ||
GetAccount(ctx sdk.Context, addr sdk.AccAddress) types.AccountI | ||
SetAccount(ctx sdk.Context, acc types.AccountI) | ||
GetModuleAddress(moduleName string) sdk.AccAddress | ||
} | ||
|
||
// FeegrantKeeper defines the expected feegrant keeper. | ||
type FeegrantKeeper interface { | ||
UseGrantedFees(ctx sdk.Context, granter, grantee sdk.AccAddress, fee sdk.Coins, msgs []sdk.Msg) error | ||
} | ||
|
||
// BankKeeper defines the contract needed for supply related APIs (noalias) | ||
type BankKeeper interface { | ||
IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) error | ||
SendCoins(ctx sdk.Context, from, to sdk.AccAddress, amt sdk.Coins) error | ||
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error | ||
} |