Files
pallectrum/electrum/gui/qt/lightning_dialog.py

146 lines
5.2 KiB
Python
Raw Normal View History

2019-01-30 17:24:43 +01:00
#!/usr/bin/env python
#
# Electrum - lightweight Bitcoin client
# Copyright (C) 2012 thomasv@gitorious
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import socket
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
import PyQt5.QtCore as QtCore
from electrum.i18n import _
from .util import *
2019-02-28 06:08:58 +01:00
help_about = _("""The local watchtower will persist on this computer after you close
your wallet, but it requires to be online regularly.""")
help_remote = _(""" To setup a remote watchtower, configure a remote electrum daemon
with 'watchtower_host' and 'watchtower_port' """)
class WatcherList(MyTreeView):
def __init__(self, parent):
super().__init__(parent, self.create_menu, stretch_column=0, editable_columns=[])
self.setModel(QStandardItemModel(self))
self.setSortingEnabled(True)
self.update()
def create_menu(self, x):
pass
def update(self):
if self.parent.lnwatcher is None:
return
2019-02-28 06:08:58 +01:00
self.model().clear()
self.update_headers({0:_('Outpoint'), 1:_('Tx'), 2:_('Status')})
sweepstore = self.parent.lnwatcher.sweepstore
for outpoint in sweepstore.list_sweep_tx():
2019-03-12 18:33:36 +01:00
n = sweepstore.get_num_tx(outpoint)
2019-02-28 06:08:58 +01:00
status = self.parent.lnwatcher.get_channel_status(outpoint)
items = [QStandardItem(e) for e in [outpoint, "%d"%n, status]]
2019-02-28 06:08:58 +01:00
self.model().insertRow(self.model().rowCount(), items)
2019-01-30 17:24:43 +01:00
2019-05-07 09:10:23 +02:00
class LightningDialog(QDialog):
2019-01-30 17:24:43 +01:00
def __init__(self, gui_object):
QDialog.__init__(self)
self.gui_object = gui_object
self.config = gui_object.config
2019-05-07 09:10:23 +02:00
self.network = gui_object.daemon.network
self.lnwatcher = self.network.lnwatcher
self.setWindowTitle(_('Lightning'))
2019-01-30 17:24:43 +01:00
self.setMinimumSize(600, 20)
watchtower_url = self.config.get('watchtower_url')
self.watchtower_e = QLineEdit(watchtower_url)
2019-05-07 09:10:23 +02:00
self.watcher_list = WatcherList(self)
# channel_db
network_w = QWidget()
network_vbox = QVBoxLayout(network_w)
2019-05-13 22:33:56 +02:00
self.num_peers = QLabel('')
network_vbox.addWidget(self.num_peers)
2019-05-07 09:10:23 +02:00
self.status = QLabel('')
network_vbox.addWidget(self.status)
2019-05-13 22:33:56 +02:00
network_vbox.addStretch(1)
2019-02-28 06:08:58 +01:00
# local
local_w = QWidget()
vbox_local = QVBoxLayout(local_w)
vbox_local.addWidget(WWLabel(help_about))
2019-05-07 09:10:23 +02:00
vbox_local.addWidget(self.watcher_list)
2019-02-28 06:08:58 +01:00
# remote
remote_w = QWidget()
vbox_remote = QVBoxLayout(remote_w)
vbox_remote.addWidget(WWLabel(help_remote))
g = QGridLayout(remote_w)
g.addWidget(QLabel(_('URL') + ':'), 1, 0)
2019-01-30 17:24:43 +01:00
g.addWidget(self.watchtower_e, 1, 1)
2019-02-28 06:08:58 +01:00
vbox_remote.addLayout(g)
vbox_remote.addStretch(1)
# tabs
tabs = QTabWidget()
2019-05-07 09:10:23 +02:00
tabs.addTab(network_w, _('Network'))
tabs.addTab(local_w, _('Watchtower'))
tabs.addTab(remote_w, _('Settings'))
2019-02-28 06:08:58 +01:00
vbox = QVBoxLayout(self)
vbox.addWidget(tabs)
2019-01-30 17:24:43 +01:00
b = QPushButton(_('Close'))
b.clicked.connect(self.on_close)
vbox.addLayout(Buttons(b))
2019-05-07 09:10:23 +02:00
self.watcher_list.update()
2019-05-13 22:33:56 +02:00
self.network.register_callback(self.update_status, ['ln_status'])
2019-05-07 09:10:23 +02:00
2019-05-13 22:33:56 +02:00
def update_status(self, event):
2019-05-07 09:10:23 +02:00
if self.network.lngossip is None:
return
channel_db = self.network.channel_db
num_peers = sum([p.initialized.is_set() for p in self.network.lngossip.peers.values()])
2019-05-13 22:33:56 +02:00
self.num_peers.setText(f'{num_peers} peers, {channel_db.num_nodes} nodes')
known = channel_db.num_channels
unknown = len(self.network.lngossip.unknown_ids)
msg = _(f'Channels: {known} of {known + unknown}')
2019-05-07 09:10:23 +02:00
self.status.setText(msg)
2019-01-30 17:24:43 +01:00
def on_close(self):
url = self.watchtower_e.text()
if url:
self.lnwatcher.set_remote_watchtower()
self.hide()
def is_hidden(self):
return self.isMinimized() or self.isHidden()
def show_or_hide(self):
if self.is_hidden():
self.bring_to_top()
else:
self.hide()
def bring_to_top(self):
self.show()
self.raise_()
def closeEvent(self, event):
self.gui_object.watchtower_window = None
event.accept()