Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamer committed Jun 9, 2023
1 parent 5668958 commit 36b022a
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 22 deletions.
23 changes: 23 additions & 0 deletions modules/coinswap/exported/exported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package exported

import (
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

var (
NewParamSetPair = paramtypes.NewParamSetPair
)

type (
ParamSet = paramtypes.ParamSet
ParamSetPairs = paramtypes.ParamSetPairs

// Subspace defines an interface that implements the legacy x/params Subspace
// type.
//
// NOTE: This is used solely for migration of x/params managed parameters.
Subspace interface {
GetParamSet(ctx sdk.Context, ps ParamSet)
}
)
6 changes: 3 additions & 3 deletions modules/coinswap/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"

"github.com/irisnet/irismod/modules/coinswap/exported"
v1 "github.com/irisnet/irismod/modules/coinswap/migrations/v1"
v2 "github.com/irisnet/irismod/modules/coinswap/migrations/v2"
v3 "github.com/irisnet/irismod/modules/coinswap/migrations/v3"
Expand All @@ -13,11 +13,11 @@ import (
// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
k Keeper
legacySubspace paramstypes.Subspace
legacySubspace exported.Subspace
}

// NewMigrator returns a new Migrator.
func NewMigrator(k Keeper, legacySubspace paramstypes.Subspace) Migrator {
func NewMigrator(k Keeper, legacySubspace exported.Subspace) Migrator {
return Migrator{k: k, legacySubspace: legacySubspace}
}

Expand Down
12 changes: 6 additions & 6 deletions modules/coinswap/migrations/v2/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package v2
import (
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"

"github.com/irisnet/irismod/modules/coinswap/exported"
"github.com/irisnet/irismod/modules/coinswap/types"
)

Expand All @@ -26,7 +26,7 @@ type (
}
)

func Migrate(ctx sdk.Context, k CoinswapKeeper, paramSpace paramstypes.Subspace) error {
func Migrate(ctx sdk.Context, k CoinswapKeeper, paramSpace exported.Subspace) error {
params := GetLegacyParams(ctx, paramSpace)
newParams := types.Params{
Fee: params.Fee,
Expand All @@ -37,15 +37,15 @@ func Migrate(ctx sdk.Context, k CoinswapKeeper, paramSpace paramstypes.Subspace)
}

// GetLegacyParams gets the parameters for the coinswap module.
func GetLegacyParams(ctx sdk.Context, paramSpace paramstypes.Subspace) Params {
func GetLegacyParams(ctx sdk.Context, paramSpace exported.Subspace) Params {
var swapParams Params
paramSpace.GetParamSet(ctx, &swapParams)
return swapParams
}

// ParamSetPairs implements paramtypes.KeyValuePairs
func (p *Params) ParamSetPairs() paramstypes.ParamSetPairs {
return paramstypes.ParamSetPairs{
paramstypes.NewParamSetPair(KeyFee, &p.Fee, nil),
func (p *Params) ParamSetPairs() exported.ParamSetPairs {
return exported.ParamSetPairs{
exported.NewParamSetPair(KeyFee, &p.Fee, nil),
}
}
16 changes: 8 additions & 8 deletions modules/coinswap/migrations/v3/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package v3

import (
sdk "github.com/cosmos/cosmos-sdk/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"

"github.com/irisnet/irismod/modules/coinswap/exported"
"github.com/irisnet/irismod/modules/coinswap/types"
)

Expand All @@ -27,7 +27,7 @@ type (
}
)

func Migrate(ctx sdk.Context, k CoinswapKeeper, paramSpace paramstypes.Subspace) error {
func Migrate(ctx sdk.Context, k CoinswapKeeper, paramSpace exported.Subspace) error {
params := GetLegacyParams(ctx, paramSpace)
newParams := types.Params{
Fee: params.Fee,
Expand All @@ -39,17 +39,17 @@ func Migrate(ctx sdk.Context, k CoinswapKeeper, paramSpace paramstypes.Subspace)
}

// GetLegacyParams gets the parameters for the coinswap module.
func GetLegacyParams(ctx sdk.Context, paramSpace paramstypes.Subspace) Params {
func GetLegacyParams(ctx sdk.Context, paramSpace exported.Subspace) Params {
var swapParams Params
paramSpace.GetParamSet(ctx, &swapParams)
return swapParams
}

// ParamSetPairs implements paramtypes.KeyValuePairs
func (p *Params) ParamSetPairs() paramstypes.ParamSetPairs {
return paramstypes.ParamSetPairs{
paramstypes.NewParamSetPair(KeyFee, &p.Fee, nil),
paramstypes.NewParamSetPair(KeyPoolCreationFee, &p.PoolCreationFee, nil),
paramstypes.NewParamSetPair(KeyTaxRate, &p.TaxRate, nil),
func (p *Params) ParamSetPairs() exported.ParamSetPairs {
return exported.ParamSetPairs{
exported.NewParamSetPair(KeyFee, &p.Fee, nil),
exported.NewParamSetPair(KeyPoolCreationFee, &p.PoolCreationFee, nil),
exported.NewParamSetPair(KeyTaxRate, &p.TaxRate, nil),
}
}
4 changes: 2 additions & 2 deletions modules/coinswap/migrations/v4/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package v4

import (
sdk "github.com/cosmos/cosmos-sdk/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"

"github.com/irisnet/irismod/modules/coinswap/exported"
"github.com/irisnet/irismod/modules/coinswap/types"
)

Expand All @@ -13,7 +13,7 @@ type CoinswapKeeper interface {
}

// Migrate migrate the coinswap params from legacy x/params module to coinswap module
func Migrate(ctx sdk.Context, k CoinswapKeeper, legacySubspace paramstypes.Subspace) error {
func Migrate(ctx sdk.Context, k CoinswapKeeper, legacySubspace exported.Subspace) error {
var params types.Params
legacySubspace.GetParamSet(ctx, &params)
return k.SetParams(ctx, params)
Expand Down
6 changes: 3 additions & 3 deletions modules/coinswap/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"

"github.com/irisnet/irismod/modules/coinswap/exported"
"github.com/irisnet/irismod/modules/coinswap/keeper"
"github.com/irisnet/irismod/modules/coinswap/simulation"
"github.com/irisnet/irismod/modules/coinswap/types"
Expand Down Expand Up @@ -90,7 +90,7 @@ type AppModule struct {
keeper keeper.Keeper
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
legacySubspace paramstypes.Subspace
legacySubspace exported.Subspace
}

// NewAppModule creates a new AppModule object
Expand All @@ -99,7 +99,7 @@ func NewAppModule(
keeper keeper.Keeper,
accountKeeper types.AccountKeeper,
bankKeeper types.BankKeeper,
legacySubspace paramstypes.Subspace,
legacySubspace exported.Subspace,
) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{cdc: cdc},
Expand Down

0 comments on commit 36b022a

Please sign in to comment.