generated from okp4/template-oss
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(upgrade): create package for register upgrades
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package app | ||
|
||
import ( | ||
"fmt" | ||
|
||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
v4 "github.com/okp4/okp4d/app/upgrades/v4" | ||
) | ||
|
||
func (app *App) setupUpgradeHandlers() { | ||
app.UpgradeKeeper.SetUpgradeHandler( | ||
v4.UpgradeName, | ||
v4.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)) | ||
} | ||
|
||
if app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { | ||
return | ||
} | ||
|
||
var storeUpgrades *storetypes.StoreUpgrades | ||
switch upgradeInfo.Name { | ||
case v4.UpgradeName: | ||
storeUpgrades = v4.StoreUpgrades | ||
} | ||
|
||
if storeUpgrades != nil { | ||
// configure store loader that checks if version == upgradeHeight and applies store upgrades | ||
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, storeUpgrades)) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package v4 | ||
|
||
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 = "v4.0.0" | ||
|
||
var StoreUpgrades = &storetypes.StoreUpgrades{ | ||
Added: []string{"logic"}, | ||
} | ||
|
||
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) | ||
} | ||
} |