Skip to content

Commit

Permalink
Added migration methods for vpn store
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrinivas8687 committed Mar 12, 2022
1 parent bca16bf commit 91ec2e3
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 9 deletions.
2 changes: 1 addition & 1 deletion x/vpn/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
res, err := sessionServer.MsgEnd(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
default:
return nil, errors.Wrapf(types.ErrorUnknownMsgType, "%s", msg.Type())
return nil, errors.Wrapf(types.ErrorUnknownMsgType, "%T", msg)
}
}
}
2 changes: 1 addition & 1 deletion x/vpn/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Keeper struct {
}

func NewKeeper(
cdc codec.BinaryMarshaler,
cdc codec.BinaryCodec,
key sdk.StoreKey,
paramsKeeper paramskeeper.Keeper,
accountKeeper authkeeper.AccountKeeper,
Expand Down
55 changes: 55 additions & 0 deletions x/vpn/keeper/migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"

depositkeeper "github.com/sentinel-official/hub/x/deposit/keeper"
nodekeeper "github.com/sentinel-official/hub/x/node/keeper"
plankeeper "github.com/sentinel-official/hub/x/plan/keeper"
providerkeeper "github.com/sentinel-official/hub/x/provider/keeper"
sessionkeeper "github.com/sentinel-official/hub/x/session/keeper"
subscriptionkeeper "github.com/sentinel-official/hub/x/subscription/keeper"
)

type Migrator struct {
deposit depositkeeper.Migrator
provider providerkeeper.Migrator
node nodekeeper.Migrator
plan plankeeper.Migrator
subscription subscriptionkeeper.Migrator
session sessionkeeper.Migrator
}

func NewMigrator(k Keeper) Migrator {
return Migrator{
deposit: depositkeeper.NewMigrator(k.Deposit),
provider: providerkeeper.NewMigrator(k.Provider),
node: nodekeeper.NewMigrator(k.Node),
plan: plankeeper.NewMigrator(k.Plan),
subscription: subscriptionkeeper.NewMigrator(k.Subscription),
session: sessionkeeper.NewMigrator(k.Session),
}
}

func (m Migrator) Migrate1to2(ctx sdk.Context) error {
if err := m.deposit.Migrate1to2(ctx); err != nil {
return err
}
if err := m.provider.Migrate1to2(ctx); err != nil {
return err
}
if err := m.node.Migrate1to2(ctx); err != nil {
return err
}
if err := m.plan.Migrate1to2(ctx); err != nil {
return err
}
if err := m.subscription.Migrate1to2(ctx); err != nil {
return err
}
if err := m.session.Migrate1to2(ctx); err != nil {
return err
}

return nil
}
19 changes: 13 additions & 6 deletions x/vpn/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ func (a AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry
types.RegisterInterfaces(registry)
}

func (a AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage {
func (a AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(types.DefaultGenesisState())
}

func (a AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, _ client.TxEncodingConfig, message json.RawMessage) error {
func (a AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, message json.RawMessage) error {
var state types.GenesisState
if err := cdc.UnmarshalJSON(message, &state); err != nil {
return err
Expand Down Expand Up @@ -92,13 +92,13 @@ func (a AppModuleBasic) GetQueryCmd() *cobra.Command {

type AppModule struct {
AppModuleBasic
cdc codec.Marshaler
cdc codec.Codec
ak expected.AccountKeeper
bk expected.BankKeeper
k keeper.Keeper
}

func NewAppModule(cdc codec.Marshaler, ak expected.AccountKeeper, bk expected.BankKeeper, k keeper.Keeper) AppModule {
func NewAppModule(cdc codec.Codec, ak expected.AccountKeeper, bk expected.BankKeeper, k keeper.Keeper) AppModule {
return AppModule{
cdc: cdc,
ak: ak,
Expand All @@ -107,15 +107,15 @@ func NewAppModule(cdc codec.Marshaler, ak expected.AccountKeeper, bk expected.Ba
}
}

func (a AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, message json.RawMessage) []abcitypes.ValidatorUpdate {
func (a AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, message json.RawMessage) []abcitypes.ValidatorUpdate {
var state types.GenesisState
cdc.MustUnmarshalJSON(message, &state)
InitGenesis(ctx, a.k, &state)

return nil
}

func (a AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage {
func (a AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(ExportGenesis(ctx, a.k))
}

Expand Down Expand Up @@ -144,8 +144,15 @@ func (a AppModule) RegisterServices(configurator module.Configurator) {
plantypes.RegisterQueryServiceServer(configurator.QueryServer(), plankeeper.NewQueryServiceServer(a.k.Plan))
subscriptiontypes.RegisterQueryServiceServer(configurator.QueryServer(), subscriptionkeeper.NewQueryServiceServer(a.k.Subscription))
sessiontypes.RegisterQueryServiceServer(configurator.QueryServer(), sessionkeeper.NewQueryServiceServer(a.k.Session))

m := keeper.NewMigrator(a.k)
if err := configurator.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil {
panic(err)
}
}

func (a AppModule) ConsensusVersion() uint64 { return 2 }

func (a AppModule) BeginBlock(_ sdk.Context, _ abcitypes.RequestBeginBlock) {}

func (a AppModule) EndBlock(ctx sdk.Context, _ abcitypes.RequestEndBlock) []abcitypes.ValidatorUpdate {
Expand Down
2 changes: 1 addition & 1 deletion x/vpn/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

func WeightedOperations(
params simulationtypes.AppParams,
cdc codec.JSONMarshaler,
cdc codec.JSONCodec,
ak expected.AccountKeeper,
bk expected.BankKeeper,
k keeper.Keeper,
Expand Down

0 comments on commit 91ec2e3

Please sign in to comment.