lnurlp import execption
withdraw not working
This commit is contained in:
parent
9a18720a96
commit
de97c0f696
6 changed files with 13 additions and 11 deletions
|
|
@ -2,6 +2,7 @@ import hashlib
|
||||||
import math
|
import math
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from fastapi import FastAPI, Request
|
from fastapi import FastAPI, Request
|
||||||
|
from starlette.exceptions import HTTPException
|
||||||
from lnurl import LnurlPayResponse, LnurlPayActionResponse, LnurlErrorResponse # type: ignore
|
from lnurl import LnurlPayResponse, LnurlPayActionResponse, LnurlErrorResponse # type: ignore
|
||||||
|
|
||||||
from lnbits.core.services import create_invoice
|
from lnbits.core.services import create_invoice
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ async def get_withdraw_link(link_id: str, num=0) -> Optional[WithdrawLink]:
|
||||||
# for item in row:
|
# for item in row:
|
||||||
# link.append(item)
|
# link.append(item)
|
||||||
# link.append(num)
|
# link.append(num)
|
||||||
print("GET_LINK", WithdrawLink.from_row(row))
|
# print("GET_LINK", WithdrawLink.from_row(row))
|
||||||
return WithdrawLink.from_row(row)
|
return WithdrawLink.from_row(row)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,9 @@ from http import HTTPStatus
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from lnbits.core.services import pay_invoice
|
from lnbits.core.services import pay_invoice
|
||||||
|
from fastapi.param_functions import Query
|
||||||
from starlette.requests import Request
|
from starlette.requests import Request
|
||||||
|
from starlette.exceptions import HTTPException
|
||||||
|
|
||||||
from . import withdraw_ext
|
from . import withdraw_ext
|
||||||
from .crud import get_withdraw_link_by_hash, update_withdraw_link
|
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,
|
# HTTPStatus.OK,
|
||||||
# )
|
# )
|
||||||
|
|
||||||
return link.lnurl_response(request).dict()
|
return link.lnurl_response(req=request).dict()
|
||||||
|
|
||||||
|
|
||||||
# CALLBACK
|
# CALLBACK
|
||||||
|
|
||||||
|
|
||||||
@withdraw_ext.get("/api/v1/lnurl/cb/{unique_hash}", status_code=HTTPStatus.OK, name="withdraw.api_lnurl_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)
|
link = await get_withdraw_link_by_hash(unique_hash)
|
||||||
k1 = request.query_params['k1']
|
payment_request = pr
|
||||||
payment_request = request.query_params['pr']
|
|
||||||
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,
|
status_code=HTTPStatus.NOT_FOUND,
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ class WithdrawLink(BaseModel):
|
||||||
|
|
||||||
def lnurl_response(self, req: Request) -> LnurlWithdrawResponse:
|
def lnurl_response(self, req: Request) -> LnurlWithdrawResponse:
|
||||||
url = req.url_for(
|
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(
|
return LnurlWithdrawResponse(
|
||||||
callback=url,
|
callback=url,
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,10 @@
|
||||||
{% if link.is_spent %}
|
{% if link.is_spent %}
|
||||||
<q-badge color="red" class="q-mb-md">Withdraw is spent.</q-badge>
|
<q-badge color="red" class="q-mb-md">Withdraw is spent.</q-badge>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a href="lightning://{{ link.lnurl }}">
|
<a href="lightning://{{ lnurl }}">
|
||||||
<q-responsive :ratio="1" class="q-mx-md">
|
<q-responsive :ratio="1" class="q-mx-md">
|
||||||
<qrcode
|
<qrcode
|
||||||
:value="this.here + '/?lightning={{link.lnurl }}'"
|
:value="this.here + '/?lightning={{lnurl }}'"
|
||||||
:options="{width: 800}"
|
:options="{width: 800}"
|
||||||
class="rounded-borders"
|
class="rounded-borders"
|
||||||
></qrcode>
|
></qrcode>
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="row q-mt-lg">
|
<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
|
>Copy LNURL</q-btn
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,8 @@ async def display(request: Request, link_id):
|
||||||
)
|
)
|
||||||
# response.status_code = HTTPStatus.NOT_FOUND
|
# response.status_code = HTTPStatus.NOT_FOUND
|
||||||
# return "Withdraw link does not exist." #probably here is where we should return the 404??
|
# 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)
|
@withdraw_ext.get("/img/{link_id}", response_class=StreamingResponse)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue