From e38ae03fea72b3715593287766c08a7d68940d77 Mon Sep 17 00:00:00 2001 From: Benjamin DENEUX Date: Thu, 24 Aug 2023 11:40:46 +0200 Subject: [PATCH] feat(mint): register migration handler --- app/app.go | 2 +- app/upgrades.go | 8 ++++++++ app/upgrades/v6/upgrade.go | 30 ++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 app/upgrades/v6/upgrade.go diff --git a/app/app.go b/app/app.go index 7f5c7087..5b7fdc92 100644 --- a/app/app.go +++ b/app/app.go @@ -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, diff --git a/app/upgrades.go b/app/upgrades.go index 2f7a8c83..e3819393 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -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() { @@ -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)) @@ -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 { diff --git a/app/upgrades/v6/upgrade.go b/app/upgrades/v6/upgrade.go new file mode 100644 index 00000000..8f3f0660 --- /dev/null +++ b/app/upgrades/v6/upgrade.go @@ -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) + } +}