plugin: nwc: lookup_invoice: fix exc, include b11

Fixes exception in lookup_invoice:
```
 62.69 | E | plugins.nwc.nwcserver.NWCServer | Error handling nwc request
Traceback (most recent call last):
  File "/home/user/code/vibecoding_vm/electrum/electrum/plugins/nwc/nwcserver.py", line 381, in run_request_task
    await task
  File "/home/user/code/vibecoding_vm/electrum/electrum/util.py", line 1211, in wrapper
    return await func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/code/vibecoding_vm/electrum/electrum/plugins/nwc/nwcserver.py", line 526, in handle_lookup_invoice
    info = self.wallet.lnworker.get_payment_info(invoice.payment_hash, direction=RECEIVED)
                                                 ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Invoice' object has no attribute 'payment_hash'
```

Always includes bolt11 invoice in response, even if the client already
sent it to us in the request. It doesn't seem useful and is marked
optional in the spec but https://sandbox.albylabs.com considers the
response invalid if the invoice is not included.
This commit is contained in:
f321x
2026-03-06 14:42:42 +01:00
parent f53203d171
commit f64923b472
+2 -3
View File
@@ -523,7 +523,7 @@ class NWCServer(Logger, EventListener):
b11 = invoice.lightning_invoice
elif self.wallet.get_request(invoice.rhash):
direction = "incoming"
info = self.wallet.lnworker.get_payment_info(invoice.payment_hash, direction=RECEIVED)
info = self.wallet.lnworker.get_payment_info(bytes.fromhex(invoice.rhash), direction=RECEIVED)
_, b11 = self.wallet.lnworker.get_bolt11_invoice(
payment_info=info,
message=invoice.message,
@@ -539,11 +539,10 @@ class NWCServer(Logger, EventListener):
"created_at": invoice.time,
"expires_at": invoice.get_expiration_date(),
"fees_paid": 0,
"invoice": b11,
"metadata": {}
}
}
if payment_hash: # if client requested by payment hash we add the invoice
response['result']['invoice'] = b11
if nip47_status := self.invoice_status_to_nip47_state(status):
response['result']['state'] = nip47_status