Added lnurl helper, and I hate mypy

This commit is contained in:
Arc 2024-11-18 20:49:24 +00:00
parent a8e05612da
commit 5a2ba743cf
7 changed files with 275 additions and 286 deletions

17
helpers.py Normal file
View file

@ -0,0 +1,17 @@
# Description: A place for helper functions.
from fastapi import Request
from lnurl.core import encode as lnurl_encode
# The lnurler function is used to generate the lnurlpay and lnurlwithdraw links
# from the lnurl api endpoints in views_lnurl.py.
# It needs the Request object to know the url of the LNbits.
# Lnurler is used in views_api.py
def lnurler(myex_id: str, route_name: str, req: Request) -> str:
url = req.url_for(route_name, myextension_id=myex_id)
url_str = str(url)
if url.netloc.endswith(".onion"):
url_str = url_str.replace("https://", "http://")
return str(lnurl_encode(url_str))