diff --git a/crud.py b/crud.py index 08d8ede..0df5358 100644 --- a/crud.py +++ b/crud.py @@ -40,43 +40,45 @@ async def create_withdraw_link( async def get_withdraw_link(link_id: str, num=0) -> Optional[WithdrawLink]: - row = await db.fetchone( + link: WithdrawLink = await db.fetchone( "SELECT * FROM withdraw.withdraw_link WHERE id = :id", {"id": link_id}, + WithdrawLink, ) - if not row: + if not link: return None - link = dict(**row) - link["number"] = num - - return WithdrawLink.parse_obj(link) + link.number = num + return link async def get_withdraw_link_by_hash(unique_hash: str, num=0) -> Optional[WithdrawLink]: - row = await db.fetchone( + link = await db.fetchone( "SELECT * FROM withdraw.withdraw_link WHERE unique_hash = :hash", {"hash": unique_hash}, + WithdrawLink, ) - if not row: + if not link: return None - link = dict(**row) - link["number"] = num + if not link: + return None - return WithdrawLink.parse_obj(link) + link.number = num + return link async def get_withdraw_links( wallet_ids: list[str], limit: int, offset: int ) -> tuple[list[WithdrawLink], int]: q = ",".join([f"'{w}'" for w in wallet_ids]) - rows = await db.fetchall( + links = await db.fetchall( f""" SELECT * FROM withdraw.withdraw_link WHERE wallet IN ({q}) ORDER BY open_time DESC LIMIT :limit OFFSET :offset """, {"limit": limit, "offset": offset}, + WithdrawLink, ) total = await db.fetchone( @@ -86,7 +88,7 @@ async def get_withdraw_links( """ ) - return [WithdrawLink(**row) for row in rows], total["total"] + return links, total["total"] async def remove_unique_withdraw_link(link: WithdrawLink, unique_hash: str) -> None: @@ -134,18 +136,19 @@ async def create_hash_check(the_hash: str, lnurl_id: str) -> HashCheck: async def get_hash_check(the_hash: str, lnurl_id: str) -> HashCheck: - rowid = await db.fetchone( - "SELECT * FROM withdraw.hash_check WHERE id = :id", {"id": the_hash} + hash_check = await db.fetchone( + "SELECT * FROM withdraw.hash_check WHERE id = :id", {"id": the_hash}, HashCheck ) - rowlnurl = await db.fetchone( + hash_check_lnurl = await db.fetchone( "SELECT * FROM withdraw.hash_check WHERE lnurl_id = :id", {"id": lnurl_id}, + HashCheck, ) - if not rowlnurl: + if not hash_check_lnurl: await create_hash_check(the_hash, lnurl_id) return HashCheck(lnurl=True, hash=False) else: - if not rowid: + if not hash_check: await create_hash_check(the_hash, lnurl_id) return HashCheck(lnurl=True, hash=False) else: diff --git a/models.py b/models.py index aa03907..ea40fe3 100644 --- a/models.py +++ b/models.py @@ -11,7 +11,7 @@ from lnurl import ( # type: ignore MilliSatoshi, # type: ignore ) from lnurl import encode as lnurl_encode -from pydantic import BaseModel +from pydantic import BaseModel, Field class CreateWithdrawData(BaseModel): @@ -42,7 +42,7 @@ class WithdrawLink(BaseModel): open_time: int = Query(0) used: int = Query(0) usescsv: str = Query(None) - number: int = Query(0) + number: int = Field(default=0, no_database=True) webhook_url: str = Query(None) webhook_headers: str = Query(None) webhook_body: str = Query(None) diff --git a/templates/withdraw/_api_docs.html b/templates/withdraw/_api_docs.html index ff88189..e3c9b5d 100644 --- a/templates/withdraw/_api_docs.html +++ b/templates/withdraw/_api_docs.html @@ -24,7 +24,7 @@
Curl example
curl -X GET {{ request.base_url }}withdraw/api/v1/links -H - "X-Api-Key: {{ user.wallets[0].inkey }}" + "X-Api-Key: " @@ -51,8 +51,8 @@
Curl example
curl -X GET {{ request.base_url - }}withdraw/api/v1/links/<withdraw_id> -H "X-Api-Key: {{ - user.wallets[0].inkey }}" + }}withdraw/api/v1/links/<withdraw_id> -H "X-Api-Key: + " @@ -86,7 +86,7 @@ "max_withdrawable": <integer>, "uses": <integer>, "wait_time": <integer>, "is_unique": <boolean>, "webhook_url": <string>}' -H "Content-type: application/json" -H - "X-Api-Key: {{ user.wallets[0].adminkey }}" + "X-Api-Key: " @@ -122,8 +122,8 @@ <string>, "min_withdrawable": <integer>, "max_withdrawable": <integer>, "uses": <integer>, "wait_time": <integer>, "is_unique": <boolean>}' -H - "Content-type: application/json" -H "X-Api-Key: {{ - user.wallets[0].adminkey }}" + "Content-type: application/json" -H "X-Api-Key: + " @@ -147,8 +147,8 @@
Curl example
curl -X DELETE {{ request.base_url - }}withdraw/api/v1/links/<withdraw_id> -H "X-Api-Key: {{ - user.wallets[0].adminkey }}" + }}withdraw/api/v1/links/<withdraw_id> -H "X-Api-Key: + " @@ -176,7 +176,7 @@ curl -X GET {{ request.base_url }}withdraw/api/v1/links/<the_hash>/<lnurl_id> -H - "X-Api-Key: {{ user.wallets[0].inkey }}" + "X-Api-Key: " diff --git a/templates/withdraw/index.html b/templates/withdraw/index.html index 8401a9f..3d79dcb 100644 --- a/templates/withdraw/index.html +++ b/templates/withdraw/index.html @@ -9,7 +9,11 @@ Quick vouchers - Advanced withdraw link(s) diff --git a/views.py b/views.py index 2ef9659..1fa7107 100644 --- a/views.py +++ b/views.py @@ -20,7 +20,7 @@ def withdraw_renderer(): @withdraw_ext_generic.get("/", response_class=HTMLResponse) async def index(request: Request, user: User = Depends(check_user_exists)): return withdraw_renderer().TemplateResponse( - "withdraw/index.html", {"request": request, "user": user.dict()} + "withdraw/index.html", {"request": request, "user": user.json()} )