2018-08-31 02:03:43 -07:00
|
|
|
package keeper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Default parameter namespace
|
|
|
|
const (
|
2018-09-18 04:16:20 -07:00
|
|
|
DefaultParamspace = "stake"
|
2018-08-31 02:03:43 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
// InflationRateChange - Maximum annual change in inflation rate
|
|
|
|
func (k Keeper) InflationRateChange(ctx sdk.Context) (res sdk.Dec) {
|
2018-09-17 08:28:13 -07:00
|
|
|
k.paramstore.Get(ctx, types.KeyInflationRateChange, &res)
|
2018-08-31 02:03:43 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// InflationMax - Maximum inflation rate
|
|
|
|
func (k Keeper) InflationMax(ctx sdk.Context) (res sdk.Dec) {
|
2018-09-17 08:28:13 -07:00
|
|
|
k.paramstore.Get(ctx, types.KeyInflationMax, &res)
|
2018-08-31 02:03:43 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// InflationMin - Minimum inflation rate
|
|
|
|
func (k Keeper) InflationMin(ctx sdk.Context) (res sdk.Dec) {
|
2018-09-17 08:28:13 -07:00
|
|
|
k.paramstore.Get(ctx, types.KeyInflationMin, &res)
|
2018-08-31 02:03:43 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// GoalBonded - Goal of percent bonded atoms
|
|
|
|
func (k Keeper) GoalBonded(ctx sdk.Context) (res sdk.Dec) {
|
2018-09-17 08:28:13 -07:00
|
|
|
k.paramstore.Get(ctx, types.KeyGoalBonded, &res)
|
2018-08-31 02:03:43 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnbondingTime
|
|
|
|
func (k Keeper) UnbondingTime(ctx sdk.Context) (res time.Duration) {
|
2018-09-17 08:28:13 -07:00
|
|
|
k.paramstore.Get(ctx, types.KeyUnbondingTime, &res)
|
2018-08-31 02:03:43 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// MaxValidators - Maximum number of validators
|
|
|
|
func (k Keeper) MaxValidators(ctx sdk.Context) (res uint16) {
|
2018-09-17 08:28:13 -07:00
|
|
|
k.paramstore.Get(ctx, types.KeyMaxValidators, &res)
|
2018-08-31 02:03:43 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// BondDenom - Bondable coin denomination
|
|
|
|
func (k Keeper) BondDenom(ctx sdk.Context) (res string) {
|
2018-09-17 08:28:13 -07:00
|
|
|
k.paramstore.Get(ctx, types.KeyBondDenom, &res)
|
2018-08-31 02:03:43 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get all parameteras as types.Params
|
|
|
|
func (k Keeper) GetParams(ctx sdk.Context) (res types.Params) {
|
|
|
|
res.InflationRateChange = k.InflationRateChange(ctx)
|
|
|
|
res.InflationMax = k.InflationMax(ctx)
|
|
|
|
res.InflationMin = k.InflationMin(ctx)
|
|
|
|
res.GoalBonded = k.GoalBonded(ctx)
|
|
|
|
res.UnbondingTime = k.UnbondingTime(ctx)
|
|
|
|
res.MaxValidators = k.MaxValidators(ctx)
|
|
|
|
res.BondDenom = k.BondDenom(ctx)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Need a distinct function because setParams depends on an existing previous
|
|
|
|
// record of params to exist (to check if maxValidators has changed) - and we
|
|
|
|
// panic on retrieval if it doesn't exist - hence if we use setParams for the very
|
|
|
|
// first params set it will panic.
|
|
|
|
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
|
|
|
|
if k.MaxValidators(ctx) != params.MaxValidators {
|
|
|
|
k.UpdateBondedValidatorsFull(ctx)
|
|
|
|
}
|
|
|
|
k.SetNewParams(ctx, params)
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the params without updating validator set
|
|
|
|
func (k Keeper) SetNewParams(ctx sdk.Context, params types.Params) {
|
2018-09-18 09:27:54 -07:00
|
|
|
k.paramstore.SetStruct(ctx, ¶ms)
|
2018-08-31 02:03:43 -07:00
|
|
|
}
|