Skip to content

Commit

Permalink
docs: demonstrate how to wire custom ante handlers in 0.50 app_di (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Sep 17, 2024
1 parent b21441c commit 3feb2c0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
6 changes: 4 additions & 2 deletions simapp/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,10 @@ var (
Config: appconfig.WrapAny(&paramsmodulev1.Module{}),
},
{
Name: "tx",
Config: appconfig.WrapAny(&txconfigv1.Config{}),
Name: "tx",
Config: appconfig.WrapAny(&txconfigv1.Config{
SkipAnteHandler: true, // Enable this to skip the default antehandlers and set custom ante handlers.
}),
},
{
Name: genutiltypes.ModuleName,
Expand Down
31 changes: 29 additions & 2 deletions simapp/app_v2.go → simapp/app_di.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
testdata_pulsar "github.com/cosmos/cosmos-sdk/testutil/testdata/testpb"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand Down Expand Up @@ -81,7 +82,7 @@ type SimApp struct {
GroupKeeper groupkeeper.Keeper
NFTKeeper nftkeeper.Keeper
ConsensusParamsKeeper consensuskeeper.Keeper
CircuitBreakerKeeper circuitkeeper.Keeper
CircuitKeeper circuitkeeper.Keeper

// simulation manager
sm *module.SimulationManager
Expand Down Expand Up @@ -182,7 +183,7 @@ func NewSimApp(
&app.GroupKeeper,
&app.NFTKeeper,
&app.ConsensusParamsKeeper,
&app.CircuitBreakerKeeper,
&app.CircuitKeeper,
); err != nil {
panic(err)
}
Expand Down Expand Up @@ -248,6 +249,9 @@ func NewSimApp(

app.sm.RegisterStoreDecoders()

// set custom ante handler
app.setAnteHandler(app.txConfig)

// A custom InitChainer can be set if extra pre-init-genesis logic is required.
// By default, when using app wiring enabled module, this is not required.
// For instance, the upgrade module will set automatically the module version map in its init genesis thanks to app wiring.
Expand All @@ -266,6 +270,29 @@ func NewSimApp(
return app
}

// setAnteHandler sets custom ante handlers.
// "x/auth/tx" pre-defined ante handler have been disabled in app_config.
func (app *SimApp) setAnteHandler(txConfig client.TxConfig) {
anteHandler, err := NewAnteHandler(
HandlerOptions{
ante.HandlerOptions{
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
SignModeHandler: txConfig.SignModeHandler(),
FeegrantKeeper: app.FeeGrantKeeper,
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
},
&app.CircuitKeeper,
},
)
if err != nil {
panic(err)
}

// Set the AnteHandler for the app
app.SetAnteHandler(anteHandler)
}

// LegacyAmino returns SimApp's amino codec.
//
// NOTE: This is solely to be used for testing purposes as it may be desirable
Expand Down
File renamed without changes.

0 comments on commit 3feb2c0

Please sign in to comment.