diff --git a/electrum/gui/qt/channels_list.py b/electrum/gui/qt/channels_list.py index cd6606aa2..9feb401d4 100644 --- a/electrum/gui/qt/channels_list.py +++ b/electrum/gui/qt/channels_list.py @@ -5,6 +5,8 @@ from PyQt5.QtWidgets import * from electrum.util import inv_dict, bh2u, bfh from electrum.i18n import _ from electrum.lnhtlc import HTLCStateMachine +from electrum.lnaddr import lndecode + from .util import MyTreeWidget, SortableTreeWidgetItem, WindowModalDialog, Buttons, OkButton, CancelButton from .amountedit import BTCAmountEdit @@ -88,7 +90,7 @@ class ChannelsList(MyTreeWidget): push_amt_inp.setAmount(0) h.addWidget(QLabel(_('Your Node ID')), 0, 0) h.addWidget(local_nodeid, 0, 1) - h.addWidget(QLabel(_('Remote Node ID or connection string')), 1, 0) + h.addWidget(QLabel(_('Remote Node ID or connection string or invoice')), 1, 0) h.addWidget(remote_nodeid, 1, 1) h.addWidget(QLabel('Local amount'), 2, 0) h.addWidget(local_amt_inp, 2, 1) @@ -104,11 +106,7 @@ class ChannelsList(MyTreeWidget): local_amt = local_amt_inp.get_amount() push_amt = push_amt_inp.get_amount() connect_contents = str(remote_nodeid.text()) - rest = None - try: - nodeid_hex, rest = connect_contents.split("@") - except ValueError: - nodeid_hex = connect_contents + nodeid_hex, rest = self.parse_connect_contents(connect_contents) try: node_id = bfh(nodeid_hex) assert len(node_id) == 33 @@ -140,5 +138,22 @@ class ChannelsList(MyTreeWidget): self.main_window.protect(self.open_channel, (node_id, local_amt, push_amt)) + @classmethod + def parse_connect_contents(cls, connect_contents: str): + rest = None + try: + # connection string? + nodeid_hex, rest = connect_contents.split("@") + except ValueError: + try: + # invoice? + invoice = lndecode(connect_contents) + nodeid_bytes = invoice.pubkey.serialize() + nodeid_hex = bh2u(nodeid_bytes) + except: + # node id as hex? + nodeid_hex = connect_contents + return nodeid_hex, rest + def open_channel(self, *args, **kwargs): self.parent.wallet.lnworker.open_channel(*args, **kwargs)