URI: 
       tinvoices: minor clean-up (type hints, mark broken things) - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 0b224ba685b7c4e0fb57f69a31f1f330119233a6
   DIR parent 23ea64808d139b45ea7ed2bb0f39e63aaa9bce58
  HTML Author: SomberNight <somber.night@protonmail.com>
       Date:   Sat, 13 Jun 2020 18:54:22 +0200
       
       invoices: minor clean-up (type hints, mark broken things)
       
       also rm some dead code
       
       Diffstat:
         M electrum/gui/qt/main_window.py      |      12 ------------
         M electrum/invoices.py                |       2 +-
         M electrum/paymentrequest.py          |      14 ++++++++------
         M electrum/plugins/email_requests/qt… |       3 ++-
         M electrum/wallet.py                  |      27 ++++++++++++++++++---------
       
       5 files changed, 29 insertions(+), 29 deletions(-)
       ---
   DIR diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py
       t@@ -1159,7 +1159,6 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
        
            def sign_payment_request(self, addr):
                alias = self.config.get('alias')
       -        alias_privkey = None
                if alias and self.alias_info:
                    alias_addr, alias_name, validated = self.alias_info
                    if alias_addr:
       t@@ -1230,17 +1229,6 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
                    tooltip_text = _("{} copied to clipboard").format(title)
                QToolTip.showText(QCursor.pos(), tooltip_text, self)
        
       -    def export_payment_request(self, addr):
       -        r = self.wallet.receive_requests.get(addr)
       -        pr = paymentrequest.serialize_request(r).SerializeToString()
       -        name = r.id + '.bip70'
       -        fileName = self.getSaveFileName(_("Select where to save your payment request"), name, "*.bip70")
       -        if fileName:
       -            with open(fileName, "wb+") as f:
       -                f.write(util.to_bytes(pr))
       -            self.show_message(_("Request saved successfully"))
       -            self.saved = True
       -
            def clear_receive_tab(self):
                self.receive_payreq_e.setText('')
                self.receive_address_e.setText('')
   DIR diff --git a/electrum/invoices.py b/electrum/invoices.py
       t@@ -115,7 +115,7 @@ class OnchainInvoice(Invoice):
                    id=pr.get_id(),
                    time=pr.get_time(),
                    exp=pr.get_expiration_date() - pr.get_time(),
       -            bip70=pr.raw.hex() if pr else None,
       +            bip70=pr.raw.hex(),
                    requestor=pr.get_requestor(),
                )
        
   DIR diff --git a/electrum/paymentrequest.py b/electrum/paymentrequest.py
       t@@ -25,7 +25,7 @@
        import hashlib
        import sys
        import time
       -from typing import Optional, List
       +from typing import Optional, List, TYPE_CHECKING
        import asyncio
        import urllib.parse
        
       t@@ -41,13 +41,16 @@ except ImportError:
        
        from . import bitcoin, ecc, util, transaction, x509, rsakey
        from .util import bh2u, bfh, make_aiohttp_session
       -from .invoices import PR_UNPAID, PR_EXPIRED, PR_PAID, PR_UNKNOWN, PR_INFLIGHT
       +from .invoices import OnchainInvoice
        from .crypto import sha256
        from .bitcoin import address_to_script
        from .transaction import PartialTxOutput
        from .network import Network
        from .logging import get_logger, Logger
        
       +if TYPE_CHECKING:
       +    from .simple_config import SimpleConfig
       +
        
        _logger = get_logger(__name__)
        
       t@@ -315,8 +318,7 @@ class PaymentRequest:
                    return False, error
        
        
       -def make_unsigned_request(req):
       -    from .transaction import Transaction
       +def make_unsigned_request(req: 'OnchainInvoice'):
            addr = req.get_address()
            time = req.time
            exp = req.exp
       t@@ -444,7 +446,7 @@ def sign_request_with_x509(pr, key_path, cert_path):
            pr.signature = bytes(sig)
        
        
       -def serialize_request(req):
       +def serialize_request(req):  # FIXME this is broken
            pr = make_unsigned_request(req)
            signature = req.get('sig')
            requestor = req.get('name')
       t@@ -455,7 +457,7 @@ def serialize_request(req):
            return pr
        
        
       -def make_request(config, req):
       +def make_request(config: 'SimpleConfig', req: 'OnchainInvoice'):
            pr = make_unsigned_request(req)
            key_path = config.get('ssl_keyfile')
            cert_path = config.get('ssl_certfile')
   DIR diff --git a/electrum/plugins/email_requests/qt.py b/electrum/plugins/email_requests/qt.py
       t@@ -44,6 +44,7 @@ from PyQt5.QtWidgets import (QVBoxLayout, QLabel, QGridLayout, QLineEdit,
        
        from electrum.gui.qt.util import (EnterButton, Buttons, CloseButton, OkButton,
                                          WindowModalDialog, get_parent_main_window)
       +from electrum.gui.qt.main_window import ElectrumWindow
        
        from electrum.plugin import BasePlugin, hook
        from electrum.paymentrequest import PaymentRequest
       t@@ -179,7 +180,7 @@ class Plugin(BasePlugin):
                window = get_parent_main_window(menu)
                menu.addAction(_("Send via e-mail"), lambda: self.send(window, addr))
        
       -    def send(self, window, addr):
       +    def send(self, window: ElectrumWindow, addr):  # FIXME this is broken
                from electrum import paymentrequest
                r = window.wallet.receive_requests.get(addr)
                message = r.get('memo', '')
   DIR diff --git a/electrum/wallet.py b/electrum/wallet.py
       t@@ -267,7 +267,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
                self.frozen_addresses      = set(db.get('frozen_addresses', []))
                self.frozen_coins          = set(db.get('frozen_coins', []))  # set of txid:vout strings
                self.fiat_value            = db.get_dict('fiat_value')
       -        self.receive_requests      = db.get_dict('payment_requests')
       +        self.receive_requests      = db.get_dict('payment_requests')  # type: Dict[str, Invoice]
                self.invoices              = db.get_dict('invoices')  # type: Dict[str, Invoice]
                self._reserved_addresses   = set(db.get('reserved_addresses', []))
        
       t@@ -1624,7 +1624,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
                        return True, conf
                return False, None
        
       -    def get_request_URI(self, req: Invoice):
       +    def get_request_URI(self, req: OnchainInvoice) -> str:
                addr = req.get_address()
                message = self.labels.get(addr, '')
                amount = req.amount
       t@@ -1674,8 +1674,13 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
                if x:
                    return self.export_request(x)
        
       -    def export_request(self, x):
       -        key = x.rhash if x.is_lightning() else x.get_address()
       +    def export_request(self, x: Invoice) -> Dict[str, Any]:
       +        if x.is_lightning():
       +            assert isinstance(x, LNInvoice)
       +            key = x.rhash
       +        else:
       +            assert isinstance(x, OnchainInvoice)
       +            key = x.get_address()
                status = self.get_request_status(key)
                status_str = x.get_status_str(status)
                is_lightning = x.is_lightning()
       t@@ -1695,7 +1700,6 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
                    if self.lnworker and status == PR_UNPAID:
                        d['can_receive'] = self.lnworker.can_receive_invoice(x)
                else:
       -            #key = x.id
                    addr = x.get_address()
                    paid, conf = self.get_payment_status(addr, x.amount)
                    d['address'] = addr
       t@@ -1715,7 +1719,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
                        d['bip70_url'] = request_url
                return d
        
       -    def export_invoice(self, x):
       +    def export_invoice(self, x: Invoice) -> Dict[str, Any]:
                status = self.get_invoice_status(x)
                status_str = x.get_status_str(status)
                is_lightning = x.is_lightning()
       t@@ -1730,10 +1734,12 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
                    'status_str': status_str,
                }
                if is_lightning:
       +            assert isinstance(x, LNInvoice)
                    d['invoice'] = x.invoice
                    if self.lnworker and status == PR_UNPAID:
                        d['can_pay'] = self.lnworker.can_pay_invoice(x)
                else:
       +            assert isinstance(x, OnchainInvoice)
                    d['outputs'] = [y.to_legacy_tuple() for y in x.outputs]
                    if x.bip70:
                        d['bip70'] = x.bip70
       t@@ -1763,25 +1769,28 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
                    bip70 = None,
                    requestor = None)
        
       -    def sign_payment_request(self, key, alias, alias_addr, password):
       +    def sign_payment_request(self, key, alias, alias_addr, password):  # FIXME this is broken
                req = self.receive_requests.get(key)
       +        assert isinstance(req, OnchainInvoice)
                alias_privkey = self.export_private_key(alias_addr, password)
                pr = paymentrequest.make_unsigned_request(req)
                paymentrequest.sign_request_with_alias(pr, alias, alias_privkey)
       +        req.bip70 = pr.raw.hex()
                req['name'] = pr.pki_data
                req['sig'] = bh2u(pr.signature)
                self.receive_requests[key] = req
        
       -    def add_payment_request(self, req):
       +    def add_payment_request(self, req: Invoice):
                if not req.is_lightning():
       +            assert isinstance(req, OnchainInvoice)
                    addr = req.get_address()
                    if not bitcoin.is_address(addr):
                        raise Exception(_('Invalid Bitcoin address.'))
                    if not self.is_mine(addr):
                        raise Exception(_('Address not in wallet.'))
                    key = addr
       -            message = req.message
                else:
       +            assert isinstance(req, LNInvoice)
                    key = req.rhash
                message = req.message
                self.receive_requests[key] = req