Browse Source

pyln: fix msat from float str

Changelog-fixed: pyln: parsing msat from a float string
fix-mocks
Michael Schmoock 4 years ago
committed by Rusty Russell
parent
commit
83a21138b8
  1. 10
      contrib/pyln-client/pyln/client/lightning.py

10
contrib/pyln-client/pyln/client/lightning.py

@ -49,19 +49,19 @@ class Millisatoshi:
"""
if isinstance(v, str):
if v.endswith("msat"):
self.millisatoshis = int(v[0:-4])
parsed = Decimal(v[0:-4])
elif v.endswith("sat"):
self.millisatoshis = int(v[0:-3]) * 1000
parsed = Decimal(v[0:-3]) * 1000
elif v.endswith("btc"):
self.millisatoshis = int(v[0:-3]) * 1000 * 10**8
parsed = Decimal(v[0:-3]) * 1000 * 10**8
else:
raise TypeError(
"Millisatoshi must be string with msat/sat/btc suffix or"
" int"
)
if self.millisatoshis != int(self.millisatoshis):
if parsed != int(parsed):
raise ValueError("Millisatoshi must be a whole number")
self.millisatoshis = int(self.millisatoshis)
self.millisatoshis = int(parsed)
elif isinstance(v, Millisatoshi):
self.millisatoshis = v.millisatoshis

Loading…
Cancel
Save