From a9af461bb49a261a7b6b832902509efb3e30aa15 Mon Sep 17 00:00:00 2001 From: dreamer Date: Mon, 16 Dec 2024 10:19:57 +0800 Subject: [PATCH] feat: add v4 upgrade plan --- app/upgrade.go | 4 +++- app/upgrades/v400/upgrades.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 app/upgrades/v400/upgrades.go diff --git a/app/upgrade.go b/app/upgrade.go index 1f138a275..c484e72c9 100644 --- a/app/upgrade.go +++ b/app/upgrade.go @@ -9,13 +9,15 @@ import ( v200 "github.com/irisnet/irishub/v4/app/upgrades/v200" v210 "github.com/irisnet/irishub/v4/app/upgrades/v210" v300 "github.com/irisnet/irishub/v4/app/upgrades/v300" + v400 "github.com/irisnet/irishub/v4/app/upgrades/v400" ) var ( router = upgrades.NewUpgradeRouter(). Register(v200.Upgrade). Register(v210.Upgrade). - Register(v300.Upgrade) + Register(v300.Upgrade). + Register(v400.Upgrade) ) // RegisterUpgradePlans register a handler of upgrade plan diff --git a/app/upgrades/v400/upgrades.go b/app/upgrades/v400/upgrades.go new file mode 100644 index 000000000..5d00b7f22 --- /dev/null +++ b/app/upgrades/v400/upgrades.go @@ -0,0 +1,31 @@ +package v400 + +import ( + "context" + + storetypes "cosmossdk.io/store/types" + upgradetypes "cosmossdk.io/x/upgrade/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/irisnet/irishub/v4/app/upgrades" +) + +// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal +var Upgrade = upgrades.Upgrade{ + UpgradeName: "v4.0.0", + UpgradeHandlerConstructor: upgradeHandlerConstructor, + StoreUpgrades: &storetypes.StoreUpgrades{}, +} + +func upgradeHandlerConstructor( + m *module.Manager, + c module.Configurator, + box upgrades.Toolbox, +) upgradetypes.UpgradeHandler { + return func(context context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + ctx := sdk.UnwrapSDKContext(context) + ctx.Logger().Info("execute a upgrade plan...") + return box.ModuleManager.RunMigrations(ctx, c, fromVM) + } +}