Allow denom

This commit is contained in:
Prathamesh Musale 2025-06-16 17:05:40 +05:30
parent 960d44842b
commit 9b85fcf8dc
3 changed files with 7 additions and 6 deletions

View File

@ -11,6 +11,7 @@ import (
// Amount can be a whole number or a decimal number. Denominations can be 3 ~ 128
// characters long and support letters, followed by either a letter, a number or
// a separator ('/', ':', '.', '_' or '-').
// TODO: Update?
var coinRegex = regexp.MustCompile(`^(\d+(\.\d+)?)([a-zA-Z][a-zA-Z0-9\/\:\._\-]{2,127})$`)
// ParseCoin parses a coin from a string. The string must be in the format

View File

@ -877,20 +877,20 @@ 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 '-'.
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