Skip to content

Conversation

santyr
Copy link
Contributor

@santyr santyr commented Aug 14, 2025

Tested with LNBits v1.3.0-rc2

This refactor overhauls the get_lnurl_invoice function to make it more robust, reliable, and independent of the web API layer, ensuring that errors are logged correctly and payments are processed as expected.

Changes Made

Fixed ImportError for api_lnurlscan:

    The initial code attempted to import api_lnurlscan from lnbits.core.views.api, which was incorrect for the user's version of LNbits, causing an ImportError.

    This was corrected to import from lnbits.core.views.lnurl_api.

Fixed TypeError on Response Object:

    After fixing the import, the code produced a TypeError: 'LnurlPayResponse' object is not subscriptable.

    The api_lnurlscan function returns a Pydantic model, not a dictionary. The code was updated to use attribute access (data.callback) instead of dictionary key access (data["callback"]).

Replaced API call with Direct lnurl.handle to Fix Silent Failures:

    The final and most critical issue was that calling the api_lnurlscan endpoint suppressed underlying errors from the lnurl library, causing the payment process to fail silently without any logs.

    The implementation was changed to bypass the API endpoint entirely and use the lnurl.handle function directly. This provides more direct control and ensures that any exceptions are caught and logged within the extension's context, preventing silent failures.

santyr added 5 commits August 13, 2025 10:51
api_lnurlscan function is being imported from nbits.core.views.api, but it is located in lnbits.core.views.lnurl_api. 

This  corrects the import path, resolving the error.
`api_lnurlscan` function returns a `LnurlPayResponse` object, not a dictionary. The code was attempting to access its properties using dictionary subscription (`data['callback']`), which caused a `TypeError`.

Updated the code to use attribute access (`data.callback`) to correctly handle the response object and resolve the runtime error.
The extension was silently failing when processing LNURL payments because it was calling the `api_lnurlscan` web endpoint. Errors from the `lnurl` library were being caught and returned as `None`, halting the process without a specific error log.

This commit changes the implementation to use the `lnurl.handle` function directly, bypassing the API layer. This provides more direct error handling, logs specific LNURL failures, and prevents the task from failing silently.
Remove extra memo and payment hash from memo generation.
…dling

Valid Lightning Addresses containing uppercase characters (e.g., `[email protected]`) were being incorrectly rejected with an "Invalid Lightning address" error.

This was caused by the underlying `lnurl-python` library performing a strict, case-sensitive validation, which violates the case-insensitive LUD-16 specification.

This commit fixes the issue by converting the address to lowercase before it is passed to the `lnurl_handle` function. This ensures compliance with the spec and allows all valid Lightning Addresses to be processed correctly, regardless of case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant