From 97502afa1f07bd8f8830ecf384d435408042dbae Mon Sep 17 00:00:00 2001 From: Michael Tsitrin <114929630+mtsitrin@users.noreply.github.com> Date: Mon, 10 Jul 2023 14:02:28 +0300 Subject: [PATCH] fix: using evmos validation for rollappID (#222) --- config/chainid.go | 27 +++++++++++++++++++++++++++ config/config.go | 10 ---------- 2 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 config/chainid.go diff --git a/config/chainid.go b/config/chainid.go new file mode 100644 index 00000000..0f97d891 --- /dev/null +++ b/config/chainid.go @@ -0,0 +1,27 @@ +package config + +import ( + "fmt" + "regexp" +) + +var ( + regexChainID = `[a-z]{1,}` + regexEIP155Separator = `_{1}` + regexEIP155 = `[1-9][0-9]*` + regexEpochSeparator = `-{1}` + regexEpoch = `[1-9][0-9]*` + rollappID = regexp.MustCompile(fmt.Sprintf(`^(%s)%s(%s)%s(%s)$`, + regexChainID, + regexEIP155Separator, + regexEIP155, + regexEpochSeparator, + regexEpoch)) +) + +func ValidateRollAppID(id string) error { + if !rollappID.MatchString(id) { + return fmt.Errorf("invalid RollApp ID '%s'", id) + } + return nil +} diff --git a/config/config.go b/config/config.go index 19387fc4..e556d6b6 100644 --- a/config/config.go +++ b/config/config.go @@ -3,7 +3,6 @@ package config import ( "fmt" "math/big" - "regexp" "strings" "unicode" ) @@ -71,15 +70,6 @@ func IsValidDAType(t string) bool { return false } -func ValidateRollAppID(id string) error { - pattern := `^[a-z]+_[0-9]{1,5}-[0-9]{1,5}$` - r := regexp.MustCompile(pattern) - if !r.MatchString(id) { - return fmt.Errorf("invalid RollApp ID '%s'", id) - } - return nil -} - func VerifyHubID(data HubData) error { if data.RPC_URL == "" { return fmt.Errorf("invalid hub ID: %s. RPC URL cannot be empty", data.ID)