From 6d80faface22a5ef07c638b946ec6a9d7fbf0662 Mon Sep 17 00:00:00 2001 From: mossid Date: Tue, 11 Sep 2018 00:08:04 +0900 Subject: [PATCH] string -> []byte --- x/gov/keeper.go | 6 +++--- x/params/space.go | 2 +- x/params/space/key.go | 14 +++++++------- x/slashing/params.go | 16 +++++++++------- x/stake/types/params.go | 14 +++++++------- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/x/gov/keeper.go b/x/gov/keeper.go index 313cad28d8..0e87ec1232 100644 --- a/x/gov/keeper.go +++ b/x/gov/keeper.go @@ -13,9 +13,9 @@ const ( ) // nolint - Paramstore key constructor -func ParamStoreKeyDepositProcedure() params.Key { return params.NewKey("depositprocedure") } -func ParamStoreKeyVotingProcedure() params.Key { return params.NewKey("votingprocedure") } -func ParamStoreKeyTallyingProcedure() params.Key { return params.NewKey("tallyingprocedure") } +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 ( diff --git a/x/params/space.go b/x/params/space.go index 8d7f450853..5d9353e476 100644 --- a/x/params/space.go +++ b/x/params/space.go @@ -14,7 +14,7 @@ type KeyFieldPairs = space.KeyFieldPairs type ParamStruct = space.ParamStruct // nolint - reexport -func NewKey(keys ...string) Key { +func NewKey(keys ...[]byte) Key { return space.NewKey(keys...) } func UnmarshalParamsFromMap(m map[string][]byte, cdc *codec.Codec, ps space.ParamStruct) error { diff --git a/x/params/space/key.go b/x/params/space/key.go index 64ac501671..41fc30e2f1 100644 --- a/x/params/space/key.go +++ b/x/params/space/key.go @@ -1,8 +1,6 @@ package space import ( - tmlibs "github.com/tendermint/tendermint/libs/common" - "github.com/cosmos/cosmos-sdk/codec" ) @@ -13,21 +11,23 @@ type Key struct { // Appending two keys with '/' as separator // Checks alphanumericity -func (k Key) Append(keys ...string) (res Key) { +func (k Key) Append(keys ...[]byte) (res Key) { res.s = make([]byte, len(k.s)) copy(res.s, k.s) for _, key := range keys { - if !tmlibs.IsASCIIText(key) { - panic("parameter key expressions can only contain alphanumeric characters") + 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('/')), []byte(key)...) + res.s = append(append(res.s, byte('/')), key...) } return } // NewKey constructs a key from a list of strings -func NewKey(keys ...string) (res Key) { +func NewKey(keys ...[]byte) (res Key) { if len(keys) < 1 { panic("length of parameter keys must not be zero") } diff --git a/x/slashing/params.go b/x/slashing/params.go index 6f6755d33d..4e5a762209 100644 --- a/x/slashing/params.go +++ b/x/slashing/params.go @@ -14,13 +14,15 @@ const ( ) // nolint - Key generators for parameter access -func MaxEvidenceAgeKey() params.Key { return params.NewKey("MaxEvidenceAge") } -func SignedBlocksWindowKey() params.Key { return params.NewKey("SignedBlocksWindow") } -func MinSignedPerWindowKey() params.Key { return params.NewKey("MinSignedPerWindow") } -func DoubleSignUnbondDurationKey() params.Key { return params.NewKey("DoubleSignUnbondDuration") } -func DowntimeUnbondDurationKey() params.Key { return params.NewKey("DowntimeUnbondDuration") } -func SlashFractionDoubleSignKey() params.Key { return params.NewKey("SlashFractionDoubleSign") } -func SlashFractionDowntimeKey() params.Key { return params.NewKey("SlashFractionDowntime") } +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 ( diff --git a/x/stake/types/params.go b/x/stake/types/params.go index de963a56bd..a38a79cb2b 100644 --- a/x/stake/types/params.go +++ b/x/stake/types/params.go @@ -15,13 +15,13 @@ import ( const defaultUnbondingTime time.Duration = 60 * 60 * 24 * 3 * time.Second // nolint - Key generators for parameter access -func KeyInflationRateChange() params.Key { return params.NewKey("InflationRateChange") } -func KeyInflationMax() params.Key { return params.NewKey("InflationMax") } -func KeyInflationMin() params.Key { return params.NewKey("InflationMin") } -func KeyGoalBonded() params.Key { return params.NewKey("GoalBonded") } -func KeyUnbondingTime() params.Key { return params.NewKey("UnbondingTime") } -func KeyMaxValidators() params.Key { return params.NewKey("MaxValidators") } -func KeyBondDenom() params.Key { return params.NewKey("BondDenom") } +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")) } // Params defines the high level settings for staking type Params struct {