From 7f8e4de52229caef5eb545ca5f0400b41c475fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1lli=20Zolt=C3=A1n?= Date: Tue, 16 Apr 2019 13:35:55 +0200 Subject: [PATCH] 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 --- contrib/pylightning/lightning/lightning.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contrib/pylightning/lightning/lightning.py b/contrib/pylightning/lightning/lightning.py index 2b0c23a3f..70d71e4d0 100644 --- a/contrib/pylightning/lightning/lightning.py +++ b/contrib/pylightning/lightning/lightning.py @@ -34,12 +34,15 @@ class Millisatoshi: self.millisatoshis = Decimal(v[0:-3]) * 1000 elif v.endswith("btc"): 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): raise ValueError("Millisatoshi must be a whole number") + self.millisatoshis = int(self.millisatoshis) elif isinstance(v, Millisatoshi): self.millisatoshis = v.millisatoshis elif int(v) == v: - self.millisatoshis = v + self.millisatoshis = int(v) else: raise TypeError("Millisatoshi must be string with msat/sat/btc suffix or int")