Skip to content

Commit

Permalink
feat: add migrator
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmic-vagabond committed Dec 1, 2023
1 parent a6ea27f commit 309aef2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
24 changes: 24 additions & 0 deletions x/margin/migrations/v4_migration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package migrations

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/elys-network/elys/x/margin/types"
)

func (m Migrator) V4Migration(ctx sdk.Context) error {
// reset params
params := types.NewParams()
m.keeper.SetParams(ctx, &params)

// reset mtps
for _, mtp := range m.keeper.GetAllMTPs(ctx) {
m.keeper.DestroyMTP(ctx, mtp.Address, mtp.Id)
}

// reset pools
for _, pool := range m.keeper.GetAllPools(ctx) {
m.keeper.RemovePool(ctx, pool.AmmPoolId)
}

return nil
}
4 changes: 2 additions & 2 deletions x/margin/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
m := migrations.NewMigrator(am.keeper)
err := cfg.RegisterMigration(types.ModuleName, 2, m.V3Migration)
err := cfg.RegisterMigration(types.ModuleName, 3, m.V4Migration)
if err != nil {
panic(err)
}
Expand All @@ -144,7 +144,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
}

// ConsensusVersion is a sequence number for state-breaking change of the module. It should be incremented on each consensus-breaking change introduced by the module. To avoid wrong/empty versions, the initial version should be set to 1
func (AppModule) ConsensusVersion() uint64 { return 3 }
func (AppModule) ConsensusVersion() uint64 { return 4 }

// BeginBlock contains the logic that is automatically triggered at the beginning of each block
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
Expand Down

0 comments on commit 309aef2

Please sign in to comment.