mirror of
https://github.com/lnbits/lnbits.git
synced 2025-06-30 02:21:00 +02:00
fix withdraw routes order
This commit is contained in:
@ -1,8 +1,8 @@
|
|||||||
|
import json
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
|
|
||||||
import shortuuid # type: ignore
|
import shortuuid # type: ignore
|
||||||
import json
|
|
||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
from fastapi.param_functions import Query
|
from fastapi.param_functions import Query
|
||||||
from starlette.requests import Request
|
from starlette.requests import Request
|
||||||
@ -22,6 +22,7 @@ from .crud import get_withdraw_link_by_hash, update_withdraw_link
|
|||||||
name="withdraw.api_lnurl_response",
|
name="withdraw.api_lnurl_response",
|
||||||
)
|
)
|
||||||
async def api_lnurl_response(request: Request, unique_hash):
|
async def api_lnurl_response(request: Request, unique_hash):
|
||||||
|
print("NOT UNIQUE")
|
||||||
link = await get_withdraw_link_by_hash(unique_hash)
|
link = await get_withdraw_link_by_hash(unique_hash)
|
||||||
|
|
||||||
if not link:
|
if not link:
|
||||||
@ -49,68 +50,26 @@ async def api_lnurl_response(request: Request, unique_hash):
|
|||||||
return json.dumps(withdrawResponse)
|
return json.dumps(withdrawResponse)
|
||||||
|
|
||||||
|
|
||||||
# FOR LNURLs WHICH ARE UNIQUE
|
|
||||||
|
|
||||||
|
|
||||||
@withdraw_ext.get(
|
|
||||||
"/api/v1/lnurl/{unique_hash}/{id_unique_hash}",
|
|
||||||
response_class=HTMLResponse,
|
|
||||||
name="withdraw.api_lnurl_multi_response",
|
|
||||||
)
|
|
||||||
async def api_lnurl_multi_response(request: Request, unique_hash, id_unique_hash):
|
|
||||||
link = await get_withdraw_link_by_hash(unique_hash)
|
|
||||||
|
|
||||||
if not link:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=HTTPStatus.OK, detail="LNURL-withdraw not found."
|
|
||||||
)
|
|
||||||
|
|
||||||
if link.is_spent:
|
|
||||||
raise HTTPException(status_code=HTTPStatus.OK, detail="Withdraw is spent.")
|
|
||||||
|
|
||||||
useslist = link.usescsv.split(",")
|
|
||||||
found = False
|
|
||||||
for x in useslist:
|
|
||||||
tohash = link.id + link.unique_hash + str(x)
|
|
||||||
if id_unique_hash == shortuuid.uuid(name=tohash):
|
|
||||||
found = True
|
|
||||||
if not found:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=HTTPStatus.OK, detail="LNURL-withdraw not found."
|
|
||||||
)
|
|
||||||
|
|
||||||
url = request.url_for("withdraw.api_lnurl_callback", unique_hash=link.unique_hash)
|
|
||||||
withdrawResponse = {
|
|
||||||
"tag": "withdrawRequest",
|
|
||||||
"callback": url,
|
|
||||||
"k1": link.k1,
|
|
||||||
"minWithdrawable": link.min_withdrawable * 1000,
|
|
||||||
"maxWithdrawable": link.max_withdrawable * 1000,
|
|
||||||
"defaultDescription": link.title,
|
|
||||||
}
|
|
||||||
return json.dumps(withdrawResponse)
|
|
||||||
|
|
||||||
|
|
||||||
# CALLBACK
|
# CALLBACK
|
||||||
|
|
||||||
|
#https://5650-2001-8a0-fa12-2900-4c13-748a-fbb9-a47f.ngrok.io/withdraw/api/v1/lnurl/cb/eJHybS8hqcBWajZM63H3FP?k1=MUaYBGrUPuAs8SLpfizmCk&pr=lnbc100n1pse2tsypp5ju0yn3w9j0n8rr3squg0knddawu2ude2cgrm6zje5f34e9jzpmlsdq8w3jhxaqxqyjw5qcqpjsp5tyhu78pamqg5zfy96kup329zt40ramc8gs2ev6jxgp66zca2348qrzjqwac3nxyg3f5mfa4ke9577c4u8kvkx8pqtdsusqdfww0aymk823x6znwa5qqzyqqqyqqqqlgqqqqppgq9q9qy9qsq66zp6pctnlmk59xwtqjga5lvqrkyccmafmn43enhhc6ugew80sanxymepshpv44m9yyhfgh8r2upvxhgk00d36rpqzfy3fxemeu4jhqp96l8hx
|
||||||
|
|
||||||
|
|
||||||
@withdraw_ext.get(
|
@withdraw_ext.get(
|
||||||
"/api/v1/lnurl/cb/{unique_hash}",
|
"/api/v1/lnurl/cb/{unique_hash}",
|
||||||
status_code=HTTPStatus.OK,
|
|
||||||
name="withdraw.api_lnurl_callback",
|
name="withdraw.api_lnurl_callback",
|
||||||
)
|
)
|
||||||
async def api_lnurl_callback(
|
async def api_lnurl_callback(
|
||||||
|
unique_hash,
|
||||||
request: Request,
|
request: Request,
|
||||||
unique_hash: str = Query(...),
|
|
||||||
k1: str = Query(...),
|
k1: str = Query(...),
|
||||||
payment_request: str = Query(..., alias="pr"),
|
pr: str = Query(...)
|
||||||
):
|
):
|
||||||
link = await get_withdraw_link_by_hash(unique_hash)
|
link = await get_withdraw_link_by_hash(unique_hash)
|
||||||
now = int(datetime.now().timestamp())
|
now = int(datetime.now().timestamp())
|
||||||
|
|
||||||
if not link:
|
if not link:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.NOT_FOUND, detail="LNURL-withdraw not found."
|
status_code=HTTPStatus.NOT_FOUND, detail="LNURL-withdraw not found"
|
||||||
)
|
)
|
||||||
|
|
||||||
if link.is_spent:
|
if link.is_spent:
|
||||||
@ -143,6 +102,8 @@ async def api_lnurl_callback(
|
|||||||
}
|
}
|
||||||
await update_withdraw_link(link.id, **changes)
|
await update_withdraw_link(link.id, **changes)
|
||||||
|
|
||||||
|
payment_request=pr
|
||||||
|
|
||||||
await pay_invoice(
|
await pay_invoice(
|
||||||
wallet_id=link.wallet,
|
wallet_id=link.wallet,
|
||||||
payment_request=payment_request,
|
payment_request=payment_request,
|
||||||
@ -154,3 +115,46 @@ async def api_lnurl_callback(
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
await update_withdraw_link(link.id, **changesback)
|
await update_withdraw_link(link.id, **changesback)
|
||||||
return {"status": "ERROR", "reason": "Link not working"}
|
return {"status": "ERROR", "reason": "Link not working"}
|
||||||
|
|
||||||
|
|
||||||
|
# FOR LNURLs WHICH ARE UNIQUE
|
||||||
|
|
||||||
|
|
||||||
|
@withdraw_ext.get(
|
||||||
|
"/api/v1/lnurl/{unique_hash}/{id_unique_hash}",
|
||||||
|
response_class=HTMLResponse,
|
||||||
|
name="withdraw.api_lnurl_multi_response",
|
||||||
|
)
|
||||||
|
async def api_lnurl_multi_response(request: Request, unique_hash, id_unique_hash):
|
||||||
|
print("UNIQUE")
|
||||||
|
link = await get_withdraw_link_by_hash(unique_hash)
|
||||||
|
|
||||||
|
if not link:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.OK, detail="LNURL-withdraw not found."
|
||||||
|
)
|
||||||
|
|
||||||
|
if link.is_spent:
|
||||||
|
raise HTTPException(status_code=HTTPStatus.OK, detail="Withdraw is spent.")
|
||||||
|
|
||||||
|
useslist = link.usescsv.split(",")
|
||||||
|
found = False
|
||||||
|
for x in useslist:
|
||||||
|
tohash = link.id + link.unique_hash + str(x)
|
||||||
|
if id_unique_hash == shortuuid.uuid(name=tohash):
|
||||||
|
found = True
|
||||||
|
if not found:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.OK, detail="LNURL-withdraw not found."
|
||||||
|
)
|
||||||
|
|
||||||
|
url = request.url_for("withdraw.api_lnurl_callback", unique_hash=link.unique_hash)
|
||||||
|
withdrawResponse = {
|
||||||
|
"tag": "withdrawRequest",
|
||||||
|
"callback": url,
|
||||||
|
"k1": link.k1,
|
||||||
|
"minWithdrawable": link.min_withdrawable * 1000,
|
||||||
|
"maxWithdrawable": link.max_withdrawable * 1000,
|
||||||
|
"defaultDescription": link.title,
|
||||||
|
}
|
||||||
|
return json.dumps(withdrawResponse)
|
||||||
|
@ -91,7 +91,7 @@ async def print_qr(request: Request, link_id):
|
|||||||
|
|
||||||
return withdraw_renderer().TemplateResponse(
|
return withdraw_renderer().TemplateResponse(
|
||||||
"withdraw/print_qr.html",
|
"withdraw/print_qr.html",
|
||||||
{"request": request, "link": link.dict(), unique: False},
|
{"request": request, "link": link.dict(), "unique": False},
|
||||||
)
|
)
|
||||||
links = []
|
links = []
|
||||||
count = 0
|
count = 0
|
||||||
|
Reference in New Issue
Block a user