Skip to content

Commit

Permalink
docs: add instructions to change DefaultGenesis (backport #21680) (#2…
Browse files Browse the repository at this point in the history
…1991)

Co-authored-by: Eric Mokaya <[email protected]>
  • Loading branch information
mergify[bot] and ziscky authored Oct 1, 2024
1 parent c32c775 commit 000d394
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 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,47 @@
---
sidebar_position: 1
---

### 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.
func (cm CustomStakingModule) DefaultGenesis() json.RawMessage {
params := stakingtypes.DefaultParams()
params.BondDenom = "mydenom"

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

// option 1 ( for depinject users ): override previous module manager
depinject.Inject(
// ... provider/invoker/supplier
&moduleManager,
)

oldStakingModule,_ := moduleManager.Modules()[stakingtypes.ModuleName].(staking.AppModule)
moduleManager.Modules()[stakingtypes.ModuleName] = CustomStakingModule{
AppModule: oldStakingModule,
cdc: appCodec,
}

// option 2 ( for non depinject users ): use new module manager
moduleManager := module.NewManagerFromMap(map[string]appmodule.AppModule{
stakingtypes.ModuleName: CustomStakingModule{cdc: appCodec, AppModule: staking.NewAppModule(...)},
// other modules ...
})

// set the module manager
app.ModuleManager = moduleManager
```

0 comments on commit 000d394

Please sign in to comment.