mirror of https://github.com/certusone/wasmd.git
68 lines
2.7 KiB
Go
68 lines
2.7 KiB
Go
package app
|
|
|
|
import (
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
"github.com/cosmos/cosmos-sdk/x/auth/ante"
|
|
channelkeeper "github.com/cosmos/ibc-go/v2/modules/core/04-channel/keeper"
|
|
ibcante "github.com/cosmos/ibc-go/v2/modules/core/ante"
|
|
|
|
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
|
|
wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types"
|
|
)
|
|
|
|
// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
|
|
// channel keeper.
|
|
type HandlerOptions struct {
|
|
ante.HandlerOptions
|
|
|
|
IBCChannelkeeper channelkeeper.Keeper
|
|
WasmConfig *wasmTypes.WasmConfig
|
|
TXCounterStoreKey sdk.StoreKey
|
|
}
|
|
|
|
func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
|
|
if options.AccountKeeper == nil {
|
|
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
|
|
}
|
|
if options.BankKeeper == nil {
|
|
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
|
|
}
|
|
if options.SignModeHandler == nil {
|
|
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
|
|
}
|
|
if options.WasmConfig == nil {
|
|
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "wasm config is required for ante builder")
|
|
}
|
|
if options.TXCounterStoreKey == nil {
|
|
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "tx counter key is required for ante builder")
|
|
}
|
|
|
|
var sigGasConsumer = options.SigGasConsumer
|
|
if sigGasConsumer == nil {
|
|
sigGasConsumer = ante.DefaultSigVerificationGasConsumer
|
|
}
|
|
|
|
anteDecorators := []sdk.AnteDecorator{
|
|
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
|
|
wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit), // after setup context to enforce limits early
|
|
wasmkeeper.NewCountTXDecorator(options.TXCounterStoreKey),
|
|
ante.NewRejectExtensionOptionsDecorator(),
|
|
ante.NewMempoolFeeDecorator(),
|
|
ante.NewValidateBasicDecorator(),
|
|
ante.NewTxTimeoutHeightDecorator(),
|
|
ante.NewValidateMemoDecorator(options.AccountKeeper),
|
|
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
|
|
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper),
|
|
// SetPubKeyDecorator must be called before all signature verification decorators
|
|
ante.NewSetPubKeyDecorator(options.AccountKeeper),
|
|
ante.NewValidateSigCountDecorator(options.AccountKeeper),
|
|
ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer),
|
|
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
|
|
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
|
|
ibcante.NewAnteDecorator(options.IBCChannelkeeper),
|
|
}
|
|
|
|
return sdk.ChainAnteDecorators(anteDecorators...), nil
|
|
}
|