integrate channels_list with existing framework
This commit is contained in:
parent
eb9434ca48
commit
f702bbac11
@ -60,7 +60,7 @@ from .transaction_dialog import show_transaction
|
|||||||
from .fee_slider import FeeSlider
|
from .fee_slider import FeeSlider
|
||||||
from .util import *
|
from .util import *
|
||||||
from .installwizard import WIF_HELP_TEXT
|
from .installwizard import WIF_HELP_TEXT
|
||||||
from .lightning_channels_list import LightningChannelsList
|
from .channels_list import ChannelsList
|
||||||
|
|
||||||
|
|
||||||
class StatusBarButton(QPushButton):
|
class StatusBarButton(QPushButton):
|
||||||
@ -138,12 +138,10 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
|||||||
self.utxo_tab = self.create_utxo_tab()
|
self.utxo_tab = self.create_utxo_tab()
|
||||||
self.console_tab = self.create_console_tab()
|
self.console_tab = self.create_console_tab()
|
||||||
self.contacts_tab = self.create_contacts_tab()
|
self.contacts_tab = self.create_contacts_tab()
|
||||||
|
self.channels_tab = self.create_channels_tab(wallet)
|
||||||
tabs.addTab(self.create_history_tab(), QIcon(":icons/tab_history.png"), _('History'))
|
tabs.addTab(self.create_history_tab(), QIcon(":icons/tab_history.png"), _('History'))
|
||||||
tabs.addTab(self.send_tab, QIcon(":icons/tab_send.png"), _('Send'))
|
tabs.addTab(self.send_tab, QIcon(":icons/tab_send.png"), _('Send'))
|
||||||
tabs.addTab(self.receive_tab, QIcon(":icons/tab_receive.png"), _('Receive'))
|
tabs.addTab(self.receive_tab, QIcon(":icons/tab_receive.png"), _('Receive'))
|
||||||
if config.get("lnbase", False):
|
|
||||||
self.lightning_channels_tab = self.create_lightning_channels_tab(wallet)
|
|
||||||
tabs.addTab(self.lightning_channels_tab, QIcon(":icons/lightning.png"), _("Channels"))
|
|
||||||
|
|
||||||
def add_optional_tab(tabs, tab, icon, description, name):
|
def add_optional_tab(tabs, tab, icon, description, name):
|
||||||
tab.tab_icon = icon
|
tab.tab_icon = icon
|
||||||
@ -154,6 +152,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
|||||||
tabs.addTab(tab, icon, description.replace("&", ""))
|
tabs.addTab(tab, icon, description.replace("&", ""))
|
||||||
|
|
||||||
add_optional_tab(tabs, self.addresses_tab, QIcon(":icons/tab_addresses.png"), _("&Addresses"), "addresses")
|
add_optional_tab(tabs, self.addresses_tab, QIcon(":icons/tab_addresses.png"), _("&Addresses"), "addresses")
|
||||||
|
add_optional_tab(tabs, self.channels_tab, QIcon(":icons/lightning.png"), _("Channels"), "channels")
|
||||||
add_optional_tab(tabs, self.utxo_tab, QIcon(":icons/tab_coins.png"), _("Co&ins"), "utxo")
|
add_optional_tab(tabs, self.utxo_tab, QIcon(":icons/tab_coins.png"), _("Co&ins"), "utxo")
|
||||||
add_optional_tab(tabs, self.contacts_tab, QIcon(":icons/tab_contacts.png"), _("Con&tacts"), "contacts")
|
add_optional_tab(tabs, self.contacts_tab, QIcon(":icons/tab_contacts.png"), _("Con&tacts"), "contacts")
|
||||||
add_optional_tab(tabs, self.console_tab, QIcon(":icons/tab_console.png"), _("Con&sole"), "console")
|
add_optional_tab(tabs, self.console_tab, QIcon(":icons/tab_console.png"), _("Con&sole"), "console")
|
||||||
@ -186,7 +185,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
|||||||
if self.network:
|
if self.network:
|
||||||
self.network_signal.connect(self.on_network_qt)
|
self.network_signal.connect(self.on_network_qt)
|
||||||
interests = ['updated', 'new_transaction', 'status',
|
interests = ['updated', 'new_transaction', 'status',
|
||||||
'banner', 'verified', 'fee']
|
'banner', 'verified', 'fee', 'on_quotes',
|
||||||
|
'on_history', 'channel', 'channels']
|
||||||
# To avoid leaking references to "self" that prevent the
|
# To avoid leaking references to "self" that prevent the
|
||||||
# window from being GC-ed when closed, callbacks should be
|
# window from being GC-ed when closed, callbacks should be
|
||||||
# methods of this class only, and specifically not be
|
# methods of this class only, and specifically not be
|
||||||
@ -194,8 +194,6 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
|||||||
self.network.register_callback(self.on_network, interests)
|
self.network.register_callback(self.on_network, interests)
|
||||||
# set initial message
|
# set initial message
|
||||||
self.console.showMessage(self.network.banner)
|
self.console.showMessage(self.network.banner)
|
||||||
self.network.register_callback(self.on_quotes, ['on_quotes'])
|
|
||||||
self.network.register_callback(self.on_history, ['on_history'])
|
|
||||||
self.new_fx_quotes_signal.connect(self.on_fx_quotes)
|
self.new_fx_quotes_signal.connect(self.on_fx_quotes)
|
||||||
self.new_fx_history_signal.connect(self.on_fx_history)
|
self.new_fx_history_signal.connect(self.on_fx_history)
|
||||||
|
|
||||||
@ -205,9 +203,6 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
|||||||
self.connect_slots(gui_object.timer)
|
self.connect_slots(gui_object.timer)
|
||||||
self.fetch_alias()
|
self.fetch_alias()
|
||||||
|
|
||||||
def on_history(self, b):
|
|
||||||
self.new_fx_history_signal.emit()
|
|
||||||
|
|
||||||
def setup_exception_hook(self):
|
def setup_exception_hook(self):
|
||||||
Exception_Hook(self)
|
Exception_Hook(self)
|
||||||
|
|
||||||
@ -216,9 +211,6 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
|||||||
self.history_list.update()
|
self.history_list.update()
|
||||||
self.address_list.update()
|
self.address_list.update()
|
||||||
|
|
||||||
def on_quotes(self, b):
|
|
||||||
self.new_fx_quotes_signal.emit()
|
|
||||||
|
|
||||||
def on_fx_quotes(self):
|
def on_fx_quotes(self):
|
||||||
self.update_status()
|
self.update_status()
|
||||||
# Refresh edits with the new rate
|
# Refresh edits with the new rate
|
||||||
@ -302,6 +294,14 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
|||||||
elif event in ['status', 'banner', 'verified', 'fee']:
|
elif event in ['status', 'banner', 'verified', 'fee']:
|
||||||
# Handle in GUI thread
|
# Handle in GUI thread
|
||||||
self.network_signal.emit(event, args)
|
self.network_signal.emit(event, args)
|
||||||
|
elif event == 'on_quotes':
|
||||||
|
self.new_fx_quotes_signal.emit()
|
||||||
|
elif event == 'on_history':
|
||||||
|
self.new_fx_history_signal.emit()
|
||||||
|
elif event == 'channels':
|
||||||
|
self.channels_list.update_rows.emit(*args)
|
||||||
|
elif event == 'channel':
|
||||||
|
self.channels_list.update_single_row.emit(*args)
|
||||||
else:
|
else:
|
||||||
self.print_error("unexpected network message:", event, args)
|
self.print_error("unexpected network message:", event, args)
|
||||||
|
|
||||||
@ -352,6 +352,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
|||||||
self.history_list.update()
|
self.history_list.update()
|
||||||
self.address_list.update()
|
self.address_list.update()
|
||||||
self.utxo_list.update()
|
self.utxo_list.update()
|
||||||
|
wallet.lnworker.on_channels_updated()
|
||||||
self.need_update.set()
|
self.need_update.set()
|
||||||
# Once GUI has been initialized check if we want to announce something since the callback has been called before the GUI was initialized
|
# Once GUI has been initialized check if we want to announce something since the callback has been called before the GUI was initialized
|
||||||
self.notify_transactions()
|
self.notify_transactions()
|
||||||
@ -522,6 +523,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
|||||||
view_menu = menubar.addMenu(_("&View"))
|
view_menu = menubar.addMenu(_("&View"))
|
||||||
add_toggle_action(view_menu, self.addresses_tab)
|
add_toggle_action(view_menu, self.addresses_tab)
|
||||||
add_toggle_action(view_menu, self.utxo_tab)
|
add_toggle_action(view_menu, self.utxo_tab)
|
||||||
|
add_toggle_action(view_menu, self.channels_tab)
|
||||||
add_toggle_action(view_menu, self.contacts_tab)
|
add_toggle_action(view_menu, self.contacts_tab)
|
||||||
add_toggle_action(view_menu, self.console_tab)
|
add_toggle_action(view_menu, self.console_tab)
|
||||||
|
|
||||||
@ -768,9 +770,10 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
|||||||
self.invoice_list.update()
|
self.invoice_list.update()
|
||||||
self.update_completions()
|
self.update_completions()
|
||||||
|
|
||||||
def create_lightning_channels_tab(self, wallet):
|
def create_channels_tab(self, wallet):
|
||||||
self.lightning_channels_list = LightningChannelsList(self, wallet.lnworker)
|
self.channels_list = ChannelsList(self)
|
||||||
return self.lightning_channels_list
|
t = self.channels_list.get_toolbar()
|
||||||
|
return self.create_list_tab(self.channels_list, t)
|
||||||
|
|
||||||
def create_history_tab(self):
|
def create_history_tab(self):
|
||||||
from .history_list import HistoryList
|
from .history_list import HistoryList
|
||||||
@ -1795,8 +1798,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
|||||||
w.searchable_list = l
|
w.searchable_list = l
|
||||||
vbox = QVBoxLayout()
|
vbox = QVBoxLayout()
|
||||||
w.setLayout(vbox)
|
w.setLayout(vbox)
|
||||||
vbox.setContentsMargins(0, 0, 0, 0)
|
#vbox.setContentsMargins(0, 0, 0, 0)
|
||||||
vbox.setSpacing(0)
|
#vbox.setSpacing(0)
|
||||||
if toolbar:
|
if toolbar:
|
||||||
vbox.addLayout(toolbar)
|
vbox.addLayout(toolbar)
|
||||||
vbox.addWidget(l)
|
vbox.addWidget(l)
|
||||||
|
|||||||
76
gui/qt/channels_list.py
Normal file
76
gui/qt/channels_list.py
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from PyQt5 import QtCore, QtWidgets
|
||||||
|
from electrum.util import inv_dict, bh2u
|
||||||
|
from electrum.i18n import _
|
||||||
|
from .util import MyTreeWidget, SortableTreeWidgetItem
|
||||||
|
|
||||||
|
class ChannelsList(MyTreeWidget):
|
||||||
|
update_rows = QtCore.pyqtSignal(list)
|
||||||
|
update_single_row = QtCore.pyqtSignal(dict)
|
||||||
|
|
||||||
|
def __init__(self, parent):
|
||||||
|
MyTreeWidget.__init__(self, parent, self.create_menu, [_('Node ID'), _('Capacity'), _('Balance')], 0)
|
||||||
|
self.main_window = parent
|
||||||
|
self.update_rows.connect(self.do_update_rows)
|
||||||
|
self.update_single_row.connect(self.do_update_single_row)
|
||||||
|
|
||||||
|
def format_fields(self, chan):
|
||||||
|
return [bh2u(chan.node_id), self.parent.format_amount(chan.constraints.capacity), self.parent.format_amount(chan.local_state.amount_msat//1000)]
|
||||||
|
|
||||||
|
def create_menu(self, position):
|
||||||
|
menu = QtWidgets.QMenu()
|
||||||
|
cur = self.currentItem()
|
||||||
|
def close():
|
||||||
|
print("closechannel result", self.parent.network.lnworker.close_channel_from_other_thread(cur.di))
|
||||||
|
menu.addAction(_("Close channel"), close)
|
||||||
|
menu.exec_(self.viewport().mapToGlobal(position))
|
||||||
|
|
||||||
|
@QtCore.pyqtSlot(dict)
|
||||||
|
def do_update_single_row(self, chan):
|
||||||
|
items = self.findItems(chan.channel_id, QtCore.Qt.UserRole|QtCore.Qt.MatchContains|QtCore.Qt.MatchRecursive, column=1)
|
||||||
|
for item in items:
|
||||||
|
for i, v in enumerate(self.format_fields(chan)):
|
||||||
|
item.setData(i, QtCore.Qt.DisplayRole, v)
|
||||||
|
|
||||||
|
@QtCore.pyqtSlot(list)
|
||||||
|
def do_update_rows(self, channels):
|
||||||
|
self.clear()
|
||||||
|
for chan in channels:
|
||||||
|
item = SortableTreeWidgetItem(self.format_fields(chan))
|
||||||
|
item.setData(0, QtCore.Qt.UserRole, chan.channel_id)
|
||||||
|
self.insertTopLevelItem(0, item)
|
||||||
|
|
||||||
|
def get_toolbar(self):
|
||||||
|
nodeid_inp = QtWidgets.QLineEdit(self)
|
||||||
|
local_amt_inp = QtWidgets.QLineEdit(self, text='200000')
|
||||||
|
push_amt_inp = QtWidgets.QLineEdit(self, text='0')
|
||||||
|
button = QtWidgets.QPushButton(_('Open channel'), self)
|
||||||
|
button.clicked.connect(lambda: self.main_window.protect(self.open_channel, (nodeid_inp, local_amt_inp, push_amt_inp)))
|
||||||
|
l=QtWidgets.QVBoxLayout(self)
|
||||||
|
h=QtWidgets.QGridLayout(self)
|
||||||
|
nodeid_label = QtWidgets.QLabel(self)
|
||||||
|
nodeid_label.setText(_("Node ID"))
|
||||||
|
local_amt_label = QtWidgets.QLabel(self)
|
||||||
|
local_amt_label.setText("Local amount (sat)")
|
||||||
|
push_amt_label = QtWidgets.QLabel(self)
|
||||||
|
push_amt_label.setText("Push amount (sat)")
|
||||||
|
h.addWidget(nodeid_label, 0, 0)
|
||||||
|
h.addWidget(local_amt_label, 0, 1)
|
||||||
|
h.addWidget(push_amt_label, 0, 2)
|
||||||
|
h.addWidget(nodeid_inp, 1, 0)
|
||||||
|
h.addWidget(local_amt_inp, 1, 1)
|
||||||
|
h.addWidget(push_amt_inp, 1, 2)
|
||||||
|
h.addWidget(button, 1, 3)
|
||||||
|
h.setColumnStretch(0, 3)
|
||||||
|
h.setColumnStretch(1, 1)
|
||||||
|
h.setColumnStretch(2, 1)
|
||||||
|
h.setColumnStretch(3, 1)
|
||||||
|
return h
|
||||||
|
|
||||||
|
def open_channel(self, nodeIdInput, local_amt_inp, push_amt_inp, password):
|
||||||
|
node_id = str(nodeIdInput.text())
|
||||||
|
local_amt = int(local_amt_inp.text())
|
||||||
|
push_amt = int(push_amt_inp.text())
|
||||||
|
assert local_amt >= 200000
|
||||||
|
assert local_amt >= push_amt
|
||||||
|
obj = self.parent.network.lnworker.open_channel(node_id, local_amt, push_amt, password)
|
||||||
@ -1,124 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
import binascii, base64
|
|
||||||
from PyQt5 import QtCore, QtWidgets
|
|
||||||
from collections import OrderedDict
|
|
||||||
import logging
|
|
||||||
import traceback
|
|
||||||
|
|
||||||
# https://api.lightning.community/#listchannels
|
|
||||||
mapping = {0: "chan_id"}
|
|
||||||
revMapp = {"chan_id": 0}
|
|
||||||
datatable = OrderedDict([])
|
|
||||||
|
|
||||||
class MyTableRow(QtWidgets.QTreeWidgetItem):
|
|
||||||
def __init__(self, di):
|
|
||||||
strs = [str(di[mapping[key]]) for key in range(len(mapping))]
|
|
||||||
super(MyTableRow, self).__init__(strs)
|
|
||||||
assert isinstance(di, dict)
|
|
||||||
self.di = di
|
|
||||||
def __getitem__(self, idx):
|
|
||||||
return self.di[idx]
|
|
||||||
def __setitem__(self, idx, val):
|
|
||||||
self.di[idx] = val
|
|
||||||
try:
|
|
||||||
self.setData(revMapp[idx], QtCore.Qt.DisplayRole, '{0}'.format(val))
|
|
||||||
except KeyError:
|
|
||||||
logging.warning("Lightning Channel field %s unknown", idx)
|
|
||||||
def __str__(self):
|
|
||||||
return str(self.di)
|
|
||||||
|
|
||||||
def addChannelRow(new):
|
|
||||||
made = MyTableRow(new)
|
|
||||||
datatable[new["chan_id"]] = made
|
|
||||||
datatable.move_to_end(new["chan_id"], last=False)
|
|
||||||
return made
|
|
||||||
|
|
||||||
|
|
||||||
class LightningChannelsList(QtWidgets.QWidget):
|
|
||||||
update_rows = QtCore.pyqtSignal(dict)
|
|
||||||
update_single_row = QtCore.pyqtSignal(dict)
|
|
||||||
|
|
||||||
def open_channel(self, nodeIdInput, local_amt_inp, push_amt_inp, password):
|
|
||||||
node_id = str(nodeIdInput.text())
|
|
||||||
print("creating channel with {}".format(node_id))
|
|
||||||
local_amt = int(local_amt_inp.text())
|
|
||||||
push_amt = int(push_amt_inp.text())
|
|
||||||
assert local_amt >= 200000
|
|
||||||
assert local_amt >= push_amt
|
|
||||||
obj = self.lnworker.open_channel(node_id, local_amt, push_amt, password)
|
|
||||||
|
|
||||||
def create_menu(self, position):
|
|
||||||
menu = QtWidgets.QMenu()
|
|
||||||
cur = self._tv.currentItem()
|
|
||||||
def close():
|
|
||||||
print("closechannel result", lnworker.close_channel_from_other_thread(cur.di))
|
|
||||||
menu.addAction("Close channel", close)
|
|
||||||
menu.exec_(self._tv.viewport().mapToGlobal(position))
|
|
||||||
|
|
||||||
@QtCore.pyqtSlot(dict)
|
|
||||||
def do_update_single_row(self, new):
|
|
||||||
try:
|
|
||||||
obj = datatable[new["chan_id"]]
|
|
||||||
except KeyError:
|
|
||||||
print("lightning chan_id {} unknown!".format(new["chan_id"]))
|
|
||||||
else:
|
|
||||||
for k, v in new.items():
|
|
||||||
try:
|
|
||||||
if obj[k] != v: obj[k] = v
|
|
||||||
except KeyError:
|
|
||||||
obj[k] = v
|
|
||||||
|
|
||||||
@QtCore.pyqtSlot(dict)
|
|
||||||
def do_update_rows(self, obj):
|
|
||||||
self._tv.clear()
|
|
||||||
for i in obj["channels"]:
|
|
||||||
self._tv.insertTopLevelItem(0, addChannelRow(i))
|
|
||||||
|
|
||||||
def __init__(self, parent, lnworker):
|
|
||||||
QtWidgets.QWidget.__init__(self, parent)
|
|
||||||
self.main_window = parent
|
|
||||||
|
|
||||||
self.update_rows.connect(self.do_update_rows)
|
|
||||||
self.update_single_row.connect(self.do_update_single_row)
|
|
||||||
|
|
||||||
self.lnworker = lnworker
|
|
||||||
lnworker.register_callback(self.update_rows.emit, ['channels_updated'])
|
|
||||||
lnworker.register_callback(self.update_single_row.emit, ['channel_updated'])
|
|
||||||
|
|
||||||
self._tv=QtWidgets.QTreeWidget(self)
|
|
||||||
self._tv.setHeaderLabels([mapping[i] for i in range(len(mapping))])
|
|
||||||
self._tv.setColumnCount(len(mapping))
|
|
||||||
self._tv.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
|
|
||||||
self._tv.customContextMenuRequested.connect(self.create_menu)
|
|
||||||
|
|
||||||
nodeid_inp = QtWidgets.QLineEdit(self)
|
|
||||||
local_amt_inp = QtWidgets.QLineEdit(self, text='200000')
|
|
||||||
push_amt_inp = QtWidgets.QLineEdit(self, text='0')
|
|
||||||
button = QtWidgets.QPushButton('Open channel', self)
|
|
||||||
button.clicked.connect(lambda: self.main_window.protect(self.open_channel, (nodeid_inp, local_amt_inp, push_amt_inp)))
|
|
||||||
|
|
||||||
l=QtWidgets.QVBoxLayout(self)
|
|
||||||
h=QtWidgets.QGridLayout(self)
|
|
||||||
nodeid_label = QtWidgets.QLabel(self)
|
|
||||||
nodeid_label.setText("Node ID")
|
|
||||||
local_amt_label = QtWidgets.QLabel(self)
|
|
||||||
local_amt_label.setText("Local amount (sat)")
|
|
||||||
push_amt_label = QtWidgets.QLabel(self)
|
|
||||||
push_amt_label.setText("Push amount (sat)")
|
|
||||||
h.addWidget(nodeid_label, 0, 0)
|
|
||||||
h.addWidget(local_amt_label, 0, 1)
|
|
||||||
h.addWidget(push_amt_label, 0, 2)
|
|
||||||
|
|
||||||
h.addWidget(nodeid_inp, 1, 0)
|
|
||||||
h.addWidget(local_amt_inp, 1, 1)
|
|
||||||
h.addWidget(push_amt_inp, 1, 2)
|
|
||||||
h.addWidget(button, 1, 3)
|
|
||||||
h.setColumnStretch(0, 3)
|
|
||||||
h.setColumnStretch(1, 1)
|
|
||||||
h.setColumnStretch(2, 1)
|
|
||||||
h.setColumnStretch(3, 1)
|
|
||||||
l.addLayout(h)
|
|
||||||
l.addWidget(self._tv)
|
|
||||||
|
|
||||||
self.resize(2500,1000)
|
|
||||||
lnworker.on_channels_updated()
|
|
||||||
@ -1,153 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
import base64
|
|
||||||
import binascii
|
|
||||||
from PyQt5 import QtCore, QtWidgets
|
|
||||||
from collections import OrderedDict
|
|
||||||
import logging
|
|
||||||
from .qrcodewidget import QRDialog
|
|
||||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot
|
|
||||||
|
|
||||||
mapping = {0: "r_hash", 1: "pay_req", 2: "settled"}
|
|
||||||
revMapp = {"r_hash": 0, "pay_req": 1, "settled": 2}
|
|
||||||
datatable = OrderedDict([])
|
|
||||||
idx = 0
|
|
||||||
|
|
||||||
class MyTableRow(QtWidgets.QTreeWidgetItem):
|
|
||||||
def __init__(self, di):
|
|
||||||
if "settled" not in di:
|
|
||||||
di["settled"] = False
|
|
||||||
strs = [str(di[mapping[key]]) for key in range(len(mapping))]
|
|
||||||
print(strs)
|
|
||||||
super(MyTableRow, self).__init__(strs)
|
|
||||||
assert isinstance(di, dict)
|
|
||||||
self.di = di
|
|
||||||
def __getitem__(self, idx):
|
|
||||||
return self.di[idx]
|
|
||||||
def __setitem__(self, idx, val):
|
|
||||||
self.di[idx] = val
|
|
||||||
try:
|
|
||||||
self.setData(revMapp[idx], QtCore.Qt.DisplayRole, '{0}'.format(val))
|
|
||||||
except KeyError:
|
|
||||||
logging.warning("Lightning Invoice field %s unknown", idx)
|
|
||||||
def __str__(self):
|
|
||||||
return str(self.di)
|
|
||||||
|
|
||||||
def addInvoiceRow(new):
|
|
||||||
made = MyTableRow(new)
|
|
||||||
datatable[new["r_hash"]] = made
|
|
||||||
datatable.move_to_end(new["r_hash"], last=False)
|
|
||||||
return made
|
|
||||||
|
|
||||||
class LightningInvoiceList(QtWidgets.QWidget):
|
|
||||||
invoice_added_signal = QtCore.pyqtSignal(dict)
|
|
||||||
|
|
||||||
@QtCore.pyqtSlot(dict)
|
|
||||||
def invoice_added_handler(self, di):
|
|
||||||
self._tv.insertTopLevelItem(0, addInvoiceRow(invoice))
|
|
||||||
|
|
||||||
def clickHandler(self, numInput, treeView, lnworker):
|
|
||||||
amt = numInput.value()
|
|
||||||
if amt < 1:
|
|
||||||
print("value too small")
|
|
||||||
return
|
|
||||||
print("creating invoice with value {}".format(amt))
|
|
||||||
global idx
|
|
||||||
#obj = {
|
|
||||||
# "r_hash": binascii.hexlify((int.from_bytes(bytearray.fromhex("9500edb0994b7bc23349193486b25c82097045db641f35fa988c0e849acdec29"), "big")+idx).to_bytes(byteorder="big", length=32)).decode("ascii"),
|
|
||||||
# "pay_req": "lntb81920n1pdf258s" + str(idx),
|
|
||||||
# "settled": False
|
|
||||||
#}
|
|
||||||
#treeView.insertTopLevelItem(0, addInvoiceRow(obj))
|
|
||||||
idx += 1
|
|
||||||
lnworker.add_invoice(amt)
|
|
||||||
|
|
||||||
def create_menu(self, position):
|
|
||||||
menu = QtWidgets.QMenu()
|
|
||||||
pay_req = self._tv.currentItem()["pay_req"]
|
|
||||||
cb = QtWidgets.QApplication.instance().clipboard()
|
|
||||||
def copy():
|
|
||||||
print(pay_req)
|
|
||||||
cb.setText(pay_req)
|
|
||||||
def qr():
|
|
||||||
d = QRDialog(pay_req, self, "Lightning invoice")
|
|
||||||
d.exec_()
|
|
||||||
menu.addAction("Copy payment request", copy)
|
|
||||||
menu.addAction("Show payment request as QR code", qr)
|
|
||||||
menu.exec_(self._tv.viewport().mapToGlobal(position))
|
|
||||||
|
|
||||||
payment_received_signal = pyqtSignal(dict)
|
|
||||||
|
|
||||||
@pyqtSlot(dict)
|
|
||||||
def paymentReceived(self, new):
|
|
||||||
try:
|
|
||||||
obj = datatable[new["r_hash"]]
|
|
||||||
except KeyError:
|
|
||||||
print("lightning payment invoice r_hash {} unknown!".format(new["r_hash"]))
|
|
||||||
else:
|
|
||||||
for k, v in new.items():
|
|
||||||
try:
|
|
||||||
if obj[k] != v: obj[k] = v
|
|
||||||
except KeyError:
|
|
||||||
obj[k] = v
|
|
||||||
|
|
||||||
def __init__(self, parent, lnworker):
|
|
||||||
QtWidgets.QWidget.__init__(self, parent)
|
|
||||||
|
|
||||||
self.payment_received_signal.connect(self.paymentReceived)
|
|
||||||
self.invoice_added_signal.connect(self.invoice_added_handler)
|
|
||||||
|
|
||||||
#lnworker.subscribe_payment_received_from_other_thread(self.payment_received_signal.emit)
|
|
||||||
#lnworker.subscribe_invoice_added_from_other_thread(self.invoice_added_signal.emit)
|
|
||||||
|
|
||||||
self._tv=QtWidgets.QTreeWidget(self)
|
|
||||||
self._tv.setHeaderLabels([mapping[i] for i in range(len(mapping))])
|
|
||||||
self._tv.setColumnCount(len(mapping))
|
|
||||||
self._tv.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
|
|
||||||
self._tv.customContextMenuRequested.connect(self.create_menu)
|
|
||||||
|
|
||||||
class SatoshiCountSpinBox(QtWidgets.QSpinBox):
|
|
||||||
def keyPressEvent(self2, e):
|
|
||||||
super(SatoshiCountSpinBox, self2).keyPressEvent(e)
|
|
||||||
if QtCore.Qt.Key_Return == e.key():
|
|
||||||
self.clickHandler(self2, self._tv, lnworker)
|
|
||||||
|
|
||||||
numInput = SatoshiCountSpinBox(self)
|
|
||||||
|
|
||||||
button = QtWidgets.QPushButton('Add invoice', self)
|
|
||||||
button.clicked.connect(lambda: self.clickHandler(numInput, self._tv, lnworker))
|
|
||||||
|
|
||||||
l=QtWidgets.QVBoxLayout(self)
|
|
||||||
h=QtWidgets.QGridLayout(self)
|
|
||||||
h.addWidget(numInput, 0, 0)
|
|
||||||
h.addWidget(button, 0, 1)
|
|
||||||
#h.addItem(QtWidgets.QSpacerItem(100, 200, QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred), 0, 2)
|
|
||||||
#h.setSizePolicy(
|
|
||||||
h.setColumnStretch(0, 1)
|
|
||||||
h.setColumnStretch(1, 1)
|
|
||||||
h.setColumnStretch(2, 2)
|
|
||||||
l.addLayout(h)
|
|
||||||
l.addWidget(self._tv)
|
|
||||||
|
|
||||||
self.resize(2500,1000)
|
|
||||||
|
|
||||||
def tick():
|
|
||||||
key = "9500edb0994b7bc23349193486b25c82097045db641f35fa988c0e849acdec29"
|
|
||||||
if not key in datatable:
|
|
||||||
return
|
|
||||||
row = datatable[key]
|
|
||||||
row["settled"] = not row["settled"]
|
|
||||||
print("data changed")
|
|
||||||
|
|
||||||
if __name__=="__main__":
|
|
||||||
from sys import argv, exit
|
|
||||||
|
|
||||||
a=QtWidgets.QApplication(argv)
|
|
||||||
|
|
||||||
w=LightningInvoiceList()
|
|
||||||
w.show()
|
|
||||||
w.raise_()
|
|
||||||
|
|
||||||
timer = QtCore.QTimer()
|
|
||||||
timer.timeout.connect(tick)
|
|
||||||
timer.start(1000)
|
|
||||||
exit(a.exec_())
|
|
||||||
@ -135,7 +135,7 @@ class LNWorker(PrintError):
|
|||||||
dumped = serialize_channels(self.channels)
|
dumped = serialize_channels(self.channels)
|
||||||
self.wallet.storage.put("channels", dumped)
|
self.wallet.storage.put("channels", dumped)
|
||||||
self.wallet.storage.write()
|
self.wallet.storage.write()
|
||||||
self.trigger_callback('channel_updated', {"chan_id": openchannel.channel_id})
|
self.network.trigger_callback('channel', openchannel)
|
||||||
|
|
||||||
def save_short_chan_id(self, chan):
|
def save_short_chan_id(self, chan):
|
||||||
"""
|
"""
|
||||||
@ -188,8 +188,7 @@ class LNWorker(PrintError):
|
|||||||
self.on_channels_updated()
|
self.on_channels_updated()
|
||||||
|
|
||||||
def on_channels_updated(self):
|
def on_channels_updated(self):
|
||||||
std_chan = [{"chan_id": chan.channel_id} for chan in self.channels.values()]
|
self.network.trigger_callback('channels', list(self.channels.values()))
|
||||||
self.trigger_callback('channels_updated', {'channels':std_chan})
|
|
||||||
|
|
||||||
def open_channel(self, node_id, local_amt_sat, push_amt_sat, pw):
|
def open_channel(self, node_id, local_amt_sat, push_amt_sat, pw):
|
||||||
coro = self._open_channel_coroutine(node_id, local_amt_sat, push_amt_sat, None if pw == "" else pw)
|
coro = self._open_channel_coroutine(node_id, local_amt_sat, push_amt_sat, None if pw == "" else pw)
|
||||||
@ -199,7 +198,7 @@ class LNWorker(PrintError):
|
|||||||
coro = self._pay_coroutine(invoice)
|
coro = self._pay_coroutine(invoice)
|
||||||
return asyncio.run_coroutine_threadsafe(coro, self.network.asyncio_loop)
|
return asyncio.run_coroutine_threadsafe(coro, self.network.asyncio_loop)
|
||||||
|
|
||||||
# not aiosafe because we call .result() which will propagate an exception
|
@aiosafe
|
||||||
async def _pay_coroutine(self, invoice):
|
async def _pay_coroutine(self, invoice):
|
||||||
openchannel = next(iter(self.channels.values()))
|
openchannel = next(iter(self.channels.values()))
|
||||||
addr = lndecode(invoice, expected_hrp=constants.net.SEGWIT_HRP)
|
addr = lndecode(invoice, expected_hrp=constants.net.SEGWIT_HRP)
|
||||||
@ -233,19 +232,3 @@ class LNWorker(PrintError):
|
|||||||
|
|
||||||
def list_channels(self):
|
def list_channels(self):
|
||||||
return serialize_channels(self.channels)
|
return serialize_channels(self.channels)
|
||||||
|
|
||||||
def register_callback(self, callback, events):
|
|
||||||
with self.lock:
|
|
||||||
for event in events:
|
|
||||||
self.callbacks[event].append(callback)
|
|
||||||
|
|
||||||
def unregister_callback(self, callback):
|
|
||||||
with self.lock:
|
|
||||||
for callbacks in self.callbacks.values():
|
|
||||||
if callback in callbacks:
|
|
||||||
callbacks.remove(callback)
|
|
||||||
|
|
||||||
def trigger_callback(self, event, *args):
|
|
||||||
with self.lock:
|
|
||||||
callbacks = self.callbacks[event][:]
|
|
||||||
[callback(*args) for callback in callbacks]
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user