electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 2b4a436572fdc1fa4cd76d1db09225e3246cc529
parent cd893de837def1aee792e0b71af24078aa812810
Author: SomberNight <somber.night@protonmail.com>
Date:   Wed,  1 Aug 2018 18:23:11 +0200

qt open channel dialog: allow pasting invoices to open a channel

Diffstat:
Melectrum/gui/qt/channels_list.py | 27+++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)

diff --git 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)