URI: 
       tfix #6056 - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 312ef15cd612a8235cf7be29dcf6f3b8a11b0ab7
   DIR parent 7a11c0591667fd15995e36c77af1fd344a61c061
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Sat, 11 Apr 2020 12:02:38 +0200
       
       fix #6056
       
       Diffstat:
         M electrum/commands.py                |       5 +++++
         M electrum/gui/kivy/uix/screens.py    |       4 ++--
         M electrum/gui/qt/main_window.py      |       3 ++-
         M electrum/lnaddr.py                  |      28 +++++++++++++++++++++++-----
         M electrum/lnworker.py                |      14 --------------
       
       5 files changed, 32 insertions(+), 22 deletions(-)
       ---
   DIR diff --git a/electrum/commands.py b/electrum/commands.py
       t@@ -58,6 +58,7 @@ from .lnpeer import channel_id_from_funding_tx
        from .plugin import run_hook
        from .version import ELECTRUM_VERSION
        from .simple_config import SimpleConfig
       +from .lnaddr import parse_lightning_invoice
        
        
        if TYPE_CHECKING:
       t@@ -981,6 +982,10 @@ class Commands:
                                                                                 password=password)
                return chan.funding_outpoint.to_str()
        
       +    @command('')
       +    async def decode_invoice(self, invoice):
       +        return parse_lightning_invoice(invoice)
       +
            @command('wn')
            async def lnpay(self, invoice, attempts=1, timeout=10, wallet: Abstract_Wallet = None):
                lnworker = wallet.lnworker
   DIR diff --git a/electrum/gui/kivy/uix/screens.py b/electrum/gui/kivy/uix/screens.py
       t@@ -33,7 +33,7 @@ from electrum.util import (parse_URI, InvalidBitcoinURI, PR_PAID, PR_UNKNOWN, PR
        from electrum.plugin import run_hook
        from electrum.wallet import InternalAddressCorruption
        from electrum import simple_config
       -from electrum.lnaddr import lndecode
       +from electrum.lnaddr import lndecode, parse_lightning_invoice
        from electrum.lnutil import RECEIVED, SENT, PaymentFailure
        
        from .dialogs.question import Question
       t@@ -299,7 +299,7 @@ class SendScreen(CScreen):
                    return
                message = self.message
                if self.is_lightning:
       -            return self.app.wallet.lnworker.parse_bech32_invoice(address)
       +            return parse_lightning_invoice(address)
                else:  # on-chain
                    if self.payment_request:
                        outputs = self.payment_request.get_outputs()
   DIR diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py
       t@@ -76,6 +76,7 @@ from electrum.logging import Logger
        from electrum.util import PR_PAID, PR_FAILED
        from electrum.util import pr_expiration_values
        from electrum.lnutil import ln_dummy_address
       +from electrum.lnaddr import parse_lightning_invoice
        
        from .exception_window import Exception_Hook
        from .amountedit import AmountEdit, BTCAmountEdit, FreezableLineEdit, FeerateEdit
       t@@ -1492,7 +1493,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
                    if not self.wallet.lnworker:
                        self.show_error(_('Lightning is disabled'))
                        return
       -            invoice_dict = self.wallet.lnworker.parse_bech32_invoice(invoice)
       +            invoice_dict = parse_lightning_invoice(invoice)
                    if invoice_dict.get('amount') is None:
                        amount = self.amount_e.get_amount()
                        if amount:
   DIR diff --git a/electrum/lnaddr.py b/electrum/lnaddr.py
       t@@ -13,6 +13,8 @@ from .bitcoin import hash160_to_b58_address, b58_address_to_hash160
        from .segwit_addr import bech32_encode, bech32_decode, CHARSET
        from . import constants
        from . import ecc
       +from .util import PR_TYPE_LN
       +from .bitcoin import COIN
        
        
        # BOLT #11:
       t@@ -307,6 +309,11 @@ class LnAddr(object):
        
        class LnDecodeException(Exception): pass
        
       +class SerializableKey:
       +    def __init__(self, pubkey):
       +        self.pubkey = pubkey
       +    def serialize(self):
       +        return self.pubkey.get_public_key_bytes(True)
        
        def lndecode(invoice: str, *, verbose=False, expected_hrp=None) -> LnAddr:
            if expected_hrp is None:
       t@@ -460,11 +467,22 @@ def lndecode(invoice: str, *, verbose=False, expected_hrp=None) -> LnAddr:
        
            return addr
        
       -class SerializableKey:
       -    def __init__(self, pubkey):
       -        self.pubkey = pubkey
       -    def serialize(self):
       -        return self.pubkey.get_public_key_bytes(True)
       +
       +
       +
       +def parse_lightning_invoice(invoice):
       +    lnaddr = lndecode(invoice, expected_hrp=constants.net.SEGWIT_HRP)
       +    amount = int(lnaddr.amount * COIN) if lnaddr.amount else None
       +    return {
       +        'type': PR_TYPE_LN,
       +        'invoice': invoice,
       +        'amount': amount,
       +        'message': lnaddr.get_description(),
       +        'time': lnaddr.date,
       +        'exp': lnaddr.get_expiry(),
       +        'pubkey': lnaddr.pubkey.serialize().hex(),
       +        'rhash': lnaddr.paymenthash.hex(),
       +    }
        
        if __name__ == '__main__':
            # run using
   DIR diff --git a/electrum/lnworker.py b/electrum/lnworker.py
       t@@ -529,20 +529,6 @@ class LNWallet(LNWorker):
                        out[k].append(v)
                return out
        
       -    def parse_bech32_invoice(self, invoice):
       -        lnaddr = lndecode(invoice, expected_hrp=constants.net.SEGWIT_HRP)
       -        amount = int(lnaddr.amount * COIN) if lnaddr.amount else None
       -        return {
       -            'type': PR_TYPE_LN,
       -            'invoice': invoice,
       -            'amount': amount,
       -            'message': lnaddr.get_description(),
       -            'time': lnaddr.date,
       -            'exp': lnaddr.get_expiry(),
       -            'pubkey': bh2u(lnaddr.pubkey.serialize()),
       -            'rhash': lnaddr.paymenthash.hex(),
       -        }
       -
            def get_lightning_history(self):
                out = {}
                for key, plist in self.get_settled_payments().items():