Skip to content

Commit

Permalink
fix: add migrations to both incentive and leveragelp
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmic-vagabond committed Nov 23, 2023
1 parent 08dc220 commit ca92ff8
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
11 changes: 11 additions & 0 deletions x/incentive/migrations/v5_migration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package migrations

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

func (m Migrator) V5Migration(ctx sdk.Context) error {
m.keeper.SetParams(ctx, types.NewParams())
return nil
}
4 changes: 2 additions & 2 deletions x/incentive/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,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, 3, m.V4Migration)
err := cfg.RegisterMigration(types.ModuleName, 4, m.V5Migration)
if err != nil {
panic(err)
}
Expand All @@ -137,7 +137,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 4 }
func (AppModule) ConsensusVersion() uint64 { return 5 }

// BeginBlock contains the logic that is automatically triggered at the beginning of each block
func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
Expand Down
13 changes: 13 additions & 0 deletions x/leveragelp/migrations/new_migrator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package migrations

import (
"github.com/elys-network/elys/x/leveragelp/keeper"
)

type Migrator struct {
keeper keeper.Keeper
}

func NewMigrator(keeper keeper.Keeper) Migrator {
return Migrator{keeper: keeper}
}
12 changes: 12 additions & 0 deletions x/leveragelp/migrations/v2_migration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package migrations

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

func (m Migrator) V2Migration(ctx sdk.Context) error {
params := types.NewParams()
m.keeper.SetParams(ctx, &params)
return nil
}
8 changes: 7 additions & 1 deletion x/leveragelp/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/elys-network/elys/x/leveragelp/client/cli"
"github.com/elys-network/elys/x/leveragelp/keeper"
"github.com/elys-network/elys/x/leveragelp/migrations"
"github.com/elys-network/elys/x/leveragelp/types"
)

Expand Down Expand Up @@ -115,6 +116,11 @@ func NewAppModule(
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, 1, m.V2Migration)
if err != nil {
panic(err)
}
}

// RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted)
Expand All @@ -138,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 1 }
func (AppModule) ConsensusVersion() uint64 { return 2 }

// 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 ca92ff8

Please sign in to comment.