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
package keeper // migrations.go | |
type Migrator struct { | |
keeper Keeper | |
} | |
func NewMigrator(keeper Keeper) Migrator { | |
return Migrator{keeper: keeper} | |
} |
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
x | |
βββ foo | |
β βββ keepers | |
β β βββ migrations.go | |
β βββ migrations | |
β β βββ v1 | |
β β β βββ tx.pb.go | |
β β β βββ ... | |
β β βββ v2 | |
β β βββ migrations.go |
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
package v2 // upgrades.go | |
var DenomMetadata = banktypes.Metadata{...} | |
func CreateUpgradeHandler( | |
mm *module.Manager, | |
configurator module.Configurator, | |
bk bankkeeper.Keeper, | |
) upgradetypes.UpgradeHandler { | |
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { |
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
package app // app.go | |
func NewSimApp(...) *SimApp { | |
// setupUpgradeHandlers should be called before `LoadLatestVersion()` | |
// because StoreLoad is sealed after that | |
app.setupUpgradeHandlers(configurator, app.BankKeeper) | |
if loadLatest { | |
if err := app.LoadLatestVersion(); err != nil { |
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
package app // upgrades.go | |
func (app *App) setupUpgradeHandlers( | |
configurator module.Configurator, | |
... | |
) { | |
app.UpgradeKeeper.SetUpgradeHandler( | |
v2.UpgradeName, | |
v2.CreateUpgradeHandler(app.mm, configurator, ...), | |
) |
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
package v2 // upgrades.go | |
func CreateUpgradeHandler( | |
mm *module.Manager, | |
configurator module.Configurator, | |
... | |
) upgradetypes.UpgradeHandler { | |
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { | |
... | |
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
package v2 // constants.go | |
const ( | |
UpgradeName = "v2.0.0" | |
... | |
) |
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
. # application project root | |
βββ app | |
β βββ upgrades | |
β β βββ v2 | |
β β β βββ constants.go | |
β β β βββ upgrades.go | |
β β βββ ... | |
β βββ app.go | |
β βββ upgrades.go | |
βββ ... |
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
func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { | |
BeginBlocker(am.keeper, ctx, req) | |
} | |
func BeginBlocker(k keeper.Keeper, ctx sdk.Context, _ abci.RequestBeginBlock) { | |
plan, found := k.GetUpgradePlan(ctx) | |
... | |
if !found { | |
return | |
} |
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
// VersionMap is a map of moduleName -> version | |
type VersionMap map[string]uint64 |