Skip to content

Commit

Permalink
Merge pull request #2 from ComputerKeeda/feature/external-seq/espress…
Browse files Browse the repository at this point in the history
…o/v1/patch-2

Add upgrade handler for "jip-2" and handle store upgrades
  • Loading branch information
ComputerKeeda authored Oct 1, 2024
2 parents 188b591 + 811d6a8 commit dd5458e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
19 changes: 17 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package app

import (
upgradetypes "cosmossdk.io/x/upgrade/types"
trackgatemoduletypes "github.com/airchains-network/junction/x/trackgate/types"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -354,15 +356,28 @@ func New(
// app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap())
// return app.App.InitChainer(ctx, req)
// })
// Handle store upgrades
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
}

if upgradeInfo.Name == "jip-2" && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{trackgatemoduletypes.StoreKey},
}

app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}

if err := app.Load(loadLatest); err != nil {
return nil, err
}

configurator := app.Configurator()
UpgradeHandleFunc := CreateDefaultUpgradeHandler(app.ModuleManager, configurator)
UpgradeHandleFunc := CreateDefaultUpgradeHandler(app.ModuleManager, configurator, app)
app.UpgradeKeeper.SetUpgradeHandler(
"jip-1",
"jip-2",
UpgradeHandleFunc, // Upgrade handler function
)

Expand Down
12 changes: 9 additions & 3 deletions app/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package app

import (
"context"
storetypes "cosmossdk.io/store/types"
trackgatemoduletypes "github.com/airchains-network/junction/x/trackgate/types"

upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/types/module"
Expand All @@ -11,12 +13,16 @@ import (
func CreateDefaultUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
app *App,
) upgradetypes.UpgradeHandler {
return func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
versionMap := module.VersionMap{
"junction": 100, // version 1.0.0
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{trackgatemoduletypes.StoreKey},
}

return versionMap, nil
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(plan.Height, &storeUpgrades))

//return versionMap, nil
return app.ModuleManager.RunMigrations(ctx, configurator, fromVM)
}
}

0 comments on commit dd5458e

Please sign in to comment.