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
|
return "-" + text if negative else text
|
||||||
|
|
||||||
|
|
||||||
def parse_btc_to_sats(text):
|
def parse_sats(text):
|
||||||
"""Convert a BTC amount to integer sats. Accepts ',' or '.' as separator."""
|
"""Convert a whole number of sats. A decimal separator is rejected."""
|
||||||
negative, whole, fraction = _split(text)
|
cleaned = _strip(text)
|
||||||
if len(fraction) > 8:
|
if not cleaned:
|
||||||
raise ValueError("more than 8 decimals")
|
raise ValueError("empty amount")
|
||||||
return _apply_sign(negative, int(whole) * SATS_PER_BTC + int(fraction.ljust(8, "0")))
|
if "," in cleaned or "." in cleaned:
|
||||||
|
raise ValueError("sats must be a whole number")
|
||||||
|
negative = cleaned.startswith("-")
|
||||||
def sats_to_btc(sats):
|
if negative:
|
||||||
"""Format integer sats as a BTC amount with 8 decimals."""
|
cleaned = cleaned[1:]
|
||||||
sats = int(sats)
|
if not cleaned.isdigit():
|
||||||
negative = sats < 0
|
raise ValueError("not a number")
|
||||||
sats = abs(sats)
|
return _apply_sign(negative, int(cleaned))
|
||||||
text = "%d,%08d" % (sats // SATS_PER_BTC, sats % SATS_PER_BTC)
|
|
||||||
return "-" + text if negative else text
|
|
||||||
Reference in new issue
Block a user