From 46770bfd71d7675abaca3d2e74cc7b8088cd8ac4 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Mon, 25 May 2020 22:18:18 +0200 Subject: [PATCH] submarine swaps: fix expected amounts --- electrum/gui/qt/swap_dialog.py | 7 +++++-- electrum/submarine_swaps.py | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/electrum/gui/qt/swap_dialog.py b/electrum/gui/qt/swap_dialog.py index 60bd7373f..aaf5788a6 100644 --- a/electrum/gui/qt/swap_dialog.py +++ b/electrum/gui/qt/swap_dialog.py @@ -155,12 +155,14 @@ class SwapDialog(WindowModalDialog): return if send_amount < self.min_amount or send_amount > self.max_amount: return - x = int(send_amount * (100 - self.percentage) / 100) + x = send_amount if self.is_reverse: + x = int(x * (100 - self.percentage) / 100) x -= self.lockup_fee x -= self.claim_fee else: x -= self.normal_fee + x = int(x * (100 - self.percentage) / 100) if x < 0: return return x @@ -172,9 +174,10 @@ class SwapDialog(WindowModalDialog): if self.is_reverse: x += self.lockup_fee x += self.claim_fee + x = int(x * 100 / (100 - self.percentage)) + 1 else: + x = int(x * 100 / (100 - self.percentage)) + 1 x += self.normal_fee - x = int(x * 100 / (100 - self.percentage)) + 1 return x def run(self): diff --git a/electrum/submarine_swaps.py b/electrum/submarine_swaps.py index 376c5ec16..6e7427469 100644 --- a/electrum/submarine_swaps.py +++ b/electrum/submarine_swaps.py @@ -163,7 +163,7 @@ class SwapManager(Logger): assert pubkey == parsed_script[9][1] assert locktime == int.from_bytes(parsed_script[6][1], byteorder='little') # check that onchain_amount is what was announced - assert onchain_amount == expected_onchain_amount + assert onchain_amount <= expected_onchain_amount, (onchain_amount, expected_onchain_amount) # verify that they are not locking up funds for more than a day assert locktime - self.network.get_local_height() < 144 # save swap data in wallet in case we need a refund @@ -217,7 +217,7 @@ class SwapManager(Logger): assert pubkey == parsed_script[7][1] assert locktime == int.from_bytes(parsed_script[10][1], byteorder='little') # check that the amount is what we expected - assert onchain_amount == expected_amount, (onchain_amount, expected_amount) + assert onchain_amount >= expected_amount, (onchain_amount, expected_amount) # verify that we will have enought time to get our tx confirmed assert locktime - self.network.get_local_height() > 10 # verify invoice preimage_hash