electrum

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

watchtower_dialog.py (3487B)


      1 #!/usr/bin/env python
      2 #
      3 # Electrum - lightweight Bitcoin client
      4 # Copyright (C) 2012 thomasv@gitorious
      5 #
      6 # Permission is hereby granted, free of charge, to any person
      7 # obtaining a copy of this software and associated documentation files
      8 # (the "Software"), to deal in the Software without restriction,
      9 # including without limitation the rights to use, copy, modify, merge,
     10 # publish, distribute, sublicense, and/or sell copies of the Software,
     11 # and to permit persons to whom the Software is furnished to do so,
     12 # subject to the following conditions:
     13 #
     14 # The above copyright notice and this permission notice shall be
     15 # included in all copies or substantial portions of the Software.
     16 #
     17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     20 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
     21 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
     22 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
     23 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     24 # SOFTWARE.
     25 
     26 from PyQt5.QtGui import QStandardItemModel, QStandardItem
     27 from PyQt5.QtCore import Qt
     28 from PyQt5.QtWidgets import (QDialog, QVBoxLayout, QPushButton, QLabel)
     29 
     30 from electrum.i18n import _
     31 from .util import MyTreeView, Buttons
     32 
     33 
     34 class WatcherList(MyTreeView):
     35     def __init__(self, parent):
     36         super().__init__(parent, self.create_menu, stretch_column=0, editable_columns=[])
     37         self.setModel(QStandardItemModel(self))
     38         self.setSortingEnabled(True)
     39         self.update()
     40 
     41     def create_menu(self, x):
     42         pass
     43 
     44     def update(self):
     45         if self.parent.lnwatcher is None:
     46             return
     47         self.model().clear()
     48         self.update_headers({0:_('Outpoint'), 1:_('Tx'), 2:_('Status')})
     49         lnwatcher = self.parent.lnwatcher
     50         l = lnwatcher.list_sweep_tx()
     51         for outpoint in l:
     52             n = lnwatcher.get_num_tx(outpoint)
     53             status = lnwatcher.get_channel_status(outpoint)
     54             items = [QStandardItem(e) for e in [outpoint, "%d"%n, status]]
     55             self.model().insertRow(self.model().rowCount(), items)
     56         size = lnwatcher.sweepstore.filesize()
     57         self.parent.size_label.setText('Database size: %.2f Mb'%(size/1024/1024.))
     58 
     59 
     60 class WatchtowerDialog(QDialog):
     61 
     62     def __init__(self, gui_object):
     63         QDialog.__init__(self)
     64         self.gui_object = gui_object
     65         self.config = gui_object.config
     66         self.network = gui_object.daemon.network
     67         assert self.network
     68         self.lnwatcher = self.network.local_watchtower
     69         self.setWindowTitle(_('Watchtower'))
     70         self.setMinimumSize(600, 20)
     71         self.size_label = QLabel()
     72         self.watcher_list = WatcherList(self)
     73 
     74         vbox = QVBoxLayout(self)
     75         vbox.addWidget(self.size_label)
     76         vbox.addWidget(self.watcher_list)
     77         b = QPushButton(_('Close'))
     78         b.clicked.connect(self.close)
     79         vbox.addLayout(Buttons(b))
     80         self.watcher_list.update()
     81 
     82     def is_hidden(self):
     83         return self.isMinimized() or self.isHidden()
     84 
     85     def show_or_hide(self):
     86         if self.is_hidden():
     87             self.bring_to_top()
     88         else:
     89             self.hide()
     90 
     91     def bring_to_top(self):
     92         self.show()
     93         self.raise_()
     94 
     95     def closeEvent(self, event):
     96         self.gui_object.watchtower_dialog = None
     97         event.accept()