Added lnurl helper, and I hate mypy
This commit is contained in:
parent
a8e05612da
commit
5a2ba743cf
7 changed files with 275 additions and 286 deletions
17
helpers.py
Normal file
17
helpers.py
Normal 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))
|
||||
Loading…
Add table
Add a link
Reference in a new issue