Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for legacy params query #45

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion x/distribution/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

// Keeper of the distribution store
Expand All @@ -22,6 +23,7 @@ type Keeper struct {
// the address capable of executing a MsgUpdateParams message. Typically, this
// should be the x/gov module account.
authority string
ss paramstypes.Subspace

feeCollectorName string // name of the FeeCollector ModuleAccount
}
Expand All @@ -30,13 +32,18 @@ type Keeper struct {
func NewKeeper(
cdc codec.BinaryCodec, key storetypes.StoreKey,
ak types.AccountKeeper, bk types.BankKeeper, sk types.StakingKeeper,
feeCollectorName string, authority string,
feeCollectorName string, authority string, ss ...paramstypes.Subspace,
) Keeper {
// ensure distribution module account is set
if addr := ak.GetModuleAddress(types.ModuleName); addr == nil {
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
}

// ensure that a param subspace is provided
if len(ss) != 1 {
panic("must provide a param subspace")
}

return Keeper{
storeKey: key,
cdc: cdc,
Expand All @@ -45,6 +52,7 @@ func NewKeeper(
stakingKeeper: sk,
feeCollectorName: feeCollectorName,
authority: authority,
ss: ss[0],
}
}

Expand Down
13 changes: 10 additions & 3 deletions x/distribution/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
)

// GetParams returns the total set of distribution parameters.
func (k Keeper) GetParams(clientCtx sdk.Context) (params types.Params) {
store := clientCtx.KVStore(k.storeKey)
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ParamsKey)
if bz == nil {
return params
return k.getLegacyParams(ctx)
}

k.cdc.MustUnmarshal(bz, &params)
Expand Down Expand Up @@ -45,3 +45,10 @@ func (k Keeper) GetCommunityTax(ctx sdk.Context) math.LegacyDec {
func (k Keeper) GetWithdrawAddrEnabled(ctx sdk.Context) (enabled bool) {
return k.GetParams(ctx).WithdrawAddrEnabled
}

// GetLegacyParams returns param set for version before migrate
func (k Keeper) getLegacyParams(ctx sdk.Context) types.Params {
var params types.Params
k.ss.GetParamSetIfExists(ctx, &params)
return params
}
9 changes: 9 additions & 0 deletions x/staking/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)

Expand All @@ -28,6 +29,7 @@ type Keeper struct {
bankKeeper types.BankKeeper
hooks types.StakingHooks
authority string
ss paramstypes.Subspace
}

// NewKeeper creates a new staking Keeper instance
Expand All @@ -37,6 +39,7 @@ func NewKeeper(
ak types.AccountKeeper,
bk types.BankKeeper,
authority string,
ss ...paramstypes.Subspace,
) *Keeper {
// ensure bonded and not bonded module accounts are set
if addr := ak.GetModuleAddress(types.BondedPoolName); addr == nil {
Expand All @@ -52,13 +55,19 @@ func NewKeeper(
panic("authority is not a valid acc address")
}

// ensure that a param subspace is provided
if len(ss) != 1 {
panic("must provide a param subspace")
}

return &Keeper{
storeKey: key,
cdc: cdc,
authKeeper: ak,
bankKeeper: bk,
hooks: nil,
authority: authority,
ss: ss[0],
}
}

Expand Down
9 changes: 8 additions & 1 deletion x/staking/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,16 @@ func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ParamsKey)
if bz == nil {
return params
return k.getLegacyParams(ctx)
}

k.cdc.MustUnmarshal(bz, &params)
return params
}

// GetLegacyParams returns param set for version before migrate
func (k Keeper) getLegacyParams(ctx sdk.Context) types.Params {
var params types.Params
k.ss.GetParamSetIfExists(ctx, &params)
return params
}
Loading