Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ica: genesis state validation #554

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
adding ValidateAccountAddress helper to reduce code duplication
  • Loading branch information
damiannolan committed Nov 29, 2021
commit 5686950a4759bab9073b5eb96c56ab7eb65fd818
18 changes: 4 additions & 14 deletions modules/apps/27-interchain-accounts/types/genesis.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package types

import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

host "github.com/cosmos/ibc-go/v2/modules/core/24-host"
)

Expand Down Expand Up @@ -66,12 +64,8 @@ func (gs ControllerGenesisState) Validate() error {
return err
}

if !IsValidAddr(acc.AccountAddress) || len(acc.AccountAddress) == 0 || len(acc.AccountAddress) > DefaultMaxAddrLength {
return sdkerrors.Wrapf(
ErrInvalidAccountAddress,
"address must contain strictly alphanumeric characters, not exceeding %d characters in length",
DefaultMaxAddrLength,
)
if err := ValidateAccountAddress(acc.AccountAddress); err != nil {
return err
}
}

Expand Down Expand Up @@ -117,12 +111,8 @@ func (gs HostGenesisState) Validate() error {
return err
}

if !IsValidAddr(acc.AccountAddress) || len(acc.AccountAddress) == 0 || len(acc.AccountAddress) > DefaultMaxAddrLength {
return sdkerrors.Wrapf(
ErrInvalidAccountAddress,
"address must contain strictly alphanumeric characters, not exceeding %d characters in length",
DefaultMaxAddrLength,
)
if err := ValidateAccountAddress(acc.AccountAddress); err != nil {
return err
}
}

Expand Down
12 changes: 11 additions & 1 deletion modules/apps/27-interchain-accounts/types/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,17 @@ func ValidateVersion(version string) error {
return sdkerrors.Wrapf(ErrInvalidVersion, "expected %s, got %s", VersionPrefix, s[0])
}

if !IsValidAddr(s[1]) || len(s[1]) == 0 || len(s[1]) > DefaultMaxAddrLength {
if err := ValidateAccountAddress(s[1]); err != nil {
return err
}

return nil
}

// ValidateAccountAddress performs basic validation of interchain account addresses, enforcing constraints
// on address length and character set
func ValidateAccountAddress(addr string) error {
if !IsValidAddr(addr) || len(addr) == 0 || len(addr) > DefaultMaxAddrLength {
return sdkerrors.Wrapf(
ErrInvalidAccountAddress,
"address must contain strictly alphanumeric characters, not exceeding %d characters in length",
Expand Down