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 <pavol@rusnak.io>

* Apply suggestions from code review

Co-authored-by: Pavol Rusnak <pavol@rusnak.io>

---------

Co-authored-by: Jan Dvorak <jan.dvorak@xorux.com>
Co-authored-by: Pavol Rusnak <pavol@rusnak.io>
This commit is contained in:
Jan Dvořák 2023-09-21 08:37:58 +02:00 committed by GitHub
commit 76fcd30ac0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -75,14 +75,22 @@ async def api_scan(p, c, request: Request, external_id: str):
if hits_amount > card.daily_limit: if hits_amount > card.daily_limit:
return {"status": "ERROR", "reason": "Max daily limit spent."} return {"status": "ERROR", "reason": "Max daily limit spent."}
hit = await create_hit(card.id, ip, agent, card.counter, ctr_int) 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 { return {
"tag": "withdrawRequest", "tag": "withdrawRequest",
"callback": str(request.url_for("boltcards.lnurl_callback", hit_id=hit.id)), "callback": str(request.url_for("boltcards.lnurl_callback", hit_id=hit.id)),
"k1": hit.id, "k1": hit.id,
"minWithdrawable": 1 * 1000, "minWithdrawable": 1 * 1000,
"maxWithdrawable": card.tx_limit * 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
} }