From bcfcc20363abf6ebdf53d660a263eeae2f42a091 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Tue, 16 Mar 2021 17:27:37 +0100 Subject: [PATCH] fix: add request_force_close method --- electrum/commands.py | 2 +- electrum/gui/qt/channels_list.py | 2 +- electrum/lnworker.py | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/electrum/commands.py b/electrum/commands.py index 9d090a955..04f381034 100644 --- a/electrum/commands.py +++ b/electrum/commands.py @@ -1099,7 +1099,7 @@ class Commands: async def request_force_close(self, channel_point, wallet: Abstract_Wallet = None): txid, index = channel_point.split(':') chan_id, _ = channel_id_from_funding_tx(txid, int(index)) - return await wallet.lnworker.request_force_close_from_backup(chan_id) + return await wallet.lnworker.request_force_close(chan_id) @command('w') async def export_channel_backup(self, channel_point, wallet: Abstract_Wallet = None): diff --git a/electrum/gui/qt/channels_list.py b/electrum/gui/qt/channels_list.py index ad3b107e8..83ae8ec8d 100644 --- a/electrum/gui/qt/channels_list.py +++ b/electrum/gui/qt/channels_list.py @@ -119,7 +119,7 @@ class ChannelsList(MyTreeView): return def task(): if self.is_force_close: - coro = self.lnworker.request_remote_force_close(channel_id) + coro = self.lnworker.request_force_close(channel_id) else: coro = self.lnworker.close_channel(channel_id) return self.network.run_from_another_thread(coro) diff --git a/electrum/lnworker.py b/electrum/lnworker.py index 51a04a4ca..a31b5ebbd 100644 --- a/electrum/lnworker.py +++ b/electrum/lnworker.py @@ -2022,6 +2022,18 @@ class LNWallet(LNWorker): peer = await self.add_peer(connect_str) await peer.trigger_force_close(channel_id) + async def request_force_close(self, channel_id: bytes): + if channel_id in self.channels: + chan = self.channels[chan_id] + peer = self._peers.get(chan.node_id) + if not peer: + raise Exception('Peer not found') + await peer.trigger_force_close(channel_id) + elif channel_id in self.channel_backups: + await self.request_force_close_from_backup(channel_id) + else: + raise Exception(f'Unknown channel {channel_id.hex()}') + def import_channel_backup(self, data): assert data.startswith('channel_backup:') encrypted = data[15:]