fixing withdraw

This commit is contained in:
Ben Arc
2021-08-20 22:21:15 +01:00
parent c4b37c6508
commit 8deea85999
2 changed files with 28 additions and 41 deletions
+18 -22
View File
@@ -12,41 +12,39 @@ from .crud import get_withdraw_link_by_hash, update_withdraw_link
# FOR LNURLs WHICH ARE NOT UNIQUE
@withdraw_ext.route("/api/v1/lnurl/<unique_hash>", methods=["GET"])
@withdraw_ext.get("/api/v1/lnurl/<unique_hash>")
async def api_lnurl_response(unique_hash):
link = await get_withdraw_link_by_hash(unique_hash)
if not link:
return (
jsonify({"status": "ERROR", "reason": "LNURL-withdraw not found."}),
return ({"status": "ERROR", "reason": "LNURL-withdraw not found."},
HTTPStatus.OK,
)
if link.is_spent:
return (
jsonify({"status": "ERROR", "reason": "Withdraw is spent."}),
return ({"status": "ERROR", "reason": "Withdraw is spent."},
HTTPStatus.OK,
)
return jsonify(link.lnurl_response.dict()), HTTPStatus.OK
return link.lnurl_response.dict(), HTTPStatus.OK
# FOR LNURLs WHICH ARE UNIQUE
@withdraw_ext.route("/api/v1/lnurl/<unique_hash>/<id_unique_hash>", methods=["GET"])
@withdraw_ext.route("/api/v1/lnurl/<unique_hash>/<id_unique_hash>")
async def api_lnurl_multi_response(unique_hash, id_unique_hash):
link = await get_withdraw_link_by_hash(unique_hash)
if not link:
return (
jsonify({"status": "ERROR", "reason": "LNURL-withdraw not found."}),
{"status": "ERROR", "reason": "LNURL-withdraw not found."},
HTTPStatus.OK,
)
if link.is_spent:
return (
jsonify({"status": "ERROR", "reason": "Withdraw is spent."}),
{"status": "ERROR", "reason": "Withdraw is spent."},
HTTPStatus.OK,
)
@@ -58,17 +56,17 @@ async def api_lnurl_multi_response(unique_hash, id_unique_hash):
found = True
if not found:
return (
jsonify({"status": "ERROR", "reason": "LNURL-withdraw not found."}),
{"status": "ERROR", "reason": "LNURL-withdraw not found."},
HTTPStatus.OK,
)
return jsonify(link.lnurl_response.dict()), HTTPStatus.OK
return link.lnurl_response.dict(), HTTPStatus.OK
# CALLBACK
@withdraw_ext.route("/api/v1/lnurl/cb/<unique_hash>", methods=["GET"])
@withdraw_ext.get("/api/v1/lnurl/cb/<unique_hash>")
async def api_lnurl_callback(unique_hash):
link = await get_withdraw_link_by_hash(unique_hash)
k1 = request.args.get("k1", type=str)
@@ -77,24 +75,22 @@ async def api_lnurl_callback(unique_hash):
if not link:
return (
jsonify({"status": "ERROR", "reason": "LNURL-withdraw not found."}),
{"status": "ERROR", "reason": "LNURL-withdraw not found."},
HTTPStatus.OK,
)
if link.is_spent:
return (
jsonify({"status": "ERROR", "reason": "Withdraw is spent."}),
{"status": "ERROR", "reason": "Withdraw is spent."},
HTTPStatus.OK,
)
if link.k1 != k1:
return jsonify({"status": "ERROR", "reason": "Bad request."}), HTTPStatus.OK
return {"status": "ERROR", "reason": "Bad request."}, HTTPStatus.OK
if now < link.open_time:
return (
jsonify(
{"status": "ERROR", "reason": f"Wait {link.open_time - now} seconds."}
),
{"status": "ERROR", "reason": f"Wait {link.open_time - now} seconds."},
HTTPStatus.OK,
)
@@ -128,12 +124,12 @@ async def api_lnurl_callback(unique_hash):
)
except ValueError as e:
await update_withdraw_link(link.id, **changesback)
return jsonify({"status": "ERROR", "reason": str(e)})
return {"status": "ERROR", "reason": str(e)}
except PermissionError:
await update_withdraw_link(link.id, **changesback)
return jsonify({"status": "ERROR", "reason": "Withdraw link is empty."})
return {"status": "ERROR", "reason": "Withdraw link is empty."}
except Exception as e:
await update_withdraw_link(link.id, **changesback)
return jsonify({"status": "ERROR", "reason": str(e)})
return {"status": "ERROR", "reason": str(e)}
return jsonify({"status": "OK"}), HTTPStatus.OK
return {"status": "OK"}, HTTPStatus.OK