electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit c2ffc6ca3a3a8d693964908b1ec88fb7e3f83229
parent a033cfeee8319ee55f46450af4524142b3d64bac
Author: SomberNight <somber.night@protonmail.com>
Date:   Thu, 18 Jun 2020 21:52:48 +0200

qt swap_dialog: "max" now takes into account the server-provided value

Diffstat:
Melectrum/gui/qt/swap_dialog.py | 10+++++-----
Melectrum/submarine_swaps.py | 12++++++------
2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/electrum/gui/qt/swap_dialog.py b/electrum/gui/qt/swap_dialog.py @@ -5,7 +5,6 @@ from PyQt5.QtWidgets import QLabel, QVBoxLayout, QGridLayout, QPushButton from electrum.i18n import _ from electrum.lnutil import ln_dummy_address from electrum.transaction import PartialTxOutput, PartialTransaction -from electrum.submarine_swaps import SWAP_MAX_VALUE_SAT from .util import (WindowModalDialog, Buttons, OkButton, CancelButton, EnterButton, ColorScheme, WWLabel, read_QIcon) @@ -114,16 +113,17 @@ class SwapDialog(WindowModalDialog): self.update_tx('!') if self.tx: amount = self.tx.output_value_for_address(ln_dummy_address()) - if amount > SWAP_MAX_VALUE_SAT: - amount = SWAP_MAX_VALUE_SAT + max_amt = self.swap_manager.get_max_amount() + if amount > max_amt: + amount = max_amt self.update_tx(amount) if self.tx: amount = self.tx.output_value_for_address(ln_dummy_address()) - assert amount <= SWAP_MAX_VALUE_SAT + assert amount <= max_amt self.send_amount_e.setAmount(amount) def _spend_max_reverse_swap(self): - amount = min(self.lnworker.num_sats_can_send(), SWAP_MAX_VALUE_SAT) + amount = min(self.lnworker.num_sats_can_send(), self.swap_manager.get_max_amount()) self.send_amount_e.setAmount(amount) def on_send_edited(self): diff --git a/electrum/submarine_swaps.py b/electrum/submarine_swaps.py @@ -25,9 +25,6 @@ if TYPE_CHECKING: API_URL = 'https://lightning.electrum.org/api' -SWAP_MAX_VALUE_SAT = LN_MAX_HTLC_VALUE_MSAT // 1000 - - WITNESS_TEMPLATE_SWAP = [ opcodes.OP_HASH160, OPPushDataGeneric(lambda x: x == 20), @@ -118,7 +115,7 @@ class SwapManager(Logger): self.lockup_fee = 0 self.percentage = 0 self.min_amount = 0 - self.max_amount = 0 + self._max_amount = 0 self.network = network self.wallet = wallet self.lnworker = wallet.lnworker @@ -365,12 +362,15 @@ class SwapManager(Logger): self.lockup_fee = fees['minerFees']['baseAsset']['reverse']['lockup'] limits = pairs['pairs']['BTC/BTC']['limits'] self.min_amount = limits['minimal'] - self.max_amount = limits['maximal'] + self._max_amount = limits['maximal'] + + def get_max_amount(self): + return min(self._max_amount, LN_MAX_HTLC_VALUE_MSAT // 1000) 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: + if send_amount < self.min_amount or send_amount > self._max_amount: return x = send_amount if is_reverse: