Skip to content

Commit

Permalink
move ecocredit param fee setting to the module migration handler
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zaremba committed Feb 18, 2022
1 parent 3402ab0 commit 9c31e22
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
9 changes: 0 additions & 9 deletions app/stable_appconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,6 @@ func (app *RegenApp) registerUpgradeHandlers() {
})

app.UpgradeKeeper.SetUpgradeHandler("v3.0.0", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// get the params
ecoParams, ok := app.ParamsKeeper.GetSubspace(ecocredittypes.ModuleName)
if !ok {
panic(fmt.Sprintf("unable to upgrade: subspace %s not found", ecocredittypes.ModuleName))
}

// set basket creation fee to 1,000 REGEN
ecoParams.Set(ctx, ecocredittypes.KeyBasketCreationFee, sdk.NewCoins(sdk.NewInt64Coin("uregen", 1e9)))

return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})

Expand Down
11 changes: 9 additions & 2 deletions x/ecocredit/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,15 @@ func (a Module) RegisterInterfaces(registry types.InterfaceRegistry) {
func (a Module) RegisterServices(configurator servermodule.Configurator) {
server.RegisterServices(configurator, a.paramSpace, a.accountKeeper, a.bankKeeper, a.distributionKeeper)

configurator.RegisterMigration(ecocredit.ModuleName, 2,
func(sdk.Context) error { return nil })
err := configurator.RegisterMigration(ecocredit.ModuleName, 2,
func(ctx sdk.Context) error {
// set basket creation fee to 1,000 REGEN
a.paramSpace.Set(ctx, ecocredit.KeyBasketCreationFee, sdk.NewCoins(sdk.NewInt64Coin("uregen", 1e9)))
return nil
})
if err != nil {
panic(fmt.Sprintf("failed to migrate x/ecocredit from version 1 to 2: %v", err))
}
}

//nolint:errcheck
Expand Down
5 changes: 5 additions & 0 deletions x/ecocredit/server/migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package server

import (
"fmt"
)
5 changes: 3 additions & 2 deletions x/ecocredit/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ func RegisterServices(
impl := newServer(configurator.ModuleKey(), paramSpace, accountKeeper, bankKeeper, distKeeper, configurator.Marshaler())
ecocredit.RegisterMsgServer(configurator.MsgServer(), impl)
ecocredit.RegisterQueryServer(configurator.QueryServer(), impl)
baskettypes.RegisterMsgServer(configurator.MsgServer(), impl.basketKeeper)
baskettypes.RegisterQueryServer(configurator.QueryServer(), impl.basketKeeper)

configurator.RegisterGenesisHandlers(impl.InitGenesis, impl.ExportGenesis)
configurator.RegisterWeightedOperationsHandler(impl.WeightedOperations)
configurator.RegisterInvariantsHandler(impl.RegisterInvariants)
baskettypes.RegisterMsgServer(configurator.MsgServer(), impl.basketKeeper)
baskettypes.RegisterQueryServer(configurator.QueryServer(), impl.basketKeeper)
}

0 comments on commit 9c31e22

Please sign in to comment.