From 6b6097a4534cf4cb40229adc40576a2375d1c812 Mon Sep 17 00:00:00 2001 From: Janus Date: Thu, 24 Jan 2019 18:21:46 +0100 Subject: [PATCH] ln: add closechannel cli command --- electrum/commands.py | 8 ++++++++ electrum/lnbase.py | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/electrum/commands.py b/electrum/commands.py index cd87f1cd8..3b4881469 100644 --- a/electrum/commands.py +++ b/electrum/commands.py @@ -808,6 +808,14 @@ class Commands: def listinvoices(self): return "\n".join(self.wallet.lnworker.list_invoices()) + @command('wn') + def closechannel(self, channel_point, force=False): + chan_id = bytes(reversed(bfh(channel_point))) + if force: + return self.network.run_from_another_thread(self.wallet.lnworker.force_close_channel(chan_id)) + else: + return self.network.run_from_another_thread(self.wallet.lnworker.close_channel(chan_id)) + def eval_bool(x: str) -> bool: if x == 'false': return False if x == 'true': return True diff --git a/electrum/lnbase.py b/electrum/lnbase.py index c79067eba..52dc45052 100644 --- a/electrum/lnbase.py +++ b/electrum/lnbase.py @@ -1180,7 +1180,8 @@ class Peer(PrintError): async def _shutdown(self, chan: Channel, payload): # set state so that we stop accepting HTLCs chan.set_state('CLOSING') - while len(chan.htlcs(LOCAL, only_pending=True)) > 0: + while len(chan.hm.htlcs_by_direction(LOCAL, RECEIVED)) > 0: + self.print_error('waiting for htlcs to settle...') await asyncio.sleep(1) our_fee = chan.pending_local_fee() scriptpubkey = bfh(bitcoin.address_to_script(chan.sweep_address))