mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 23:54:22 +01:00
pylightning: millisatoshis type is int
Millisatoshi's inner representation expected to be an int, otherwise unwanted exceptions could occur
The following example raises: TypeError: __int__ returned non-int (type decimal.Decimal)
from lightning import Millisatoshi
one_sat = Millisatoshi("1sat")
two_sats = one_sat * 2
This commit is contained in:
committed by
Rusty Russell
parent
4985693bea
commit
7f8e4de522
@@ -34,12 +34,15 @@ class Millisatoshi:
|
|||||||
self.millisatoshis = Decimal(v[0:-3]) * 1000
|
self.millisatoshis = Decimal(v[0:-3]) * 1000
|
||||||
elif v.endswith("btc"):
|
elif v.endswith("btc"):
|
||||||
self.millisatoshis = Decimal(v[0:-3]) * 1000 * 10**8
|
self.millisatoshis = 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 self.millisatoshis != int(self.millisatoshis):
|
||||||
raise ValueError("Millisatoshi must be a whole number")
|
raise ValueError("Millisatoshi must be a whole number")
|
||||||
|
self.millisatoshis = int(self.millisatoshis)
|
||||||
elif isinstance(v, Millisatoshi):
|
elif isinstance(v, Millisatoshi):
|
||||||
self.millisatoshis = v.millisatoshis
|
self.millisatoshis = v.millisatoshis
|
||||||
elif int(v) == v:
|
elif int(v) == v:
|
||||||
self.millisatoshis = v
|
self.millisatoshis = int(v)
|
||||||
else:
|
else:
|
||||||
raise TypeError("Millisatoshi must be string with msat/sat/btc suffix or int")
|
raise TypeError("Millisatoshi must be string with msat/sat/btc suffix or int")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user