Skip to content

Commit

Permalink
Also bring back dec coin custom parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mattverse committed Mar 4, 2024
1 parent 33a4a85 commit 8bc1443
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions types/dec_coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,9 +631,22 @@ func (coins DecCoins) Sort() DecCoins {
// ParseDecCoin parses a decimal coin from a string, returning an error if
// invalid. An empty string is considered invalid.
func ParseDecCoin(coinStr string) (coin DecCoin, err error) {
amountStr, denomStr, err := ParseDecAmount(coinStr)
if err != nil {
return DecCoin{}, err
var amountStr, denomStr string
// if custom parsing has not been set, use default coin regex
if reDecCoin == nil {
amountStr, denomStr, err = ParseDecAmount(coinStr)
if err != nil {
return DecCoin{}, err
}
} else {
coinStr = strings.TrimSpace(coinStr)

matches := reDecCoin.FindStringSubmatch(coinStr)
if matches == nil {
return DecCoin{}, fmt.Errorf("invalid decimal coin expression: %s", coinStr)
}

amountStr, denomStr = matches[1], matches[2]
}

amount, err := math.LegacyNewDecFromStr(amountStr)
Expand Down

0 comments on commit 8bc1443

Please sign in to comment.