From 11bb39ee82eb8dd99f8caedfe6768e90f15066e6 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Mon, 19 Apr 2021 18:56:04 +0200 Subject: [PATCH] kivy: implement freezing channels --- .../kivy/uix/dialogs/lightning_channels.py | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/electrum/gui/kivy/uix/dialogs/lightning_channels.py b/electrum/gui/kivy/uix/dialogs/lightning_channels.py index 4fcbf120f..94af6269d 100644 --- a/electrum/gui/kivy/uix/dialogs/lightning_channels.py +++ b/electrum/gui/kivy/uix/dialogs/lightning_channels.py @@ -244,6 +244,8 @@ Builder.load_string(r''' can_receive:'' is_open:False warning: '' + is_frozen_for_sending: False + is_frozen_for_receiving: False BoxLayout: padding: '12dp', '12dp', '12dp', '12dp' spacing: '12dp' @@ -286,6 +288,12 @@ Builder.load_string(r''' BoxLabel: text: _('Fee rate') value: '{} sat/byte'.format(root.feerate) + BoxLabel: + text: _('Frozen (for sending)') + value: str(root.is_frozen_for_sending) + BoxLabel: + text: _('Frozen (for receiving)') + value: str(root.is_frozen_for_receiving) Widget: size_hint: 1, 0.1 TopLabel: @@ -474,16 +482,27 @@ class ChannelDetailsPopup(Popup, Logger): self.closing_txid, closing_height, closing_timestamp = closed msg = messages.MSG_NON_TRAMPOLINE_CHANNEL_FROZEN_WITHOUT_GOSSIP self.warning = '' if self.app.wallet.lnworker.channel_db or self.app.wallet.lnworker.is_trampoline_peer(chan.node_id) else _('Warning') + ': ' + msg + self.is_frozen_for_sending = chan.is_frozen_for_sending() + self.is_frozen_for_receiving = chan.is_frozen_for_receiving() self.update_action_dropdown() def update_action_dropdown(self): action_dropdown = self.ids.action_dropdown # type: ActionDropdown - options = ( + options = [ ActionButtonOption(text=_('Backup'), func=lambda btn: self.export_backup()), ActionButtonOption(text=_('Close channel'), func=lambda btn: self.close(), enabled=not self.is_closed), ActionButtonOption(text=_('Force-close'), func=lambda btn: self.force_close(), enabled=not self.is_closed), ActionButtonOption(text=_('Delete'), func=lambda btn: self.remove_channel(), enabled=self.can_be_deleted), - ) + ] + if not self.chan.is_closed(): + if not self.chan.is_frozen_for_sending(): + options.append(ActionButtonOption(text=_("Freeze") + "\n(for sending)", func=lambda btn: self.freeze_for_sending())) + else: + options.append(ActionButtonOption(text=_("Unfreeze") + "\n(for sending)", func=lambda btn: self.freeze_for_sending())) + if not self.chan.is_frozen_for_receiving(): + options.append(ActionButtonOption(text=_("Freeze") + "\n(for receiving)", func=lambda btn: self.freeze_for_receiving())) + else: + options.append(ActionButtonOption(text=_("Unfreeze") + "\n(for receiving)", func=lambda btn: self.freeze_for_receiving())) action_dropdown.update(options=options) def close(self): @@ -574,6 +593,20 @@ class ChannelDetailsPopup(Popup, Logger): self.logger.exception("Could not force close channel") self.app.show_info(_('Could not force close channel: ') + repr(e)) # repr because str(Exception()) == '' + def freeze_for_sending(self): + lnworker = self.chan.lnworker + if lnworker.channel_db or lnworker.is_trampoline_peer(self.chan.node_id): + self.is_frozen_for_sending = not self.is_frozen_for_sending + self.chan.set_frozen_for_sending(self.is_frozen_for_sending) + self.update_action_dropdown() + else: + self.app.show_info(messages.MSG_NON_TRAMPOLINE_CHANNEL_FROZEN_WITHOUT_GOSSIP) + + def freeze_for_receiving(self): + self.is_frozen_for_receiving = not self.is_frozen_for_receiving + self.chan.set_frozen_for_receiving(self.is_frozen_for_receiving) + self.update_action_dropdown() + class LightningChannelsDialog(Factory.Popup):