Skip to content

Commit

Permalink
refactor(assets,delegation): check case with flag
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxMustermann2 committed May 30, 2024
1 parent fb6364b commit 79df9e5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion x/assets/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (gs GenesisState) Validate() error {
// validate the stakerID
var stakerClientChainID uint64
var err error
if _, stakerClientChainID, err = ValidateID(stakerID, true); err != nil {
if _, stakerClientChainID, err = ValidateID(stakerID, true, true); err != nil {
return errorsmod.Wrapf(
ErrInvalidGenesisData,
"invalid stakerID: %s",
Expand Down
5 changes: 2 additions & 3 deletions x/assets/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@ func ParseID(key string) (string, uint64, error) {
return keys[0], id, nil
}

func ValidateID(key string, validateEth bool) (string, uint64, error) {
// check lowercase
if key != strings.ToLower(key) {
func ValidateID(key string, checkLowercase bool, validateEth bool) (string, uint64, error) {
if checkLowercase && key != strings.ToLower(key) {
return "", 0, errorsmod.Wrapf(ErrParseAssetsStateKey, "ID not lowercase: %s", key)
}
// parse it
Expand Down
8 changes: 6 additions & 2 deletions x/delegation/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ func (gs GenesisState) Validate() error {
// validate staker ID
var stakerClientChainID uint64
var err error
if _, stakerClientChainID, err = assetstypes.ValidateID(stakerID, true); err != nil {
if _, stakerClientChainID, err = assetstypes.ValidateID(
stakerID, true, true,
); err != nil {
return errorsmod.Wrapf(
ErrInvalidGenesisData, "invalid staker ID %s: %s", stakerID, err,
)
Expand All @@ -53,7 +55,9 @@ func (gs GenesisState) Validate() error {
assets[assetID] = struct{}{}
// validate asset ID
var assetClientChainID uint64
if _, assetClientChainID, err = assetstypes.ValidateID(assetID, true); err != nil {
if _, assetClientChainID, err = assetstypes.ValidateID(
assetID, true, true,
); err != nil {
return errorsmod.Wrapf(
ErrInvalidGenesisData, "invalid asset ID %s: %s", assetID, err,
)
Expand Down

0 comments on commit 79df9e5

Please sign in to comment.