From cf926e841263215b86f37bdc0d1beb788ba1b9a2 Mon Sep 17 00:00:00 2001 From: ThomasV <thomasv@electrum.org> Date: Mon, 15 Mar 2021 12:38:00 +0100 Subject: [PATCH] Qt: add option to request force close of channel --- electrum/gui/qt/channels_list.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/electrum/gui/qt/channels_list.py b/electrum/gui/qt/channels_list.py index a37eb190b..81038de29 100644 --- a/electrum/gui/qt/channels_list.py +++ b/electrum/gui/qt/channels_list.py @@ -6,7 +6,7 @@ from typing import Sequence, Optional, Dict from PyQt5 import QtCore, QtGui from PyQt5.QtCore import Qt from PyQt5.QtWidgets import (QMenu, QHBoxLayout, QLabel, QVBoxLayout, QGridLayout, QLineEdit, - QPushButton, QAbstractItemView, QComboBox) + QPushButton, QAbstractItemView, QComboBox, QCheckBox) from PyQt5.QtGui import QFont, QStandardItem, QBrush from electrum.util import bh2u, NotEnoughFunds, NoDynamicFeeEstimates @@ -104,11 +104,23 @@ class ChannelsList(MyTreeView): self.main_window.show_error('Failed to close channel:\n{}'.format(repr(e))) def close_channel(self, channel_id): + self.is_force_close = False msg = _('Close channel?') - if not self.parent.question(msg): + force_cb = QCheckBox('Request force close from remote peer') + tooltip = _( + 'If you check this option, your node will pretend that it has lost its data and ask the remote node to broadcast their latest state. ' + 'Doing so from time to time helps make sure that nodes are honest, because your node can punish them if they broadcast a revoked state.') + def on_checked(b): + self.is_force_close = bool(b) + force_cb.stateChanged.connect(on_checked) + force_cb.setToolTip(tooltip) + if not self.parent.question(msg, checkbox=force_cb): return def task(): - coro = self.lnworker.close_channel(channel_id) + if self.is_force_close: + coro = self.lnworker.request_remote_force_close(channel_id) + else: + coro = self.lnworker.close_channel(channel_id) return self.network.run_from_another_thread(coro) WaitingDialog(self, 'please wait..', task, self.on_success, self.on_failure)