Browse Source

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

dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
SomberNight 7 years ago
committed by ThomasV
parent
commit
2b4a436572
  1. 27
      electrum/gui/qt/channels_list.py

27
electrum/gui/qt/channels_list.py

@ -5,6 +5,8 @@ from PyQt5.QtWidgets import *
from electrum.util import inv_dict, bh2u, bfh from electrum.util import inv_dict, bh2u, bfh
from electrum.i18n import _ from electrum.i18n import _
from electrum.lnhtlc import HTLCStateMachine from electrum.lnhtlc import HTLCStateMachine
from electrum.lnaddr import lndecode
from .util import MyTreeWidget, SortableTreeWidgetItem, WindowModalDialog, Buttons, OkButton, CancelButton from .util import MyTreeWidget, SortableTreeWidgetItem, WindowModalDialog, Buttons, OkButton, CancelButton
from .amountedit import BTCAmountEdit from .amountedit import BTCAmountEdit
@ -88,7 +90,7 @@ class ChannelsList(MyTreeWidget):
push_amt_inp.setAmount(0) push_amt_inp.setAmount(0)
h.addWidget(QLabel(_('Your Node ID')), 0, 0) h.addWidget(QLabel(_('Your Node ID')), 0, 0)
h.addWidget(local_nodeid, 0, 1) 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(remote_nodeid, 1, 1)
h.addWidget(QLabel('Local amount'), 2, 0) h.addWidget(QLabel('Local amount'), 2, 0)
h.addWidget(local_amt_inp, 2, 1) h.addWidget(local_amt_inp, 2, 1)
@ -104,11 +106,7 @@ class ChannelsList(MyTreeWidget):
local_amt = local_amt_inp.get_amount() local_amt = local_amt_inp.get_amount()
push_amt = push_amt_inp.get_amount() push_amt = push_amt_inp.get_amount()
connect_contents = str(remote_nodeid.text()) connect_contents = str(remote_nodeid.text())
rest = None nodeid_hex, rest = self.parse_connect_contents(connect_contents)
try:
nodeid_hex, rest = connect_contents.split("@")
except ValueError:
nodeid_hex = connect_contents
try: try:
node_id = bfh(nodeid_hex) node_id = bfh(nodeid_hex)
assert len(node_id) == 33 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)) 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): def open_channel(self, *args, **kwargs):
self.parent.wallet.lnworker.open_channel(*args, **kwargs) self.parent.wallet.lnworker.open_channel(*args, **kwargs)

Loading…
Cancel
Save