Browse Source

lnworker: merge request_force_close and request_remote_force_close

patch-4
ThomasV 4 years ago
parent
commit
3c9838d999
  1. 10
      electrum/commands.py
  2. 22
      electrum/lnworker.py

10
electrum/commands.py

@ -1096,10 +1096,15 @@ class Commands:
return await coro
@command('wn')
async def request_force_close(self, channel_point, wallet: Abstract_Wallet = None):
async def request_force_close(self, channel_point, connection_string=None, wallet: Abstract_Wallet = None):
"""
Requests the remote to force close a channel.
If a connection string is passed, can be used without having state or any backup for the channel.
Assumes that channel was originally opened with the same local peer (node_keypair).
"""
txid, index = channel_point.split(':')
chan_id, _ = channel_id_from_funding_tx(txid, int(index))
return await wallet.lnworker.request_force_close(chan_id)
await wallet.lnworker.request_force_close(chan_id, connect_str=connection_string)
@command('w')
async def export_channel_backup(self, channel_point, wallet: Abstract_Wallet = None):
@ -1264,6 +1269,7 @@ command_options = {
'to_height': (None, "Only show transactions that confirmed before given block height"),
'iknowwhatimdoing': (None, "Acknowledge that I understand the full implications of what I am about to do"),
'gossip': (None, "Apply command to gossip node instead of wallet"),
'connection_string': (None, "Lightning network node ID or network address"),
}

22
electrum/lnworker.py

@ -2008,23 +2008,11 @@ class LNWallet(LNWorker):
assert backup_bytes == pw_decode_with_version_and_mac(encrypted, xpub), "encrypt failed"
return 'channel_backup:' + encrypted
async def request_remote_force_close(
self, *, funding_txid: str, funding_index: int, connect_str: str):
"""
Requests the remote to force close a channel. Can be used without
having state or any backup for the channel.
Assumes that channel was originally opened with the same local peer (node_keypair).
Kept for console use.
Example:
network.run_from_another_thread(wallet.lnworker.request_remote_force_close(funding_txid="11a3b391bc99dbca0b2be4fdd8f18ca641896c81ae4d9596b30cbf1eef17af71", funding_index=1, connect_str="023a8dfe081c6bbd0504e599f33d39d17687de63023a8b20afcb59147d9d77c19d"))
"""
channel_id = lnutil.channel_id_from_funding_tx(funding_txid, funding_index)[0]
peer = await self.add_peer(connect_str)
await peer.trigger_force_close(channel_id)
async def request_force_close(self, channel_id: bytes) -> None:
if channel_id in self.channels:
async def request_force_close(self, channel_id: bytes, *, connect_str=None) -> None:
if connect_str:
peer = await self.add_peer(connect_str)
await peer.trigger_force_close(channel_id)
elif channel_id in self.channels:
chan = self.channels[channel_id]
peer = self._peers.get(chan.node_id)
if not peer:

Loading…
Cancel
Save