From aed2414f3a69cd72b5bc1b8a16f3eee97e9b4dee Mon Sep 17 00:00:00 2001 From: Eneko Illarramendi Date: Mon, 18 May 2020 06:33:02 +0200 Subject: [PATCH] fix: show better errors when a LNURL-withdraw wallet cannot be created, closes #39 --- README.md | 2 +- lnbits/core/views/lnurl.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 42a97f9d..f642d1be 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ LNURL has a fallback scheme, so if scanned by a regular QR code reader it can de ![lnurl fallback](https://i.imgur.com/CPBKHIv.png) https://github.com/btcontract/lnurl-rfc/blob/master/spec.md -Adding **/lnurlwallet?lightning="LNURL-withdraw"** will trigger a withdraw that builds an LNbits wallet. +Using **lnbits.com/?lightning="LNURL-withdraw"** will trigger a withdraw that builds an LNbits wallet. Example use would be an ATM, which utilises LNURL, if the user scans the QR with a regular QR code scanner app, they will stilll be able to access the funds. ![lnurl ATM](https://i.imgur.com/Gi6bn3L.jpg) diff --git a/lnbits/core/views/lnurl.py b/lnbits/core/views/lnurl.py index 172b11c2..21b30572 100644 --- a/lnbits/core/views/lnurl.py +++ b/lnbits/core/views/lnurl.py @@ -17,9 +17,13 @@ def lnurlwallet(): memo = "LNbits LNURL funding" try: - withdraw_res = handle_lnurl(request.args.get("lightning"), response_class=LnurlWithdrawResponse) + withdraw_res = handle_lnurl(request.args.get("lightning")) + if not withdraw_res.ok: + abort(HTTPStatus.BAD_REQUEST, f"Could not process LNURL-withdraw: {withdraw_res.error_msg}") + if not isinstance(withdraw_res, LnurlWithdrawResponse): + abort(HTTPStatus.BAD_REQUEST, "Not a valid LNURL-withdraw.") except LnurlException: - abort(HTTPStatus.INTERNAL_SERVER_ERROR, "Could not process withdraw LNURL.") + abort(HTTPStatus.INTERNAL_SERVER_ERROR, "Could not process LNURL-withdraw.") try: ok, checking_id, payment_request, error_message = WALLET.create_invoice(withdraw_res.max_sats, memo) @@ -35,7 +39,7 @@ def lnurlwallet(): ) if not r.ok: - abort(HTTPStatus.INTERNAL_SERVER_ERROR, "Could not process withdraw LNURL.") + abort(HTTPStatus.INTERNAL_SERVER_ERROR, "Could not process LNURL-withdraw.") for i in range(10): invoice_status = WALLET.get_invoice_status(checking_id)