URI: 
       tlightning_tx_dialog.py - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
       tlightning_tx_dialog.py (4669B)
       ---
            1 #!/usr/bin/env python
            2 #
            3 # Electrum - lightweight Bitcoin client
            4 # Copyright (C) 2020 The Electrum Developers
            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 typing import TYPE_CHECKING
           27 from decimal import Decimal
           28 import datetime
           29 
           30 from PyQt5.QtGui import QFont
           31 from PyQt5.QtWidgets import QVBoxLayout, QLabel, QGridLayout
           32 
           33 from electrum.i18n import _
           34 from electrum.invoices import LNInvoice
           35 
           36 from .util import WindowModalDialog, ButtonsLineEdit, ColorScheme, Buttons, CloseButton, MONOSPACE_FONT
           37 from .qrtextedit import ShowQRTextEdit
           38 
           39 if TYPE_CHECKING:
           40     from .main_window import ElectrumWindow
           41 
           42 
           43 
           44 class LightningTxDialog(WindowModalDialog):
           45 
           46     def __init__(self, parent: 'ElectrumWindow', tx_item: dict):
           47         WindowModalDialog.__init__(self, parent, _("Lightning Payment"))
           48         self.parent = parent
           49         self.is_sent = bool(tx_item['direction'] == 'sent')
           50         self.label = tx_item['label']
           51         self.timestamp = tx_item['timestamp']
           52         self.amount = Decimal(tx_item['amount_msat']) / 1000
           53         self.payment_hash = tx_item['payment_hash']
           54         self.preimage = tx_item['preimage']
           55         invoice = (self.parent.wallet.get_invoice(self.payment_hash)
           56                    or self.parent.wallet.get_request(self.payment_hash))
           57         if invoice:
           58             assert isinstance(invoice, LNInvoice), f"{self.invoice!r}"
           59             self.invoice = invoice.invoice
           60         else:
           61             self.invoice = ''
           62 
           63         self.setMinimumWidth(700)
           64         vbox = QVBoxLayout()
           65         self.setLayout(vbox)
           66 
           67         # FIXME fiat values here are using today's FX rate instead of historical
           68         vbox.addWidget(QLabel(_("Amount") + ": " + self.parent.format_amount_and_units(self.amount)))
           69         if self.is_sent:
           70             fee = Decimal(tx_item['fee_msat']) / 1000
           71             vbox.addWidget(QLabel(_("Fee") + ": " + self.parent.format_amount_and_units(fee)))
           72         time_str = datetime.datetime.fromtimestamp(self.timestamp).isoformat(' ')[:-3]
           73         vbox.addWidget(QLabel(_("Date") + ": " + time_str))
           74 
           75         qr_icon = "qrcode_white.png" if ColorScheme.dark_scheme else "qrcode.png"
           76 
           77         vbox.addWidget(QLabel(_("Payment hash") + ":"))
           78         self.hash_e = ButtonsLineEdit(self.payment_hash)
           79         self.hash_e.addCopyButton(self.parent.app)
           80         self.hash_e.addButton(qr_icon,
           81                               self.show_qr(self.hash_e, _("Payment hash")),
           82                               _("Show QR Code"))
           83         self.hash_e.setReadOnly(True)
           84         self.hash_e.setFont(QFont(MONOSPACE_FONT))
           85         vbox.addWidget(self.hash_e)
           86 
           87         vbox.addWidget(QLabel(_("Preimage") + ":"))
           88         self.preimage_e = ButtonsLineEdit(self.preimage)
           89         self.preimage_e.addCopyButton(self.parent.app)
           90         self.preimage_e.addButton(qr_icon,
           91                                   self.show_qr(self.preimage_e, _("Preimage")),
           92                                   _("Show QR Code"))
           93         self.preimage_e.setReadOnly(True)
           94         self.preimage_e.setFont(QFont(MONOSPACE_FONT))
           95         vbox.addWidget(self.preimage_e)
           96 
           97         vbox.addWidget(QLabel(_("Lightning Invoice") + ":"))
           98         self.invoice_e = ShowQRTextEdit(self.invoice, config=parent.config)
           99         self.invoice_e.setMaximumHeight(150)
          100         self.invoice_e.addCopyButton(self.parent.app)
          101         vbox.addWidget(self.invoice_e)
          102 
          103         vbox.addLayout(Buttons(CloseButton(self)))
          104 
          105     def show_qr(self, line_edit, title=''):
          106         def f():
          107             text = line_edit.text()
          108             try:
          109                 self.parent.show_qrcode(text, title, parent=self)
          110             except Exception as e:
          111                 self.show_message(repr(e))
          112         return f