fix: lnurl_encoding error was not handled (#56)

This commit is contained in:
dni ⚡ 2025-07-15 15:11:17 +02:00 committed by GitHub
commit b42fee99e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 1047 additions and 750 deletions

28
helpers.py Normal file
View file

@ -0,0 +1,28 @@
from fastapi import Request
from lnurl import Lnurl
from lnurl import encode as lnurl_encode
from shortuuid import uuid
from .models import WithdrawLink
def create_lnurl(link: WithdrawLink, req: Request) -> Lnurl:
if link.is_unique:
usescssv = link.usescsv.split(",")
tohash = link.id + link.unique_hash + usescssv[link.number]
multihash = uuid(name=tohash)
url = req.url_for(
"withdraw.api_lnurl_multi_response",
unique_hash=link.unique_hash,
id_unique_hash=multihash,
)
else:
url = req.url_for("withdraw.api_lnurl_response", unique_hash=link.unique_hash)
try:
return lnurl_encode(str(url))
except Exception as e:
raise ValueError(
f"Error creating LNURL with url: `{url!s}`, "
"check your webserver proxy configuration."
) from e