Skip to content

Commit

Permalink
check .onion and change scheme to http (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
talvasconcelos authored Sep 24, 2023
1 parent d8b6ac4 commit b2fcdff
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lnurl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from datetime import datetime
from http import HTTPStatus
from urllib.parse import urlparse

import httpx
import shortuuid
Expand Down Expand Up @@ -38,6 +39,12 @@ async def api_lnurl_response(request: Request, unique_hash: str):
status_code=HTTPStatus.NOT_FOUND, detail="Withdraw is spent."
)
url = request.url_for("withdraw.api_lnurl_callback", unique_hash=link.unique_hash)

# Check if url is .onion and change to http
if urlparse(url).netloc.endswith(".onion"):
# change url string scheme to http
url = url.replace("https://", "http://")

return {
"tag": "withdrawRequest",
"callback": url,
Expand Down Expand Up @@ -189,6 +196,12 @@ async def api_lnurl_multi_response(request: Request, unique_hash: str, id_unique
)

url = request.url_for("withdraw.api_lnurl_callback", unique_hash=link.unique_hash)

# Check if url is .onion and change to http
if urlparse(url).netloc.endswith(".onion"):
# change url string scheme to http
url = url.replace("https://", "http://")

return {
"tag": "withdrawRequest",
"callback": f"{url}?id_unique_hash={id_unique_hash}",
Expand Down

0 comments on commit b2fcdff

Please sign in to comment.