Skip to content

Commit be0695d

Browse files
committed
util: format_satoshis_plain: remove TODO, hard-fail on float
1 parent 40a169a commit be0695d

2 files changed

Lines changed: 3 additions & 4 deletions

File tree

electrum/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def satoshis(amount):
103103
return int(COIN*to_decimal(amount)) if amount is not None else None
104104

105105

106-
def format_satoshis(x: Union[float, int, Decimal, None]) -> Optional[str]:
106+
def format_satoshis(x: Union[int, Decimal, None]) -> Optional[str]:
107107
"""
108108
input: satoshis as a Number
109109
output: str formatted as bitcoin amount

electrum/util.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ def chunks(items, size: int):
776776

777777

778778
def format_satoshis_plain(
779-
x: Union[int, float, Decimal, str], # amount in satoshis,
779+
x: Union[int, Decimal, str], # amount in satoshis,
780780
*,
781781
decimal_point: int = 8, # how much to shift decimal point to left (default: sat->BTC)
782782
precision: int = 0, # extra digits after satoshi precision (e.g. for msat)
@@ -786,8 +786,7 @@ def format_satoshis_plain(
786786
point and has no thousands separator"""
787787
if is_max_allowed and parse_max_spend(x):
788788
return f'max({x})'
789-
assert isinstance(x, (int, float, Decimal)), f"{x!r} should be a number"
790-
# TODO(ghost43) just hard-fail if x is a float. do we even use floats for money anywhere?
789+
assert isinstance(x, (int, Decimal)), f"{x!r} should be an int or Decimal"
791790
x = to_decimal(x)
792791
scale_factor = pow(10, decimal_point)
793792
return "{:.{}f}".format(x / scale_factor, 8 + precision).rstrip('0').rstrip('.')

0 commit comments

Comments
 (0)