electrum

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

address_dialog.py (4676B)


      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 typing import TYPE_CHECKING
     27 
     28 from PyQt5.QtWidgets import QVBoxLayout, QLabel
     29 
     30 from electrum.i18n import _
     31 
     32 from .util import WindowModalDialog, ButtonsLineEdit, ColorScheme, Buttons, CloseButton
     33 from .history_list import HistoryList, HistoryModel
     34 from .qrtextedit import ShowQRTextEdit
     35 
     36 if TYPE_CHECKING:
     37     from .main_window import ElectrumWindow
     38 
     39 
     40 class AddressHistoryModel(HistoryModel):
     41     def __init__(self, parent: 'ElectrumWindow', address):
     42         super().__init__(parent)
     43         self.address = address
     44 
     45     def get_domain(self):
     46         return [self.address]
     47 
     48     def should_include_lightning_payments(self) -> bool:
     49         return False
     50 
     51 
     52 class AddressDialog(WindowModalDialog):
     53 
     54     def __init__(self, parent: 'ElectrumWindow', address: str):
     55         WindowModalDialog.__init__(self, parent, _("Address"))
     56         self.address = address
     57         self.parent = parent
     58         self.config = parent.config
     59         self.wallet = parent.wallet
     60         self.app = parent.app
     61         self.saved = True
     62 
     63         self.setMinimumWidth(700)
     64         vbox = QVBoxLayout()
     65         self.setLayout(vbox)
     66 
     67         vbox.addWidget(QLabel(_("Address") + ":"))
     68         self.addr_e = ButtonsLineEdit(self.address)
     69         self.addr_e.addCopyButton(self.app)
     70         icon = "qrcode_white.png" if ColorScheme.dark_scheme else "qrcode.png"
     71         self.addr_e.addButton(icon, self.show_qr, _("Show QR Code"))
     72         self.addr_e.setReadOnly(True)
     73         vbox.addWidget(self.addr_e)
     74 
     75         try:
     76             pubkeys = self.wallet.get_public_keys(address)
     77         except BaseException as e:
     78             pubkeys = None
     79         if pubkeys:
     80             vbox.addWidget(QLabel(_("Public keys") + ':'))
     81             for pubkey in pubkeys:
     82                 pubkey_e = ButtonsLineEdit(pubkey)
     83                 pubkey_e.addCopyButton(self.app)
     84                 pubkey_e.setReadOnly(True)
     85                 vbox.addWidget(pubkey_e)
     86 
     87         redeem_script = self.wallet.get_redeem_script(address)
     88         if redeem_script:
     89             vbox.addWidget(QLabel(_("Redeem Script") + ':'))
     90             redeem_e = ShowQRTextEdit(text=redeem_script, config=self.config)
     91             redeem_e.addCopyButton(self.app)
     92             vbox.addWidget(redeem_e)
     93 
     94         witness_script = self.wallet.get_witness_script(address)
     95         if witness_script:
     96             vbox.addWidget(QLabel(_("Witness Script") + ':'))
     97             witness_e = ShowQRTextEdit(text=witness_script, config=self.config)
     98             witness_e.addCopyButton(self.app)
     99             vbox.addWidget(witness_e)
    100 
    101         address_path_str = self.wallet.get_address_path_str(address)
    102         if address_path_str:
    103             vbox.addWidget(QLabel(_("Derivation path") + ':'))
    104             der_path_e = ButtonsLineEdit(address_path_str)
    105             der_path_e.addCopyButton(self.app)
    106             der_path_e.setReadOnly(True)
    107             vbox.addWidget(der_path_e)
    108 
    109         vbox.addWidget(QLabel(_("History")))
    110         addr_hist_model = AddressHistoryModel(self.parent, self.address)
    111         self.hw = HistoryList(self.parent, addr_hist_model)
    112         addr_hist_model.set_view(self.hw)
    113         vbox.addWidget(self.hw)
    114 
    115         vbox.addLayout(Buttons(CloseButton(self)))
    116         self.format_amount = self.parent.format_amount
    117         addr_hist_model.refresh('address dialog constructor')
    118 
    119     def show_qr(self):
    120         text = self.address
    121         try:
    122             self.parent.show_qrcode(text, 'Address', parent=self)
    123         except Exception as e:
    124             self.show_message(repr(e))