Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add instructions to change DefaultGenesis #21680

Merged
merged 12 commits into from
Oct 1, 2024
54 changes: 54 additions & 0 deletions docs/build/building-apps/06-app-go-genesis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
sidebar_position: 1
---


ziscky marked this conversation as resolved.
Show resolved Hide resolved
### Modifying the `DefaultGenesis`

It is possible to modify the DefaultGenesis parameters for modules by wrapping the module, providing it to the `*module.Manager` and injecting it with `depinject`.


Example ( staking ) :

```go
type CustomStakingModule struct {
staking.AppModule
cdc codec.Codec
}

// DefaultGenesis will override the Staking module DefaultGenesis AppModuleBasic method.
ziscky marked this conversation as resolved.
Show resolved Hide resolved
func (cm CustomStakingModule) DefaultGenesis() json.RawMessage {
params := stakingtypes.DefaultParams()
params.BondDenom = "mydenom"

return cm.cdc.MustMarshalJSON(&stakingtypes.GenesisState{
Params: params,
})
}

// option 1: use new module manager
ziscky marked this conversation as resolved.
Show resolved Hide resolved
moduleManager := module.NewManagerFromMap(map[string]appmodule.AppModule{
stakingtypes.ModuleName: CustomStakingModule{cdc: appCodec, AppModule: staking.NewAppModule(...)},
// other modules ...
})

// option 2: override previous module manager
ziscky marked this conversation as resolved.
Show resolved Hide resolved
oldStakingModule,_ := moduleManager.Modules()[stakingtypes.ModuleName].(staking.AppModule)
moduleManager.Modules()[stakingtypes.ModuleName] = CustomStakingModule{
AppModule: oldStakingModule,
cdc: appCodec,
}


// depinject users
ziscky marked this conversation as resolved.
Show resolved Hide resolved
depinject.Inject(
// ...
&moduleManager,
)

ziscky marked this conversation as resolved.
Show resolved Hide resolved
// non-depinject users
ziscky marked this conversation as resolved.
Show resolved Hide resolved
moduleManager.RegisterLegacyAminoCodec(legacyAmino)
moduleManager.RegisterInterfaces(interfaceRegistry)

```

Loading