lnurlp import execption

withdraw not working
This commit is contained in:
Tiago vasconcelos 2021-10-11 11:46:36 +01:00
parent 9a18720a96
commit de97c0f696
6 changed files with 13 additions and 11 deletions

View file

@ -2,6 +2,7 @@ import hashlib
import math
from http import HTTPStatus
from fastapi import FastAPI, Request
from starlette.exceptions import HTTPException
from lnurl import LnurlPayResponse, LnurlPayActionResponse, LnurlErrorResponse # type: ignore
from lnbits.core.services import create_invoice

View file

@ -61,7 +61,7 @@ async def get_withdraw_link(link_id: str, num=0) -> Optional[WithdrawLink]:
# for item in row:
# link.append(item)
# link.append(num)
print("GET_LINK", WithdrawLink.from_row(row))
# print("GET_LINK", WithdrawLink.from_row(row))
return WithdrawLink.from_row(row)

View file

@ -3,7 +3,9 @@ from http import HTTPStatus
from datetime import datetime
from lnbits.core.services import pay_invoice
from fastapi.param_functions import Query
from starlette.requests import Request
from starlette.exceptions import HTTPException
from . import withdraw_ext
from .crud import get_withdraw_link_by_hash, update_withdraw_link
@ -80,19 +82,17 @@ async def api_lnurl_multi_response(request: Request, unique_hash, id_unique_hash
# HTTPStatus.OK,
# )
return link.lnurl_response(request).dict()
return link.lnurl_response(req=request).dict()
# CALLBACK
@withdraw_ext.get("/api/v1/lnurl/cb/{unique_hash}", status_code=HTTPStatus.OK, name="withdraw.api_lnurl_callback")
async def api_lnurl_callback(unique_hash):
async def api_lnurl_callback(unique_hash, k1: str = Query(...), pr: str = Query(...)):
link = await get_withdraw_link_by_hash(unique_hash)
k1 = request.query_params['k1']
payment_request = request.query_params['pr']
payment_request = pr
now = int(datetime.now().timestamp())
if not link:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND,

View file

@ -62,7 +62,7 @@ class WithdrawLink(BaseModel):
def lnurl_response(self, req: Request) -> LnurlWithdrawResponse:
url = req.url_for(
"withdraw.api_lnurl_callback", unique_hash=self.unique_hash, _external=True
name="withdraw.api_lnurl_callback", unique_hash=self.unique_hash
)
return LnurlWithdrawResponse(
callback=url,

View file

@ -7,10 +7,10 @@
{% if link.is_spent %}
<q-badge color="red" class="q-mb-md">Withdraw is spent.</q-badge>
{% endif %}
<a href="lightning://{{ link.lnurl }}">
<a href="lightning://{{ lnurl }}">
<q-responsive :ratio="1" class="q-mx-md">
<qrcode
:value="this.here + '/?lightning={{link.lnurl }}'"
:value="this.here + '/?lightning={{lnurl }}'"
:options="{width: 800}"
class="rounded-borders"
></qrcode>
@ -18,7 +18,7 @@
</a>
</div>
<div class="row q-mt-lg">
<q-btn outline color="grey" @click="copyText('{{ link.lnurl }}')"
<q-btn outline color="grey" @click="copyText('{{ lnurl }}')"
>Copy LNURL</q-btn
>
</div>

View file

@ -33,7 +33,8 @@ async def display(request: Request, link_id):
)
# response.status_code = HTTPStatus.NOT_FOUND
# return "Withdraw link does not exist." #probably here is where we should return the 404??
return withdraw_renderer().TemplateResponse("withdraw/display.html", {"request":request,"link":{**link.dict(), "lnurl": link.lnurl(request)}, "unique":True})
print("LINK", link)
return withdraw_renderer().TemplateResponse("withdraw/display.html", {"request":request,"link":link.dict(), "lnurl": link.lnurl(req=request), "unique":True})
@withdraw_ext.get("/img/{link_id}", response_class=StreamingResponse)