Regex in Coin.from_str() unable to parse denoms containing a hyphen
ibjc opened this issue · comments
jc commented
- terra_sdk version: 3.0.0
- Python version: 3.8
- Operating System: linux
Description
tokenfactory denoms can have a hyphen in the name, which seems to break the Coin.from_str regex.
the normal constructor works fine, ex: Coin(denom="factory/terra1xyz/my-denom", amount=69420)
terra.py/terra_sdk/core/coin.py
Line 110 in 18423ae
What I Did
In [5]: Coins.from_str("69420factory/terra1xyz/my-denom")
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Input In [5], in <cell line: 1>()
----> 1 Coins.from_str("69420factory/terra1xyz/my-denom")
File /usr/local/lib/python3.8/site-packages/terra_sdk/core/coins.py:52, in Coins.from_str(cls, s)
43 """Converts a comma-separated list of Coin-format strings to :class:`Coins`.
44
45 >>> Coins.from_str('1000uluna,1234ukrw')
(...)
49 s (str): string to convert
50 """
51 coin_strings = s.split(r",")
---> 52 return Coins(Coin.from_str(cs) for cs in coin_strings)
File /usr/local/lib/python3.8/site-packages/terra_sdk/core/coins.py:82, in Coins.__init__(self, arg, **denoms)
80 else:
81 coins = arg
---> 82 for coin in coins:
83 x = self._coins.get(coin.denom)
84 if x is not None:
File /usr/local/lib/python3.8/site-packages/terra_sdk/core/coins.py:52, in <genexpr>(.0)
43 """Converts a comma-separated list of Coin-format strings to :class:`Coins`.
44
45 >>> Coins.from_str('1000uluna,1234ukrw')
(...)
49 s (str): string to convert
50 """
51 coin_strings = s.split(r",")
---> 52 return Coins(Coin.from_str(cs) for cs in coin_strings)
File /usr/local/lib/python3.8/site-packages/terra_sdk/core/coin.py:113, in Coin.from_str(cls, string)
111 match = re.match(pattern, string)
112 if match is None:
--> 113 raise ValueError(f"failed to parse Coin: {string}")
114 else:
115 return cls(match.group(3), match.group(1))
ValueError: failed to parse Coin: 69420factory/terra1xyz/my-denom