From 76fcd30ac005ba28f054e3959d252fad0de1b9f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Dvo=C5=99=C3=A1k?= <80678558+gorrdy@users.noreply.github.com> Date: Thu, 21 Sep 2023 08:37:58 +0200 Subject: [PATCH] add support for LUD-19 for boltcards extension (#19) * fix broken link for tag, boltcard -> boltcards (name of the extension) * add support for LUD-19 in bolt cards extension * Apply suggestions from code review Co-authored-by: Pavol Rusnak * Apply suggestions from code review Co-authored-by: Pavol Rusnak --------- Co-authored-by: Jan Dvorak Co-authored-by: Pavol Rusnak --- lnurl.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lnurl.py b/lnurl.py index e3ac7f1..4b39374 100644 --- a/lnurl.py +++ b/lnurl.py @@ -75,14 +75,22 @@ async def api_scan(p, c, request: Request, external_id: str): if hits_amount > card.daily_limit: return {"status": "ERROR", "reason": "Max daily limit spent."} hit = await create_hit(card.id, ip, agent, card.counter, ctr_int) - lnurlpay = lnurl_encode(str(request.url_for("boltcards.lnurlp_response", hit_id=hit.id))) + + # the raw lnurl + lnurlpay_raw = str(request.url_for("boltcards.lnurlp_response", hit_id=hit.id)) + # bech32 encoded lnurl + lnurlpay_bech32 = lnurl_encode(lnurlpay_raw) + # create a lud17 lnurlp to support lud19, add to payLink field of the withdrawRequest + lnurlpay_nonbech32_lud17 = lnurlpay_raw.replace("https://", "lnurlp://").replace("http://","lnurlp://") + return { "tag": "withdrawRequest", "callback": str(request.url_for("boltcards.lnurl_callback", hit_id=hit.id)), "k1": hit.id, "minWithdrawable": 1 * 1000, "maxWithdrawable": card.tx_limit * 1000, - "defaultDescription": f"Boltcard (refund address lnurl://{lnurlpay})", + "defaultDescription": f"Boltcard (refund address lnurl://{lnurlpay_bech32})", + "payLink": lnurlpay_nonbech32_lud17, # LUD-19 compatibility }