Skip to content

Commit

Permalink
feat(mint): register migration handler
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux authored and ccamel committed Dec 4, 2023
1 parent 3df4557 commit e38ae03
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ func New(
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, app.GetSubspace(minttypes.ModuleName)),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper),
slashing.NewAppModule(appCodec,
app.SlashingKeeper,
app.AccountKeeper,
Expand Down
8 changes: 8 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
v4 "github.com/okp4/okp4d/app/upgrades/v4"
v41 "github.com/okp4/okp4d/app/upgrades/v41"
v5 "github.com/okp4/okp4d/app/upgrades/v5"
v6 "github.com/okp4/okp4d/app/upgrades/v6"
)

func (app *App) setupUpgradeHandlers() {
Expand All @@ -27,6 +28,11 @@ func (app *App) setupUpgradeHandlers() {
v5.CreateUpgradeHandler(app.ParamsKeeper, &app.ConsensusParamsKeeper, app.mm, app.configurator),
)

app.UpgradeKeeper.SetUpgradeHandler(
v6.UpgradeName,
v6.CreateUpgradeHandler(app.mm, app.configurator),
)

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Errorf("failed to read upgrade info from disk: %w", err))
Expand All @@ -44,6 +50,8 @@ func (app *App) setupUpgradeHandlers() {
storeUpgrades = v41.StoreUpgrades
case v5.UpgradeName:
storeUpgrades = v5.StoreUpgrades
case v6.UpgradeName:
storeUpgrades = v6.StoreUpgrades
}

if storeUpgrades != nil {
Expand Down
30 changes: 30 additions & 0 deletions app/upgrades/v6/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package v5

import (
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

const UpgradeName = "v6.0.0"

var StoreUpgrades = &storetypes.StoreUpgrades{
Added: []string{
"feeibc",
},
}

// CreateUpgradeHandler is the handler that will perform migration from v5.0.0 to v6.0.0.
// Migrate the mint module with new parameters.
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
logger := ctx.Logger().With("upgrade", UpgradeName)

logger.Debug("running module migrations...")
return mm.RunMigrations(ctx, configurator, vm)
}
}

0 comments on commit e38ae03

Please sign in to comment.