Skip to content

Commit

Permalink
add: support for legacy params query
Browse files Browse the repository at this point in the history
  • Loading branch information
facs95 committed Sep 3, 2023
1 parent a3b98a4 commit 43d90e9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
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],

Check failure on line 55 in x/distribution/keeper/keeper.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)
}
}

Expand Down
8 changes: 8 additions & 0 deletions x/distribution/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,11 @@ func (k Keeper) GetCommunityTax(ctx sdk.Context) math.LegacyDec {
func (k Keeper) GetWithdrawAddrEnabled(ctx sdk.Context) (enabled bool) {
return k.GetParams(ctx).WithdrawAddrEnabled
}


Check failure on line 49 in x/distribution/keeper/params.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)
// GetLegacyParams returns param set for version before migrate
func (k Keeper) getLegacyParams(ctx sdk.Context) types.Params {

Check failure on line 51 in x/distribution/keeper/params.go

View workflow job for this annotation

GitHub Actions / Analyze

func `Keeper.getLegacyParams` is unused (unused)

Check failure on line 51 in x/distribution/keeper/params.go

View workflow job for this annotation

GitHub Actions / golangci-lint

func `Keeper.getLegacyParams` is unused (unused)
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
}

0 comments on commit 43d90e9

Please sign in to comment.