Skip to content

Commit ec91c10

Browse files
julienrbrtGNaD13
authored andcommitted
docs: demonstrate how to wire custom ante handlers in 0.50 app_di (cosmos#21767)
1 parent 46bf94d commit ec91c10

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

simapp/app_config.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,10 @@ var (
202202
Config: appconfig.WrapAny(&paramsmodulev1.Module{}),
203203
},
204204
{
205-
Name: "tx",
206-
Config: appconfig.WrapAny(&txconfigv1.Config{}),
205+
Name: "tx",
206+
Config: appconfig.WrapAny(&txconfigv1.Config{
207+
SkipAnteHandler: true, // Enable this to skip the default antehandlers and set custom ante handlers.
208+
}),
207209
},
208210
{
209211
Name: genutiltypes.ModuleName,

simapp/app_v2.go renamed to simapp/app_di.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
testdata_pulsar "github.com/cosmos/cosmos-sdk/testutil/testdata/testpb"
3030
"github.com/cosmos/cosmos-sdk/types/module"
3131
"github.com/cosmos/cosmos-sdk/x/auth"
32+
"github.com/cosmos/cosmos-sdk/x/auth/ante"
3233
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
3334
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
3435
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
@@ -81,7 +82,7 @@ type SimApp struct {
8182
GroupKeeper groupkeeper.Keeper
8283
NFTKeeper nftkeeper.Keeper
8384
ConsensusParamsKeeper consensuskeeper.Keeper
84-
CircuitBreakerKeeper circuitkeeper.Keeper
85+
CircuitKeeper circuitkeeper.Keeper
8586

8687
// simulation manager
8788
sm *module.SimulationManager
@@ -182,7 +183,7 @@ func NewSimApp(
182183
&app.GroupKeeper,
183184
&app.NFTKeeper,
184185
&app.ConsensusParamsKeeper,
185-
&app.CircuitBreakerKeeper,
186+
&app.CircuitKeeper,
186187
); err != nil {
187188
panic(err)
188189
}
@@ -248,6 +249,9 @@ func NewSimApp(
248249

249250
app.sm.RegisterStoreDecoders()
250251

252+
// set custom ante handler
253+
app.setAnteHandler(app.txConfig)
254+
251255
// A custom InitChainer can be set if extra pre-init-genesis logic is required.
252256
// By default, when using app wiring enabled module, this is not required.
253257
// For instance, the upgrade module will set automatically the module version map in its init genesis thanks to app wiring.
@@ -266,6 +270,29 @@ func NewSimApp(
266270
return app
267271
}
268272

273+
// setAnteHandler sets custom ante handlers.
274+
// "x/auth/tx" pre-defined ante handler have been disabled in app_config.
275+
func (app *SimApp) setAnteHandler(txConfig client.TxConfig) {
276+
anteHandler, err := NewAnteHandler(
277+
HandlerOptions{
278+
ante.HandlerOptions{
279+
AccountKeeper: app.AccountKeeper,
280+
BankKeeper: app.BankKeeper,
281+
SignModeHandler: txConfig.SignModeHandler(),
282+
FeegrantKeeper: app.FeeGrantKeeper,
283+
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
284+
},
285+
&app.CircuitKeeper,
286+
},
287+
)
288+
if err != nil {
289+
panic(err)
290+
}
291+
292+
// Set the AnteHandler for the app
293+
app.SetAnteHandler(anteHandler)
294+
}
295+
269296
// LegacyAmino returns SimApp's amino codec.
270297
//
271298
// NOTE: This is solely to be used for testing purposes as it may be desirable

0 commit comments

Comments
 (0)