Browse Source

wallet.get_bolt11_invoice: handle request not having LN part

fixes https://github.com/spesmilo/electrum/issues/8402

To reproduce,
- create wallet from a zpub
- LN is disabled there by default
- create a receive request, which won't have a lightning part
- enable config var "bip21_lightning"
- enable LN
- existing request is now ~breaking receive tab
master
SomberNight 3 years ago
parent
commit
38ec72527f
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 2
      electrum/lnworker.py
  2. 4
      electrum/wallet.py

2
electrum/lnworker.py

@ -1801,6 +1801,7 @@ class LNWallet(LNWorker):
fallback_address: Optional[str],
channels: Optional[Sequence[Channel]] = None,
) -> Tuple[LnAddr, str]:
assert isinstance(payment_hash, bytes), f"expected bytes, but got {type(payment_hash)}"
pair = self._bolt11_cache.get(payment_hash)
if pair:
@ -1856,6 +1857,7 @@ class LNWallet(LNWorker):
self.wallet.save_db()
def get_preimage(self, payment_hash: bytes) -> Optional[bytes]:
assert isinstance(payment_hash, bytes), f"expected bytes, but got {type(payment_hash)}"
r = self.preimages.get(payment_hash.hex())
return bytes.fromhex(r) if r else None

4
electrum/wallet.py

@ -2605,10 +2605,12 @@ class Abstract_Wallet(ABC, Logger, EventListener):
def get_bolt11_invoice(self, req: Request) -> str:
if not self.lnworker:
return ''
if (payment_hash := req.payment_hash) is None: # e.g. req might have been generated before enabling LN
return ''
amount_msat = req.get_amount_msat() or None
assert (amount_msat is None or amount_msat > 0), amount_msat
lnaddr, invoice = self.lnworker.get_bolt11_invoice(
payment_hash=req.payment_hash,
payment_hash=payment_hash,
amount_msat=amount_msat,
message=req.message,
expiry=req.exp,

Loading…
Cancel
Save