fix: v1 changes
This commit is contained in:
parent
134016312f
commit
7ea4146d7f
5 changed files with 38 additions and 31 deletions
39
crud.py
39
crud.py
|
|
@ -40,43 +40,45 @@ async def create_withdraw_link(
|
||||||
|
|
||||||
|
|
||||||
async def get_withdraw_link(link_id: str, num=0) -> Optional[WithdrawLink]:
|
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",
|
"SELECT * FROM withdraw.withdraw_link WHERE id = :id",
|
||||||
{"id": link_id},
|
{"id": link_id},
|
||||||
|
WithdrawLink,
|
||||||
)
|
)
|
||||||
if not row:
|
if not link:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
link = dict(**row)
|
link.number = num
|
||||||
link["number"] = num
|
return link
|
||||||
|
|
||||||
return WithdrawLink.parse_obj(link)
|
|
||||||
|
|
||||||
|
|
||||||
async def get_withdraw_link_by_hash(unique_hash: str, num=0) -> Optional[WithdrawLink]:
|
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",
|
"SELECT * FROM withdraw.withdraw_link WHERE unique_hash = :hash",
|
||||||
{"hash": unique_hash},
|
{"hash": unique_hash},
|
||||||
|
WithdrawLink,
|
||||||
)
|
)
|
||||||
if not row:
|
if not link:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
link = dict(**row)
|
if not link:
|
||||||
link["number"] = num
|
return None
|
||||||
|
|
||||||
return WithdrawLink.parse_obj(link)
|
link.number = num
|
||||||
|
return link
|
||||||
|
|
||||||
|
|
||||||
async def get_withdraw_links(
|
async def get_withdraw_links(
|
||||||
wallet_ids: list[str], limit: int, offset: int
|
wallet_ids: list[str], limit: int, offset: int
|
||||||
) -> tuple[list[WithdrawLink], int]:
|
) -> tuple[list[WithdrawLink], int]:
|
||||||
q = ",".join([f"'{w}'" for w in wallet_ids])
|
q = ",".join([f"'{w}'" for w in wallet_ids])
|
||||||
rows = await db.fetchall(
|
links = await db.fetchall(
|
||||||
f"""
|
f"""
|
||||||
SELECT * FROM withdraw.withdraw_link WHERE wallet IN ({q})
|
SELECT * FROM withdraw.withdraw_link WHERE wallet IN ({q})
|
||||||
ORDER BY open_time DESC LIMIT :limit OFFSET :offset
|
ORDER BY open_time DESC LIMIT :limit OFFSET :offset
|
||||||
""",
|
""",
|
||||||
{"limit": limit, "offset": offset},
|
{"limit": limit, "offset": offset},
|
||||||
|
WithdrawLink,
|
||||||
)
|
)
|
||||||
|
|
||||||
total = await db.fetchone(
|
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:
|
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:
|
async def get_hash_check(the_hash: str, lnurl_id: str) -> HashCheck:
|
||||||
rowid = await db.fetchone(
|
hash_check = await db.fetchone(
|
||||||
"SELECT * FROM withdraw.hash_check WHERE id = :id", {"id": the_hash}
|
"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",
|
"SELECT * FROM withdraw.hash_check WHERE lnurl_id = :id",
|
||||||
{"id": lnurl_id},
|
{"id": lnurl_id},
|
||||||
|
HashCheck,
|
||||||
)
|
)
|
||||||
if not rowlnurl:
|
if not hash_check_lnurl:
|
||||||
await create_hash_check(the_hash, lnurl_id)
|
await create_hash_check(the_hash, lnurl_id)
|
||||||
return HashCheck(lnurl=True, hash=False)
|
return HashCheck(lnurl=True, hash=False)
|
||||||
else:
|
else:
|
||||||
if not rowid:
|
if not hash_check:
|
||||||
await create_hash_check(the_hash, lnurl_id)
|
await create_hash_check(the_hash, lnurl_id)
|
||||||
return HashCheck(lnurl=True, hash=False)
|
return HashCheck(lnurl=True, hash=False)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ from lnurl import ( # type: ignore
|
||||||
MilliSatoshi, # type: ignore
|
MilliSatoshi, # type: ignore
|
||||||
)
|
)
|
||||||
from lnurl import encode as lnurl_encode
|
from lnurl import encode as lnurl_encode
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
|
||||||
class CreateWithdrawData(BaseModel):
|
class CreateWithdrawData(BaseModel):
|
||||||
|
|
@ -42,7 +42,7 @@ class WithdrawLink(BaseModel):
|
||||||
open_time: int = Query(0)
|
open_time: int = Query(0)
|
||||||
used: int = Query(0)
|
used: int = Query(0)
|
||||||
usescsv: str = Query(None)
|
usescsv: str = Query(None)
|
||||||
number: int = Query(0)
|
number: int = Field(default=0, no_database=True)
|
||||||
webhook_url: str = Query(None)
|
webhook_url: str = Query(None)
|
||||||
webhook_headers: str = Query(None)
|
webhook_headers: str = Query(None)
|
||||||
webhook_body: str = Query(None)
|
webhook_body: str = Query(None)
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
>curl -X GET {{ request.base_url }}withdraw/api/v1/links -H
|
>curl -X GET {{ request.base_url }}withdraw/api/v1/links -H
|
||||||
"X-Api-Key: {{ user.wallets[0].inkey }}"
|
"X-Api-Key: <span v-text="user.wallets[0].inkey"></span>"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
|
@ -51,8 +51,8 @@
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
>curl -X GET {{ request.base_url
|
>curl -X GET {{ request.base_url
|
||||||
}}withdraw/api/v1/links/<withdraw_id> -H "X-Api-Key: {{
|
}}withdraw/api/v1/links/<withdraw_id> -H "X-Api-Key:
|
||||||
user.wallets[0].inkey }}"
|
<span v-text="user.wallets[0].inkey"></span>"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
|
@ -86,7 +86,7 @@
|
||||||
"max_withdrawable": <integer>, "uses": <integer>,
|
"max_withdrawable": <integer>, "uses": <integer>,
|
||||||
"wait_time": <integer>, "is_unique": <boolean>,
|
"wait_time": <integer>, "is_unique": <boolean>,
|
||||||
"webhook_url": <string>}' -H "Content-type: application/json" -H
|
"webhook_url": <string>}' -H "Content-type: application/json" -H
|
||||||
"X-Api-Key: {{ user.wallets[0].adminkey }}"
|
"X-Api-Key: <span v-text="user.wallets[0].adminkey"></span>"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
|
@ -122,8 +122,8 @@
|
||||||
<string>, "min_withdrawable": <integer>,
|
<string>, "min_withdrawable": <integer>,
|
||||||
"max_withdrawable": <integer>, "uses": <integer>,
|
"max_withdrawable": <integer>, "uses": <integer>,
|
||||||
"wait_time": <integer>, "is_unique": <boolean>}' -H
|
"wait_time": <integer>, "is_unique": <boolean>}' -H
|
||||||
"Content-type: application/json" -H "X-Api-Key: {{
|
"Content-type: application/json" -H "X-Api-Key:
|
||||||
user.wallets[0].adminkey }}"
|
<span v-text="user.wallets[0].adminkey"></span>"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
|
@ -147,8 +147,8 @@
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
>curl -X DELETE {{ request.base_url
|
>curl -X DELETE {{ request.base_url
|
||||||
}}withdraw/api/v1/links/<withdraw_id> -H "X-Api-Key: {{
|
}}withdraw/api/v1/links/<withdraw_id> -H "X-Api-Key:
|
||||||
user.wallets[0].adminkey }}"
|
<span v-text="user.wallets[0].adminkey"></span>"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
|
@ -176,7 +176,7 @@
|
||||||
<code
|
<code
|
||||||
>curl -X GET {{ request.base_url
|
>curl -X GET {{ request.base_url
|
||||||
}}withdraw/api/v1/links/<the_hash>/<lnurl_id> -H
|
}}withdraw/api/v1/links/<the_hash>/<lnurl_id> -H
|
||||||
"X-Api-Key: {{ user.wallets[0].inkey }}"
|
"X-Api-Key: <span v-text="user.wallets[0].inkey"></span>"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,11 @@
|
||||||
<q-btn unelevated color="primary" @click="simpleformDialog.show = true"
|
<q-btn unelevated color="primary" @click="simpleformDialog.show = true"
|
||||||
>Quick vouchers</q-btn
|
>Quick vouchers</q-btn
|
||||||
>
|
>
|
||||||
<q-btn unelevated color="primary" @click="formDialog.show = true"
|
<q-btn
|
||||||
|
unelevated
|
||||||
|
color="primary"
|
||||||
|
@click="formDialog.show = true"
|
||||||
|
class="q-ml-md"
|
||||||
>Advanced withdraw link(s)</q-btn
|
>Advanced withdraw link(s)</q-btn
|
||||||
>
|
>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
|
|
|
||||||
2
views.py
2
views.py
|
|
@ -20,7 +20,7 @@ def withdraw_renderer():
|
||||||
@withdraw_ext_generic.get("/", response_class=HTMLResponse)
|
@withdraw_ext_generic.get("/", response_class=HTMLResponse)
|
||||||
async def index(request: Request, user: User = Depends(check_user_exists)):
|
async def index(request: Request, user: User = Depends(check_user_exists)):
|
||||||
return withdraw_renderer().TemplateResponse(
|
return withdraw_renderer().TemplateResponse(
|
||||||
"withdraw/index.html", {"request": request, "user": user.dict()}
|
"withdraw/index.html", {"request": request, "user": user.json()}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue