Converted some core stuff

This commit is contained in:
Ben Arc
2021-08-20 21:31:01 +01:00
parent bdbdc1601b
commit c4b37c6508
4 changed files with 99 additions and 157 deletions
+7 -7
View File
@@ -10,22 +10,22 @@ from ..crud import get_standalone_payment
from ..tasks import api_invoice_listeners
@core_app.route("/public/v1/payment/<payment_hash>", methods=["GET"])
@core_app.get("/public/v1/payment/<payment_hash>")
async def api_public_payment_longpolling(payment_hash):
payment = await get_standalone_payment(payment_hash)
if not payment:
return jsonify({"message": "Payment does not exist."}), HTTPStatus.NOT_FOUND
return {"message": "Payment does not exist."}, HTTPStatus.NOT_FOUND
elif not payment.pending:
return jsonify({"status": "paid"}), HTTPStatus.OK
return {"status": "paid"}, HTTPStatus.OK
try:
invoice = bolt11.decode(payment.bolt11)
expiration = datetime.datetime.fromtimestamp(invoice.date + invoice.expiry)
if expiration < datetime.datetime.now():
return jsonify({"status": "expired"}), HTTPStatus.OK
return {"status": "expired"}, HTTPStatus.OK
except:
return jsonify({"message": "Invalid bolt11 invoice."}), HTTPStatus.BAD_REQUEST
return {"message": "Invalid bolt11 invoice."}, HTTPStatus.BAD_REQUEST
send_payment, receive_payment = trio.open_memory_channel(0)
@@ -38,7 +38,7 @@ async def api_public_payment_longpolling(payment_hash):
async for payment in receive_payment:
if payment.payment_hash == payment_hash:
nonlocal response
response = (jsonify({"status": "paid"}), HTTPStatus.OK)
response = ({"status": "paid"}, HTTPStatus.OK)
cancel_scope.cancel()
async def timeouter(cancel_scope):
@@ -52,4 +52,4 @@ async def api_public_payment_longpolling(payment_hash):
if response:
return response
else:
return jsonify({"message": "timeout"}), HTTPStatus.REQUEST_TIMEOUT
return {"message": "timeout"}, HTTPStatus.REQUEST_TIMEOUT