Merge pull request #164 from lnbits/lnurlwhashcheck

Changed api to check lnurl exists and checking hash sent
This commit is contained in:
Arc 2021-03-20 01:08:59 +00:00 committed by GitHub
commit e4fb18a53a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 11 deletions

View File

@ -118,11 +118,17 @@ async def create_hash_check(
),
)
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
return hashCheck
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
rowid = await db.fetchone("SELECT * FROM hash_check WHERE id = ?", (the_hash,))
rowlnurl = await db.fetchone("SELECT * FROM hash_check WHERE lnurl_id = ?", (the_hash,))
if not rowlnurl:
return {"lnurl": False, "hash": False}
else:
if not rowid:
await create_hash_check(the_hash, lnurl_id)
return {"lnurl": True, "hash": False}
else:
return {"lnurl": True, "hash": True}

View File

@ -119,9 +119,4 @@ async def api_link_delete(link_id):
@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
return jsonify({"status": True}), HTTPStatus.OK
return jsonify(hashCheck), HTTPStatus.OK