spesmilo / electrum

Electrum Bitcoin Wallet
https://electrum.org
MIT License
7.44k stars 3.09k forks source link

non-lightning request in request list raises exception when exporting to Dict using wallet.export_request() #8151

Closed accumulator closed 1 year ago

accumulator commented 1 year ago

Some logging added locally. It looks like self.lnworker.get_invoice_status(x) assumes x is a lightning invoice, and crashes if no LN invoice is found in the request.

Not sure what the best solutions is here. Make lnworker.get_invoice_status more robust and return a PR_UNKNOWN, or add an extra if not is_lightning guard around the lnworker.get_invoice_status call?

  2.88 | I | wallet | export req: Invoice(amount_msat=500000000, message='Test', time=1654193513, exp=2678400, outputs=[<TxOutput script=0014a3dd51f5789e41da59d7b2ce73912d1ae4bfe389 address=tb1q50w4ratcneqa5kwhkt888yfdrtjtlcufafh4f0 value=500000>], height=2253656, bip70=None, lightning_invoice=None)
  2.88 | I | wallet | export req d: {'is_lightning': False, 'amount_BTC': '0.005', 'message': 'Test', 'timestamp': 1654193513, 'expiration': 1656871913, 'status': 1, 'status_str': 'Expired', 'request_id': '0c31748e45', 'tx_hashes': [], 'amount_sat': 500000, 'address': 'tb1q50w4ratcneqa5kwhkt888yfdrtjtlcufafh4f0', 'URI': 'bitcoin:tb1q50w4ratcneqa5kwhkt888yfdrtjtlcufafh4f0?amount=0.005&message=Test&time=1654193513&exp=2678400'}
  2.88 | E | gui.qml.qeapp.Exception_Hook | exception caught by crash reporter
Traceback (most recent call last):
  File "/home/sander/projects/electrum/electrum/electrum/gui/qml/qewallet.py", line 290, in requestModel
    self._requestModel = QERequestListModel(self.wallet)
  File "/home/sander/projects/electrum/electrum/electrum/gui/qml/qeinvoicelistmodel.py", line 185, in __init__
    super().__init__(wallet, parent)
  File "/home/sander/projects/electrum/electrum/electrum/gui/qml/qeinvoicelistmodel.py", line 29, in __init__
    self.init_model()
  File "/home/sander/projects/electrum/electrum/electrum/gui/qml/qeinvoicelistmodel.py", line 60, in init_model
    item = self.invoice_to_model(invoice)
  File "/home/sander/projects/electrum/electrum/electrum/gui/qml/qeinvoicelistmodel.py", line 200, in invoice_to_model
    item = super().invoice_to_model(invoice)
  File "/home/sander/projects/electrum/electrum/electrum/gui/qml/qeinvoicelistmodel.py", line 115, in invoice_to_model
    item = self.get_invoice_as_dict(invoice)
  File "/home/sander/projects/electrum/electrum/electrum/gui/qml/qeinvoicelistmodel.py", line 213, in get_invoice_as_dict
    return self.wallet.export_request(invoice)
  File "/home/sander/projects/electrum/electrum/electrum/wallet.py", line 2406, in export_request
    if  not self.lnworker or self.lnworker.get_invoice_status(x) != PR_PAID:
  File "/home/sander/projects/electrum/electrum/electrum/lnworker.py", line 1900, in get_invoice_status
    invoice_id = invoice.rhash
  File "/home/sander/projects/electrum/electrum/electrum/invoices.py", line 225, in rhash
    return self._lnaddr.paymenthash.hex()
  File "/home/sander/projects/electrum/electrum/electrum/invoices.py", line 220, in _lnaddr
    self.__lnaddr = lndecode(self.lightning_invoice)
  File "/home/sander/projects/electrum/electrum/electrum/lnaddr.py", line 365, in lndecode
    decoded_bech32 = bech32_decode(invoice, ignore_long_length=True)
  File "/home/sander/projects/electrum/electrum/electrum/segwit_addr.py", line 90, in bech32_decode
    bech_lower = bech.lower()
AttributeError: 'NoneType' object has no attribute 'lower'
accumulator commented 1 year ago

Added explicit is_lightning check in aac0e4f693b25eaa269e11d3e3351f6b636d23f6 for now, but making lnworker.get_invoice_status() more robust is probably the better solution. Thoughts?

ecdsa commented 1 year ago

I guess it is fine for now. thanks