Check type of amounts passed to conversion, avoid MemoryError when a string is being concatenated 10^12 times. Close#48

This commit is contained in:
Michał Sałaban 2019-04-04 13:06:04 +02:00
parent 3358e5a30a
commit a7c8579b13
2 changed files with 12 additions and 0 deletions

View file

@ -13,6 +13,9 @@ else: # pragma: no cover
def to_atomic(amount):
"""Convert Monero decimal to atomic integer of piconero."""
if not isinstance(amount, (Decimal, float) + _integer_types):
raise ValueError("Amount '{}' doesn't have numeric type. Only Decimal, int, long and "
"float (not recommended) are accepted as amounts.")
return int(amount * 10**12)
def from_atomic(amount):