diff --git a/lnbits/extensions/withdraw/crud.py b/lnbits/extensions/withdraw/crud.py index 78fd7f56..64d4373e 100644 --- a/lnbits/extensions/withdraw/crud.py +++ b/lnbits/extensions/withdraw/crud.py @@ -98,3 +98,28 @@ async def delete_withdraw_link(link_id: str) -> None: def chunks(lst, n): for i in range(0, len(lst), 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 \ No newline at end of file diff --git a/lnbits/extensions/withdraw/models.py b/lnbits/extensions/withdraw/models.py index 1903dba6..4d147f25 100644 --- a/lnbits/extensions/withdraw/models.py +++ b/lnbits/extensions/withdraw/models.py @@ -63,7 +63,6 @@ class WithdrawLink(NamedTuple): class HashCheck(NamedTuple): id: str lnurl_id: str - @classmethod def from_row(cls, row: Row) -> "Hash": return cls(**dict(row)) \ No newline at end of file diff --git a/lnbits/extensions/withdraw/views_api.py b/lnbits/extensions/withdraw/views_api.py index cb8b7f0a..d34422ba 100644 --- a/lnbits/extensions/withdraw/views_api.py +++ b/lnbits/extensions/withdraw/views_api.py @@ -12,6 +12,8 @@ from .crud import ( get_withdraw_links, update_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) return "", HTTPStatus.NO_CONTENT + +@withdraw_ext.route("/api/v1/links//", 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