Skip to content

Commit

Permalink
Merge pull request #140 from realiotech/feat/sdk-47
Browse files Browse the repository at this point in the history
Feat/sdk 47
  • Loading branch information
GNaD13 authored May 15, 2024
2 parents b5a1b0e + c5a2a6a commit e91cd81
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
24 changes: 24 additions & 0 deletions x/multi-staking/keeper/migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/staking/exported"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
)

// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
stkm stakingkeeper.Migrator
}

// NewMigrator returns a new Migrator.
func NewMigrator(keeper *stakingkeeper.Keeper, legacySubspace exported.Subspace) Migrator {
return Migrator{
stkm: stakingkeeper.NewMigrator(keeper, legacySubspace),
}
}

// Migrate1to2 migrates multi-staking state from consensus version 1 to 2. (sdk46 to sdk47)
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
return m.stkm.Migrate3to4(ctx)
}
24 changes: 9 additions & 15 deletions x/multi-staking/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/realio-tech/multi-staking-module/x/multi-staking/client/cli"
multistakingkeeper "github.com/realio-tech/multi-staking-module/x/multi-staking/keeper"
"github.com/realio-tech/multi-staking-module/x/multi-staking/keeper"
multistakingtypes "github.com/realio-tech/multi-staking-module/x/multi-staking/types"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -88,7 +88,7 @@ type AppModule struct {
// embed the Cosmos SDK's x/staking AppModule
skAppModule staking.AppModule

keeper multistakingkeeper.Keeper
keeper keeper.Keeper
sk *stakingkeeper.Keeper
ak stakingtypes.AccountKeeper
bk stakingtypes.BankKeeper
Expand All @@ -99,7 +99,7 @@ type AppModule struct {

// NewAppModule creates a new AppModule object using the native x/staking module
// AppModule constructor.
func NewAppModule(cdc codec.Codec, keeper multistakingkeeper.Keeper, sk *stakingkeeper.Keeper, ak stakingtypes.AccountKeeper, bk stakingtypes.BankKeeper, ss exported.Subspace) AppModule {
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, sk *stakingkeeper.Keeper, ak stakingtypes.AccountKeeper, bk stakingtypes.BankKeeper, ss exported.Subspace) AppModule {
stakingAppMod := staking.NewAppModule(cdc, sk, ak, bk, ss)
return AppModule{
AppModuleBasic: AppModuleBasic{cdc: cdc},
Expand All @@ -120,7 +120,7 @@ func (AppModule) Name() string {
// RegisterInvariants registers the staking module invariants.
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
am.skAppModule.RegisterInvariants(ir)
multistakingkeeper.RegisterInvariants(ir, am.keeper)
keeper.RegisterInvariants(ir, am.keeper)
}

// QuerierRoute returns the staking module's querier route name.
Expand All @@ -131,23 +131,17 @@ func (AppModule) QuerierRoute() string {
// RegisterServices registers a GRPC query service to respond to the
// module-specific GRPC queries.
func (am AppModule) RegisterServices(cfg module.Configurator) {
stakingtypes.RegisterMsgServer(cfg.MsgServer(), multistakingkeeper.NewMsgServerImpl(am.keeper))
multistakingtypes.RegisterQueryServer(cfg.QueryServer(), multistakingkeeper.NewQueryServerImpl(am.keeper))
stakingtypes.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
multistakingtypes.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServerImpl(am.keeper))

querier := stakingkeeper.Querier{Keeper: am.sk}
stakingtypes.RegisterQueryServer(cfg.QueryServer(), querier)

// migrate staking module
m := stakingkeeper.NewMigrator(am.sk, am.legacySubspace)
if err := cfg.RegisterMigration(stakingtypes.ModuleName, 1, m.Migrate1to2); err != nil {
m := keeper.NewMigrator(am.sk, am.legacySubspace)
if err := cfg.RegisterMigration(multistakingtypes.ModuleName, 1, m.Migrate1to2); err != nil {
panic(fmt.Sprintf("failed to migrate x/%s from version 1 to 2: %v", stakingtypes.ModuleName, err))
}
if err := cfg.RegisterMigration(stakingtypes.ModuleName, 2, m.Migrate2to3); err != nil {
panic(fmt.Sprintf("failed to migrate x/%s from version 2 to 3: %v", stakingtypes.ModuleName, err))
}
if err := cfg.RegisterMigration(stakingtypes.ModuleName, 3, m.Migrate3to4); err != nil {
panic(fmt.Sprintf("failed to migrate x/%s from version 3 to 4: %v", stakingtypes.ModuleName, err))
}
}

// InitGenesis initial genesis state for multi-staking module
Expand Down Expand Up @@ -183,4 +177,4 @@ func (am AppModule) EndBlock(ctx sdk.Context, requestEndBlock abci.RequestEndBlo
}

// ConsensusVersion return module consensus version
func (AppModule) ConsensusVersion() uint64 { return 1 }
func (AppModule) ConsensusVersion() uint64 { return 2 }

0 comments on commit e91cd81

Please sign in to comment.