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

R4R: Add custom validation for denom #6755

Merged
merged 13 commits into from
Oct 6, 2020
9 changes: 6 additions & 3 deletions types/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,15 +589,18 @@ var (
reDecCoin = regexp.MustCompile(fmt.Sprintf(`^(%s)%s(%s)$`, reDecAmt, reSpc, reDnmString))
)

// ValidateDenom validates a denomination string returning an error if it is
// invalid.
func ValidateDenom(denom string) error {
// DefaultValidateDenom is the default validation function for Coin.Denom.
func DefaultValidateDenom(denom string) error {
if !reDnm.MatchString(denom) {
return fmt.Errorf("invalid denom: %s", denom)
}
return nil
}

// ValidateDenom validates a denomination string returning an error if it is
// invalid.
var ValidateDenom = DefaultValidateDenom

func mustValidateDenom(denom string) {
if err := ValidateDenom(denom); err != nil {
panic(err)
Expand Down