Update denom parsing to allow $Z denom #1

Merged
nabarun merged 2 commits from pm-support-denom into zenith 2025-06-23 06:13:52 +00:00
2 changed files with 7 additions and 7 deletions

View File

@ -875,22 +875,22 @@ func ValidateDenom(denom string) error {
}
// isValidRune checks if a given rune is a valid character for a rune.
// It returns true if the rune is a letter, digit, '/', ':', '.', '_', or '-'.
// It returns true if the rune is a letter, digit, '/', ':', '.', '_', '-', or '$'.
func isValidRune(r rune) bool {
return unicode.IsLetter(r) || unicode.IsDigit(r) || r == '/' || r == ':' || r == '.' || r == '_' || r == '-'
return unicode.IsLetter(r) || unicode.IsDigit(r) || r == '/' || r == ':' || r == '.' || r == '_' || r == '-' || r == '$'
}
// MatchDenom checks if the given string is a valid denomination.
// A valid denomination must have a length between 3 and 128 characters,
// A valid denomination must have a length between 2 and 128 characters,
// start with a letter, and only contain valid runes.
func MatchDenom(s string) bool {
length := len(s)
if length < 3 || length > 128 {
if length < 2 || length > 128 {
return false
}
firstRune := rune(s[0])
if !unicode.IsLetter(firstRune) {
if !unicode.IsLetter(firstRune) && firstRune != '$' {
return false
}

View File

@ -676,7 +676,7 @@ func ParseDecAmount(coinStr string) (string, string, error) {
amountRune = append(amountRune, r)
} else if unicode.IsSpace(r) { // if space is seen, indicates that we have finished parsing amount
parsingAmount = false
} else if unicode.IsLetter(r) { // if letter is seen, indicates that it is the start of denom
} else if unicode.IsLetter(r) || r == '$' { // if letter is seen, indicates that it is the start of denom
parsingAmount = false
seenLetter = true
denomRune = append(denomRune, r)
@ -693,7 +693,7 @@ func ParseDecAmount(coinStr string) (string, string, error) {
}
} else {
// Parsing the denomination
if unicode.IsLetter(r) || unicode.IsDigit(r) || r == '/' || r == ':' || r == '.' || r == '_' || r == '-' {
if unicode.IsLetter(r) || unicode.IsDigit(r) || r == '/' || r == ':' || r == '.' || r == '_' || r == '-' || r == '$' {
denomRune = append(denomRune, r)
} else {
// Invalid character encountered in denomination part