From abac4a4340dc1aa82989ebea4032005bee048d6f Mon Sep 17 00:00:00 2001 From: ThomasV Date: Fri, 26 Jun 2020 09:19:40 +0200 Subject: [PATCH] swaps: check_invoice_amount (fixes #6217) --- electrum/submarine_swaps.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/electrum/submarine_swaps.py b/electrum/submarine_swaps.py index 251197ed2..b022986cc 100644 --- a/electrum/submarine_swaps.py +++ b/electrum/submarine_swaps.py @@ -387,21 +387,24 @@ class SwapManager(Logger): def get_max_amount(self): return min(self._max_amount, LN_MAX_HTLC_VALUE_MSAT // 1000) + def check_invoice_amount(self, x): + return x >= self.min_amount and x <= self._max_amount + def get_recv_amount(self, send_amount: Optional[int], is_reverse: bool) -> Optional[int]: if send_amount is None: return - if send_amount < self.min_amount or send_amount > self._max_amount: - return x = send_amount if is_reverse: + if not self.check_invoice_amount(x): + return x = int(x * (100 - self.percentage) / 100) x -= self.lockup_fee x -= self.get_claim_fee() else: x -= self.normal_fee x = int(x * (100 - self.percentage) / 100) - if x < 0: - return + if not self.check_invoice_amount(x): + return return x def get_send_amount(self, recv_amount: Optional[int], is_reverse: bool) -> Optional[int]: @@ -412,7 +415,11 @@ class SwapManager(Logger): x += self.lockup_fee x += self.get_claim_fee() x = int(x * 100 / (100 - self.percentage)) + 1 + if not self.check_invoice_amount(x): + return else: + if not self.check_invoice_amount(x): + return x = int(x * 100 / (100 - self.percentage)) + 1 x += self.normal_fee return x