Should work
This commit is contained in:
parent
7cd3487bc9
commit
514329045f
3 changed files with 41 additions and 1 deletions
|
|
@ -98,3 +98,28 @@ async def delete_withdraw_link(link_id: str) -> None:
|
||||||
def chunks(lst, n):
|
def chunks(lst, n):
|
||||||
for i in range(0, len(lst), n):
|
for i in range(0, len(lst), n):
|
||||||
yield lst[i : i + n]
|
yield lst[i : i + n]
|
||||||
|
|
||||||
|
async def create_hash_check(
|
||||||
|
the_hash: str,
|
||||||
|
lnurl_id: str,
|
||||||
|
) -> HashCheck:
|
||||||
|
await db.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO hash_check (
|
||||||
|
id,
|
||||||
|
lnurl_id
|
||||||
|
)
|
||||||
|
VALUES (?, ?)
|
||||||
|
""",
|
||||||
|
(
|
||||||
|
the_hash,
|
||||||
|
lnurl_id,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
hashCheck = await get_hash_check(the_hash, lnurl_id)
|
||||||
|
row = await db.fetchone("SELECT * FROM hash_check WHERE id = ?", (the_hash,))
|
||||||
|
return HashCheck.from_row(row) if row else None
|
||||||
|
|
||||||
|
async def get_hash_check(the_hash: str, lnurl_id: str) -> Optional[HashCheck]:
|
||||||
|
row = await db.fetchone("SELECT * FROM hash_check WHERE id = ?", (the_hash,))
|
||||||
|
return HashCheck.from_row(row) if row else None
|
||||||
|
|
@ -63,7 +63,6 @@ class WithdrawLink(NamedTuple):
|
||||||
class HashCheck(NamedTuple):
|
class HashCheck(NamedTuple):
|
||||||
id: str
|
id: str
|
||||||
lnurl_id: str
|
lnurl_id: str
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_row(cls, row: Row) -> "Hash":
|
def from_row(cls, row: Row) -> "Hash":
|
||||||
return cls(**dict(row))
|
return cls(**dict(row))
|
||||||
|
|
@ -12,6 +12,8 @@ from .crud import (
|
||||||
get_withdraw_links,
|
get_withdraw_links,
|
||||||
update_withdraw_link,
|
update_withdraw_link,
|
||||||
delete_withdraw_link,
|
delete_withdraw_link,
|
||||||
|
create_hash_check,
|
||||||
|
get_hash_check,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -111,3 +113,17 @@ async def api_link_delete(link_id):
|
||||||
await delete_withdraw_link(link_id)
|
await delete_withdraw_link(link_id)
|
||||||
|
|
||||||
return "", HTTPStatus.NO_CONTENT
|
return "", HTTPStatus.NO_CONTENT
|
||||||
|
|
||||||
|
@withdraw_ext.route("/api/v1/links/<the_hash>/<lnurl_id>", methods=["GET"])
|
||||||
|
@api_check_wallet_key("invoice")
|
||||||
|
async def api_hash_retrieve(the_hash, lnurl_id):
|
||||||
|
hashCheck = await get_hash_check(the_hash, lnurl_id)
|
||||||
|
|
||||||
|
if not hashCheck:
|
||||||
|
hashCheck = await create_hash_check(the_hash, lnurl_id)
|
||||||
|
return jsonify({"status": False}), HTTPStatus.OK
|
||||||
|
|
||||||
|
if link.wallet != g.wallet.id:
|
||||||
|
return jsonify({"status": True}), HTTPStatus.OK
|
||||||
|
|
||||||
|
return jsonify({"status": True}), HTTPStatus.OK
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue