diff --git a/x/gov/keeper.go b/x/gov/keeper.go index 0e87ec123..fbdf79555 100644 --- a/x/gov/keeper.go +++ b/x/gov/keeper.go @@ -7,21 +7,16 @@ import ( "github.com/cosmos/cosmos-sdk/x/params" ) -// nolint +// Parameter store default namespace const ( DefaultParamSpace = "gov" ) -// nolint - Paramstore key constructor -func ParamStoreKeyDepositProcedure() params.Key { return params.NewKey([]byte("depositprocedure")) } -func ParamStoreKeyVotingProcedure() params.Key { return params.NewKey([]byte("votingprocedure")) } -func ParamStoreKeyTallyingProcedure() params.Key { return params.NewKey([]byte("tallyingprocedure")) } - -// Cached parameter store keys -var ( - paramStoreKeyDepositProcedure = ParamStoreKeyDepositProcedure() - paramStoreKeyVotingProcedure = ParamStoreKeyVotingProcedure() - paramStoreKeyTallyingProcedure = ParamStoreKeyTallyingProcedure() +// Parameter store key +const ( + ParamStoreKeyDepositProcedure = "depositprocedure" + ParamStoreKeyVotingProcedure = "votingprocedure" + ParamStoreKeyTallyingProcedure = "tallyingprocedure" ) // Governance Keeper @@ -224,7 +219,7 @@ func (keeper Keeper) activateVotingPeriod(ctx sdk.Context, proposal Proposal) { // nolint: errcheck func (keeper Keeper) GetDepositProcedure(ctx sdk.Context) DepositProcedure { var depositProcedure DepositProcedure - keeper.ps.Get(ctx, paramStoreKeyDepositProcedure, &depositProcedure) + keeper.ps.Get(ctx, ParamStoreKeyDepositProcedure, &depositProcedure) return depositProcedure } @@ -232,7 +227,7 @@ func (keeper Keeper) GetDepositProcedure(ctx sdk.Context) DepositProcedure { // nolint: errcheck func (keeper Keeper) GetVotingProcedure(ctx sdk.Context) VotingProcedure { var votingProcedure VotingProcedure - keeper.ps.Get(ctx, paramStoreKeyVotingProcedure, &votingProcedure) + keeper.ps.Get(ctx, ParamStoreKeyVotingProcedure, &votingProcedure) return votingProcedure } @@ -240,23 +235,23 @@ func (keeper Keeper) GetVotingProcedure(ctx sdk.Context) VotingProcedure { // nolint: errcheck func (keeper Keeper) GetTallyingProcedure(ctx sdk.Context) TallyingProcedure { var tallyingProcedure TallyingProcedure - keeper.ps.Get(ctx, paramStoreKeyTallyingProcedure, &tallyingProcedure) + keeper.ps.Get(ctx, ParamStoreKeyTallyingProcedure, &tallyingProcedure) return tallyingProcedure } // nolint: errcheck func (keeper Keeper) setDepositProcedure(ctx sdk.Context, depositProcedure DepositProcedure) { - keeper.ps.Set(ctx, paramStoreKeyDepositProcedure, &depositProcedure) + keeper.ps.Set(ctx, ParamStoreKeyDepositProcedure, &depositProcedure) } // nolint: errcheck func (keeper Keeper) setVotingProcedure(ctx sdk.Context, votingProcedure VotingProcedure) { - keeper.ps.Set(ctx, paramStoreKeyVotingProcedure, &votingProcedure) + keeper.ps.Set(ctx, ParamStoreKeyVotingProcedure, &votingProcedure) } // nolint: errcheck func (keeper Keeper) setTallyingProcedure(ctx sdk.Context, tallyingProcedure TallyingProcedure) { - keeper.ps.Set(ctx, paramStoreKeyTallyingProcedure, &tallyingProcedure) + keeper.ps.Set(ctx, ParamStoreKeyTallyingProcedure, &tallyingProcedure) } // ===================================================== diff --git a/x/params/client/utils/utils.go b/x/params/client/utils/utils.go index edd6375df..d2c2040e6 100644 --- a/x/params/client/utils/utils.go +++ b/x/params/client/utils/utils.go @@ -13,7 +13,7 @@ func QueryParams(cliCtx context.CLIContext, subStoreName string, ps params.Param m := make(map[string][]byte) for _, p := range ps.KeyFieldPairs() { - key := p.Key.String() + key := p.Key bz, err := cliCtx.QueryStore([]byte(subStoreName+"/"+key), storeName) if err != nil { return err diff --git a/x/params/doc.go b/x/params/doc.go new file mode 100644 index 000000000..1843abce9 --- /dev/null +++ b/x/params/doc.go @@ -0,0 +1,14 @@ +package params + +/* +Package params provides a globally available parameter store . + +There are two main types, Keeper and Space. Space is an isolated namespace, prefixed by preconfigured spacename. Keeper has a permission to access all existing spaces and create new space. + +Space can be used by the individual keepers, who needs a private parameter store that the other keeper are not able to modify. Keeper can be used by the Governance keeper, who need to modify any parameter in case of the proposal passes. + +Basic Usage: + + + +*/ diff --git a/x/params/keeper_test.go b/x/params/keeper_test.go index 99a5ebf18..a733a97d9 100644 --- a/x/params/keeper_test.go +++ b/x/params/keeper_test.go @@ -36,16 +36,16 @@ func createTestCodec() *codec.Codec { func TestKeeper(t *testing.T) { kvs := []struct { - key Key + key string param int64 }{ - {NewKey([]byte("key1")), 10}, - {NewKey([]byte("key2")), 55}, - {NewKey([]byte("key3")), 182}, - {NewKey([]byte("key4")), 17582}, - {NewKey([]byte("key5")), 2768554}, - {NewKey([]byte("space1"), []byte("key1")), 1157279}, - {NewKey([]byte("space1"), []byte("key2")), 9058701}, + {"key1", 10}, + {"key2", 55}, + {"key3", 182}, + {"key4", 17582}, + {"key5", 2768554}, + {"space1/key1", 1157279}, + {"space1/key2", 9058701}, } skey := sdk.NewKVStoreKey("test") @@ -91,19 +91,19 @@ func TestGet(t *testing.T) { space := keeper.Subspace("test") kvs := []struct { - key Key + key string param interface{} zero interface{} ptr interface{} }{ - {NewKey([]byte("string")), "test", "", new(string)}, - {NewKey([]byte("bool")), true, false, new(bool)}, - {NewKey([]byte("int16")), int16(1), int16(0), new(int16)}, - {NewKey([]byte("int32")), int32(1), int32(0), new(int32)}, - {NewKey([]byte("int64")), int64(1), int64(0), new(int64)}, - {NewKey([]byte("uint16")), uint16(1), uint16(0), new(uint16)}, - {NewKey([]byte("uint32")), uint32(1), uint32(0), new(uint32)}, - {NewKey([]byte("uint64")), uint64(1), uint64(0), new(uint64)}, + {"string", "test", "", new(string)}, + {"bool", true, false, new(bool)}, + {"int16", int16(1), int16(0), new(int16)}, + {"int32", int32(1), int32(0), new(int32)}, + {"int64", int64(1), int64(0), new(int64)}, + {"uint16", uint16(1), uint16(0), new(uint16)}, + {"uint32", uint32(1), uint32(0), new(uint32)}, + {"uint64", uint64(1), uint64(0), new(uint64)}, /* {NewKey("int"), sdk.NewInt(1), *new(sdk.Int), new(sdk.Int)}, {NewKey("uint"), sdk.NewUint(1), *new(sdk.Uint), new(sdk.Uint)}, @@ -116,9 +116,9 @@ func TestGet(t *testing.T) { } for _, kv := range kvs { - require.NotPanics(t, func() { space.GetIfExists(ctx, NewKey([]byte("invalid")), kv.ptr) }) + require.NotPanics(t, func() { space.GetIfExists(ctx, "invalid", kv.ptr) }) require.Equal(t, kv.zero, reflect.ValueOf(kv.ptr).Elem().Interface()) - require.Panics(t, func() { space.Get(ctx, NewKey([]byte("invalid")), kv.ptr) }) + require.Panics(t, func() { space.Get(ctx, "invalid", kv.ptr) }) require.Equal(t, kv.zero, reflect.ValueOf(kv.ptr).Elem().Interface()) require.NotPanics(t, func() { space.GetIfExists(ctx, kv.key, kv.ptr) }) @@ -126,7 +126,7 @@ func TestGet(t *testing.T) { require.NotPanics(t, func() { space.Get(ctx, kv.key, kv.ptr) }) require.Equal(t, kv.param, reflect.ValueOf(kv.ptr).Elem().Interface()) - require.Panics(t, func() { space.Get(ctx, NewKey([]byte("invalid")), kv.ptr) }) + require.Panics(t, func() { space.Get(ctx, "invalid", kv.ptr) }) require.Equal(t, kv.param, reflect.ValueOf(kv.ptr).Elem().Interface()) require.Panics(t, func() { space.Get(ctx, kv.key, nil) }) diff --git a/x/params/space.go b/x/params/space.go index 5d9353e47..22e2a41ab 100644 --- a/x/params/space.go +++ b/x/params/space.go @@ -8,15 +8,9 @@ import ( // nolint - reexport type Space = space.Space type ReadOnlySpace = space.ReadOnlySpace -type Key = space.Key -type KeyFieldPair = space.KeyFieldPair -type KeyFieldPairs = space.KeyFieldPairs type ParamStruct = space.ParamStruct +type KeyFieldPairs = space.KeyFieldPairs -// nolint - reexport -func NewKey(keys ...[]byte) Key { - return space.NewKey(keys...) -} func UnmarshalParamsFromMap(m map[string][]byte, cdc *codec.Codec, ps space.ParamStruct) error { return space.UnmarshalParamsFromMap(m, cdc, ps) } diff --git a/x/params/space/key.go b/x/params/space/key.go deleted file mode 100644 index 13966a0bb..000000000 --- a/x/params/space/key.go +++ /dev/null @@ -1,73 +0,0 @@ -package space - -import ( - "github.com/cosmos/cosmos-sdk/codec" -) - -// Wrapper for key string -type Key struct { - s []byte -} - -// Appending two keys with '/' as separator -// Checks alphanumericity -func (k Key) Append(keys ...[]byte) (res Key) { - res.s = make([]byte, len(k.s)) - copy(res.s, k.s) - - for _, key := range keys { - for _, b := range key { - if !(32 <= b && b <= 126) { - panic("parameter key expressions can only contain alphanumeric characters") - } - } - res.s = append(append(res.s, byte('/')), key...) - } - return -} - -// NewKey constructs a key from a list of strings -func NewKey(keys ...[]byte) (res Key) { - if len(keys) < 1 { - panic("length of parameter keys must not be zero") - } - res = Key{keys[0]} - - return res.Append(keys[1:]...) -} - -// KeyBytes make KVStore key bytes from Key -func (k Key) Bytes() []byte { - return k.s -} - -// Human readable string -func (k Key) String() string { - return string(k.s) -} - -// Used for associating paramstore key and field of param structs -type KeyFieldPair struct { - Key Key - Field interface{} -} - -// Slice of KeyFieldPair -type KeyFieldPairs []KeyFieldPair - -// Interface for structs containing parameters for a module -type ParamStruct interface { - KeyFieldPairs() KeyFieldPairs -} - -// Takes a map from key string to byte slice and -// unmarshalles it to ParamStruct -func UnmarshalParamsFromMap(m map[string][]byte, cdc *codec.Codec, ps ParamStruct) error { - for _, p := range ps.KeyFieldPairs() { - err := cdc.UnmarshalJSON(m[p.Key.String()], p.Field) - if err != nil { - return err - } - } - return nil -} diff --git a/x/params/space/pair.go b/x/params/space/pair.go new file mode 100644 index 000000000..c37c599fe --- /dev/null +++ b/x/params/space/pair.go @@ -0,0 +1,31 @@ +package space + +import ( + "github.com/cosmos/cosmos-sdk/codec" +) + +// Used for associating paramstore key and field of param structs +type KeyFieldPair struct { + Key string + Field interface{} +} + +// Slice of KeyFieldPair +type KeyFieldPairs []KeyFieldPair + +// Interface for structs containing parameters for a module +type ParamStruct interface { + KeyFieldPairs() KeyFieldPairs +} + +// Takes a map from key string to byte slice and +// unmarshalles it to ParamStruct +func UnmarshalParamsFromMap(m map[string][]byte, cdc *codec.Codec, ps ParamStruct) error { + for _, p := range ps.KeyFieldPairs() { + err := cdc.UnmarshalJSON(m[p.Key], p.Field) + if err != nil { + return err + } + } + return nil +} diff --git a/x/params/space/space.go b/x/params/space/space.go index 817468579..ca3757f44 100644 --- a/x/params/space/space.go +++ b/x/params/space/space.go @@ -35,9 +35,9 @@ func NewSpace(cdc *codec.Codec, key sdk.StoreKey, tkey sdk.StoreKey, space strin } // Get parameter from store -func (s Space) Get(ctx sdk.Context, key Key, ptr interface{}) { +func (s Space) Get(ctx sdk.Context, key string, ptr interface{}) { store := ctx.KVStore(s.key).Prefix(s.space) - bz := store.Get(key.Bytes()) + bz := store.Get([]byte(key)) err := s.cdc.UnmarshalJSON(bz, ptr) if err != nil { panic(err) @@ -45,9 +45,9 @@ func (s Space) Get(ctx sdk.Context, key Key, ptr interface{}) { } // GetIfExists do not modify ptr if the stored parameter is nil -func (s Space) GetIfExists(ctx sdk.Context, key Key, ptr interface{}) { +func (s Space) GetIfExists(ctx sdk.Context, key string, ptr interface{}) { store := ctx.KVStore(s.key).Prefix(s.space) - bz := store.Get(key.Bytes()) + bz := store.Get([]byte(key)) if bz == nil { return } @@ -58,28 +58,28 @@ func (s Space) GetIfExists(ctx sdk.Context, key Key, ptr interface{}) { } // Get raw bytes of parameter from store -func (s Space) GetRaw(ctx sdk.Context, key Key) []byte { +func (s Space) GetRaw(ctx sdk.Context, key string) []byte { store := ctx.KVStore(s.key).Prefix(s.space) - res := store.Get(key.Bytes()) + res := store.Get([]byte(key)) return res } // Check if the parameter is set in the store -func (s Space) Has(ctx sdk.Context, key Key) bool { +func (s Space) Has(ctx sdk.Context, key string) bool { store := ctx.KVStore(s.key).Prefix(s.space) - return store.Has(key.Bytes()) + return store.Has([]byte(key)) } // Returns true if the parameter is set in the block -func (s Space) Modified(ctx sdk.Context, key Key) bool { +func (s Space) Modified(ctx sdk.Context, key string) bool { tstore := ctx.KVStore(s.tkey).Prefix(s.space) - return tstore.Has(key.Bytes()) + return tstore.Has([]byte(key)) } // Set parameter, return error if stored parameter has different type from input -func (s Space) Set(ctx sdk.Context, key Key, param interface{}) { +func (s Space) Set(ctx sdk.Context, key string, param interface{}) { store := ctx.KVStore(s.key).Prefix(s.space) - keybz := key.Bytes() + keybz := []byte(key) bz := store.Get(keybz) if bz != nil { @@ -102,8 +102,8 @@ func (s Space) Set(ctx sdk.Context, key Key, param interface{}) { } // Set raw bytes of parameter -func (s Space) SetRaw(ctx sdk.Context, key Key, param []byte) { - keybz := key.Bytes() +func (s Space) SetRaw(ctx sdk.Context, key string, param []byte) { + keybz := []byte(key) store := ctx.KVStore(s.key).Prefix(s.space) store.Set(keybz, param) @@ -112,6 +112,13 @@ func (s Space) SetRaw(ctx sdk.Context, key Key, param []byte) { tstore.Set(keybz, []byte{}) } +// Set from ParamStruct +func (s Space) SetFromParamStruct(ctx sdk.Context, ps ParamStruct) { + for _, pair := range ps.KeyFieldPairs() { + s.Set(ctx, pair.Key, pair.Field) + } +} + // Returns a KVStore identical with the paramspace func (s Space) KVStore(ctx sdk.Context) sdk.KVStore { return ctx.KVStore(s.key).Prefix(s.space) @@ -123,21 +130,21 @@ type ReadOnlySpace struct { } // Exposes Get -func (ros ReadOnlySpace) Get(ctx sdk.Context, key Key, ptr interface{}) { +func (ros ReadOnlySpace) Get(ctx sdk.Context, key string, ptr interface{}) { ros.s.Get(ctx, key, ptr) } // Exposes GetRaw -func (ros ReadOnlySpace) GetRaw(ctx sdk.Context, key Key) []byte { +func (ros ReadOnlySpace) GetRaw(ctx sdk.Context, key string) []byte { return ros.s.GetRaw(ctx, key) } // Exposes Has -func (ros ReadOnlySpace) Has(ctx sdk.Context, key Key) bool { +func (ros ReadOnlySpace) Has(ctx sdk.Context, key string) bool { return ros.s.Has(ctx, key) } // Exposes Modified -func (ros ReadOnlySpace) Modified(ctx sdk.Context, key Key) bool { +func (ros ReadOnlySpace) Modified(ctx sdk.Context, key string) bool { return ros.s.Modified(ctx, key) } diff --git a/x/slashing/genesis.go b/x/slashing/genesis.go index 7da9b313c..e5a58ba0a 100644 --- a/x/slashing/genesis.go +++ b/x/slashing/genesis.go @@ -21,15 +21,8 @@ func DefaultGenesisState() GenesisState { // and the keeper's address to pubkey map func InitGenesis(ctx sdk.Context, keeper Keeper, data GenesisState, sdata types.GenesisState) { for _, validator := range sdata.Validators { - keeper.addPubkey(ctx, validator.GetPubKey()) + keeper.addPubkey(ctx, validator.KeyGetPub()) } - p := data.Params - keeper.paramstore.Set(ctx, maxEvidenceAgeKey, p.MaxEvidenceAge) - keeper.paramstore.Set(ctx, signedBlocksWindowKey, p.SignedBlocksWindow) - keeper.paramstore.Set(ctx, minSignedPerWindowKey, p.MinSignedPerWindow) - keeper.paramstore.Set(ctx, doubleSignUnbondDurationKey, p.DoubleSignUnbondDuration) - keeper.paramstore.Set(ctx, downtimeUnbondDurationKey, p.DowntimeUnbondDuration) - keeper.paramstore.Set(ctx, slashFractionDoubleSignKey, p.SlashFractionDoubleSign) - keeper.paramstore.Set(ctx, slashFractionDowntimeKey, p.SlashFractionDowntime) + keeper.paramstore.SetFromParamStruct(data.Params) } diff --git a/x/slashing/params.go b/x/slashing/params.go index 4e5a76220..2cd334734 100644 --- a/x/slashing/params.go +++ b/x/slashing/params.go @@ -4,8 +4,6 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/cosmos/cosmos-sdk/x/params" ) // Default parameter namespace @@ -13,26 +11,15 @@ const ( DefaultParamSpace = "slashing" ) -// nolint - Key generators for parameter access -func MaxEvidenceAgeKey() params.Key { return params.NewKey([]byte("MaxEvidenceAge")) } -func SignedBlocksWindowKey() params.Key { return params.NewKey([]byte("SignedBlocksWindow")) } -func MinSignedPerWindowKey() params.Key { return params.NewKey([]byte("MinSignedPerWindow")) } -func DoubleSignUnbondDurationKey() params.Key { - return params.NewKey([]byte("DoubleSignUnbondDuration")) -} -func DowntimeUnbondDurationKey() params.Key { return params.NewKey([]byte("DowntimeUnbondDuration")) } -func SlashFractionDoubleSignKey() params.Key { return params.NewKey([]byte("SlashFractionDoubleSign")) } -func SlashFractionDowntimeKey() params.Key { return params.NewKey([]byte("SlashFractionDowntime")) } - -// Cached parameter keys -var ( - maxEvidenceAgeKey = MaxEvidenceAgeKey() - signedBlocksWindowKey = SignedBlocksWindowKey() - minSignedPerWindowKey = MinSignedPerWindowKey() - doubleSignUnbondDurationKey = DoubleSignUnbondDurationKey() - downtimeUnbondDurationKey = DowntimeUnbondDurationKey() - slashFractionDoubleSignKey = SlashFractionDoubleSignKey() - slashFractionDowntimeKey = SlashFractionDowntimeKey() +// Parameter store key +const ( + KeyMaxEvidenceAge = "MaxEvidenceAge" + KeySignedBlocksWindow = "SignedBlocksWindow" + KeyMinSignedPerWindow = "MinSignedPerWindow" + KeyDoubleSignUnbondDuration = "DoubleSignUnbondDuration" + KeyDowntimeUnbondDuration = "DowntimeUnbondDuration" + KeySlashFractionDoubleSign = "SlashFractionDoubleSign" + KeySlashFractionDowntime = "SlashFractionDowntime" ) // Params - used for initializing default parameter for slashing at genesis @@ -73,44 +60,44 @@ func DefaultParams() Params { // MaxEvidenceAge - Max age for evidence - 21 days (3 weeks) // MaxEvidenceAge = 60 * 60 * 24 * 7 * 3 func (k Keeper) MaxEvidenceAge(ctx sdk.Context) (res time.Duration) { - k.paramstore.Get(ctx, maxEvidenceAgeKey, &res) + k.paramstore.Get(ctx, KeyMaxEvidenceAge, &res) return } // SignedBlocksWindow - sliding window for downtime slashing func (k Keeper) SignedBlocksWindow(ctx sdk.Context) (res int64) { - k.paramstore.Get(ctx, signedBlocksWindowKey, &res) + k.paramstore.Get(ctx, KeySignedBlocksWindow, &res) return } // Downtime slashing thershold - default 50% of the SignedBlocksWindow func (k Keeper) MinSignedPerWindow(ctx sdk.Context) int64 { var minSignedPerWindow sdk.Dec - k.paramstore.Get(ctx, minSignedPerWindowKey, &minSignedPerWindow) + k.paramstore.Get(ctx, KeyMinSignedPerWindow, &minSignedPerWindow) signedBlocksWindow := k.SignedBlocksWindow(ctx) return sdk.NewDec(signedBlocksWindow).Mul(minSignedPerWindow).RoundInt64() } // Double-sign unbond duration func (k Keeper) DoubleSignUnbondDuration(ctx sdk.Context) (res time.Duration) { - k.paramstore.Get(ctx, doubleSignUnbondDurationKey, &res) + k.paramstore.Get(ctx, KeyDoubleSignUnbondDuration, &res) return } // Downtime unbond duration func (k Keeper) DowntimeUnbondDuration(ctx sdk.Context) (res time.Duration) { - k.paramstore.Get(ctx, downtimeUnbondDurationKey, &res) + k.paramstore.Get(ctx, KeyDowntimeUnbondDuration, &res) return } // SlashFractionDoubleSign - currently default 5% func (k Keeper) SlashFractionDoubleSign(ctx sdk.Context) (res sdk.Dec) { - k.paramstore.Get(ctx, slashFractionDoubleSignKey, &res) + k.paramstore.Get(ctx, KeySlashFractionDoubleSign, &res) return } // SlashFractionDowntime - currently default 1% func (k Keeper) SlashFractionDowntime(ctx sdk.Context) (res sdk.Dec) { - k.paramstore.Get(ctx, slashFractionDowntimeKey, &res) + k.paramstore.Get(ctx, KeySlashFractionDowntime, &res) return } diff --git a/x/stake/keeper/params.go b/x/stake/keeper/params.go index b44201140..a6b1eec1f 100644 --- a/x/stake/keeper/params.go +++ b/x/stake/keeper/params.go @@ -12,56 +12,45 @@ const ( DefaultParamSpace = "stake" ) -// Cached parameter keys -var ( - keyInflationRateChange = types.KeyInflationRateChange() - keyInflationMax = types.KeyInflationMax() - keyInflationMin = types.KeyInflationMin() - keyGoalBonded = types.KeyGoalBonded() - keyUnbondingTime = types.KeyUnbondingTime() - keyMaxValidators = types.KeyMaxValidators() - keyBondDenom = types.KeyBondDenom() -) - // InflationRateChange - Maximum annual change in inflation rate func (k Keeper) InflationRateChange(ctx sdk.Context) (res sdk.Dec) { - k.paramstore.Get(ctx, keyInflationRateChange, &res) + k.paramstore.Get(ctx, types.KeyInflationRateChange, &res) return } // InflationMax - Maximum inflation rate func (k Keeper) InflationMax(ctx sdk.Context) (res sdk.Dec) { - k.paramstore.Get(ctx, keyInflationMax, &res) + k.paramstore.Get(ctx, types.KeyInflationMax, &res) return } // InflationMin - Minimum inflation rate func (k Keeper) InflationMin(ctx sdk.Context) (res sdk.Dec) { - k.paramstore.Get(ctx, keyInflationMin, &res) + k.paramstore.Get(ctx, types.KeyInflationMin, &res) return } // GoalBonded - Goal of percent bonded atoms func (k Keeper) GoalBonded(ctx sdk.Context) (res sdk.Dec) { - k.paramstore.Get(ctx, keyGoalBonded, &res) + k.paramstore.Get(ctx, types.KeyGoalBonded, &res) return } // UnbondingTime func (k Keeper) UnbondingTime(ctx sdk.Context) (res time.Duration) { - k.paramstore.Get(ctx, keyUnbondingTime, &res) + k.paramstore.Get(ctx, types.KeyUnbondingTime, &res) return } // MaxValidators - Maximum number of validators func (k Keeper) MaxValidators(ctx sdk.Context) (res uint16) { - k.paramstore.Get(ctx, keyMaxValidators, &res) + k.paramstore.Get(ctx, types.KeyMaxValidators, &res) return } // BondDenom - Bondable coin denomination func (k Keeper) BondDenom(ctx sdk.Context) (res string) { - k.paramstore.Get(ctx, keyBondDenom, &res) + k.paramstore.Get(ctx, types.KeyBondDenom, &res) return } @@ -90,11 +79,11 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { // set the params without updating validator set func (k Keeper) SetNewParams(ctx sdk.Context, params types.Params) { - k.paramstore.Set(ctx, keyInflationRateChange, params.InflationRateChange) - k.paramstore.Set(ctx, keyInflationMax, params.InflationMax) - k.paramstore.Set(ctx, keyInflationMin, params.InflationMin) - k.paramstore.Set(ctx, keyGoalBonded, params.GoalBonded) - k.paramstore.Set(ctx, keyUnbondingTime, params.UnbondingTime) - k.paramstore.Set(ctx, keyMaxValidators, params.MaxValidators) - k.paramstore.Set(ctx, keyBondDenom, params.BondDenom) + k.paramstore.Set(ctx, types.KeyInflationRateChange, params.InflationRateChange) + k.paramstore.Set(ctx, types.KeyInflationMax, params.InflationMax) + k.paramstore.Set(ctx, types.KeyInflationMin, params.InflationMin) + k.paramstore.Set(ctx, types.KeyGoalBonded, params.GoalBonded) + k.paramstore.Set(ctx, types.KeyUnbondingTime, params.UnbondingTime) + k.paramstore.Set(ctx, types.KeyMaxValidators, params.MaxValidators) + k.paramstore.Set(ctx, types.KeyBondDenom, params.BondDenom) } diff --git a/x/stake/types/params.go b/x/stake/types/params.go index a38a79cb2..c1a062df8 100644 --- a/x/stake/types/params.go +++ b/x/stake/types/params.go @@ -14,14 +14,16 @@ import ( // unbonding time. const defaultUnbondingTime time.Duration = 60 * 60 * 24 * 3 * time.Second -// nolint - Key generators for parameter access -func KeyInflationRateChange() params.Key { return params.NewKey([]byte("InflationRateChange")) } -func KeyInflationMax() params.Key { return params.NewKey([]byte("InflationMax")) } -func KeyInflationMin() params.Key { return params.NewKey([]byte("InflationMin")) } -func KeyGoalBonded() params.Key { return params.NewKey([]byte("GoalBonded")) } -func KeyUnbondingTime() params.Key { return params.NewKey([]byte("UnbondingTime")) } -func KeyMaxValidators() params.Key { return params.NewKey([]byte("MaxValidators")) } -func KeyBondDenom() params.Key { return params.NewKey([]byte("BondDenom")) } +// nolint - Keys for parameter access +const ( + KeyInflationRateChange = "InflationRateChange" + KeyInflationMax = "InflationMax" + KeyInflationMin = "InflationMin" + KeyGoalBonded = "GoalBonded" + KeyUnbondingTime = "UnbondingTime" + KeyMaxValidators = "MaxValidators" + KeyBondDenom = "BondDenom" +) // Params defines the high level settings for staking type Params struct { @@ -39,13 +41,13 @@ type Params struct { // Implements params.ParamStruct func (p *Params) KeyFieldPairs() params.KeyFieldPairs { return params.KeyFieldPairs{ - {KeyInflationRateChange(), &p.InflationRateChange}, - {KeyInflationMax(), &p.InflationMax}, - {KeyInflationMin(), &p.InflationMin}, - {KeyGoalBonded(), &p.GoalBonded}, - {KeyUnbondingTime(), &p.UnbondingTime}, - {KeyMaxValidators(), &p.MaxValidators}, - {KeyBondDenom(), &p.BondDenom}, + {KeyInflationRateChange, &p.InflationRateChange}, + {KeyInflationMax, &p.InflationMax}, + {KeyInflationMin, &p.InflationMin}, + {KeyGoalBonded, &p.GoalBonded}, + {KeyUnbondingTime, &p.UnbondingTime}, + {KeyMaxValidators, &p.MaxValidators}, + {KeyBondDenom, &p.BondDenom}, } }