Skip to content

Commit

Permalink
feat(mint): create migration for v3
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux authored and ccamel committed Dec 4, 2023
1 parent 3ea9694 commit 3df4557
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
11 changes: 4 additions & 7 deletions x/mint/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/okp4/okp4d/x/mint/exported"
v3 "github.com/okp4/okp4d/x/mint/migrations/v3"
)

type Migrator struct {
keeper Keeper
legacySubspace exported.Subspace
keeper Keeper
}

func NewMigrator(keeper Keeper, legacySubspace exported.Subspace) Migrator {
func NewMigrator(keeper Keeper) Migrator {
return Migrator{
keeper: keeper,
legacySubspace: legacySubspace,
keeper: keeper,
}
}

func (m Migrator) Migrate2to3(ctx sdk.Context) error {
return v3.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc, m.legacySubspace)
return v3.MigrateStore(ctx, ctx.KVStore(m.keeper.storeKey), m.keeper.cdc)
}
16 changes: 10 additions & 6 deletions x/mint/migrations/v3/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ package v3

import (
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/okp4/okp4d/x/mint/exported"
"github.com/okp4/okp4d/x/mint/types"
)

// MigrateStore migrates the x/mint module state from the consensus version 2 to
// version 3.
// This version include new/deleted parameters in store.
func MigrateStore(ctx sdk.Context,
storeKey storetypes.StoreKey,
store sdk.KVStore,
cdc codec.BinaryCodec,
legacySubspace exported.Subspace,
) error {
logger := ctx.Logger().
With("module", "mint").
Expand All @@ -23,7 +21,13 @@ func MigrateStore(ctx sdk.Context,

logger.Debug("migrate mint params")

// TODO:
newParams := types.DefaultParams()

bz, err := cdc.Marshal(&newParams)
if err != nil {
return err
}
store.Set(types.ParamsKey, bz)

logger.Debug("module migration done")

Expand Down
8 changes: 2 additions & 6 deletions x/mint/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"

"github.com/okp4/okp4d/x/mint/client/cli"
"github.com/okp4/okp4d/x/mint/exported"
"github.com/okp4/okp4d/x/mint/keeper"
"github.com/okp4/okp4d/x/mint/simulation"
"github.com/okp4/okp4d/x/mint/types"
Expand Down Expand Up @@ -87,17 +86,14 @@ type AppModule struct {

keeper keeper.Keeper
authKeeper types.AccountKeeper
// legacySubspace is used principally for migration
legacySubspace exported.Subspace
}

// NewAppModule creates a new AppModule object.
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak types.AccountKeeper, legacySubspace exported.Subspace) AppModule {
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak types.AccountKeeper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{cdc: cdc},
keeper: keeper,
authKeeper: ak,
legacySubspace: legacySubspace,
}
}

Expand All @@ -115,7 +111,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)

migrator := keeper.NewMigrator(am.keeper, am.legacySubspace)
migrator := keeper.NewMigrator(am.keeper)

migrations := []struct {
fromVersion uint64
Expand Down

0 comments on commit 3df4557

Please sign in to comment.