Take sats as whole numbers and drop sats_to_btc
This commit is contained in:
1 parent
b044b0b5ad
commit
a016d31cc5
1 file changed
+13
-15
@@ -130,18 +130,16 @@ def kroner_whole(ore):
|
||||
return "-" + text if negative else text
|
||||
|
||||
|
||||
def parse_btc_to_sats(text):
|
||||
"""Convert a BTC amount to integer sats. Accepts ',' or '.' as separator."""
|
||||
negative, whole, fraction = _split(text)
|
||||
if len(fraction) > 8:
|
||||
raise ValueError("more than 8 decimals")
|
||||
return _apply_sign(negative, int(whole) * SATS_PER_BTC + int(fraction.ljust(8, "0")))
|
||||
|
||||
|
||||
def sats_to_btc(sats):
|
||||
"""Format integer sats as a BTC amount with 8 decimals."""
|
||||
sats = int(sats)
|
||||
negative = sats < 0
|
||||
sats = abs(sats)
|
||||
text = "%d,%08d" % (sats // SATS_PER_BTC, sats % SATS_PER_BTC)
|
||||
return "-" + text if negative else text
|
||||
def parse_sats(text):
|
||||
"""Convert a whole number of sats. A decimal separator is rejected."""
|
||||
cleaned = _strip(text)
|
||||
if not cleaned:
|
||||
raise ValueError("empty amount")
|
||||
if "," in cleaned or "." in cleaned:
|
||||
raise ValueError("sats must be a whole number")
|
||||
negative = cleaned.startswith("-")
|
||||
if negative:
|
||||
cleaned = cleaned[1:]
|
||||
if not cleaned.isdigit():
|
||||
raise ValueError("not a number")
|
||||
return _apply_sign(negative, int(cleaned))
|
||||
Reference in new issue
Block a user