From 15cd84652e59e12db3bda21260b4430c923eca9c Mon Sep 17 00:00:00 2001 From: benarc Date: Mon, 18 Oct 2021 10:28:31 +0100 Subject: [PATCH 1/3] copilot payments not triggering animations --- lnbits/extensions/copilot/lnurl.py | 56 ++++++++++++++++-------------- lnbits/extensions/copilot/tasks.py | 1 + 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/lnbits/extensions/copilot/lnurl.py b/lnbits/extensions/copilot/lnurl.py index d1c1fc95..cafb5921 100644 --- a/lnbits/extensions/copilot/lnurl.py +++ b/lnbits/extensions/copilot/lnurl.py @@ -33,21 +33,22 @@ async def lnurl_response(req: Request, cp_id: str = Query(None)): status_code=HTTPStatus.NOT_FOUND, detail="Copilot not found" ) - resp = LnurlPayResponse( - callback=req.url_for("copilot.lnurl_callback", cp_id=cp_id, _external=True), - min_sendable=10000, - max_sendable=50000000, - metadata=LnurlPayMetadata(json.dumps([["text/plain", str(cp.lnurl_title)]])), - ) + payResponse = { + "tag": "payRequest", + "callback": req.url_for("copilot.lnurl_callback", cp_id=cp_id), + "metadata": LnurlPayMetadata(json.dumps([["text/plain", str(cp.lnurl_title)]])), + "maxSendable": 50000000, + "minSendable": 10000, + } - params = resp.dict() if cp.show_message: - params["commentAllowed"] = 300 - - return params + payResponse["commentAllowed"] = 300 + return json.dumps(payResponse) -@copilot_ext.get("/lnurl/cb/{cp_id}", response_class=HTMLResponse) +@copilot_ext.get( + "/lnurl/cb/{cp_id}", response_class=HTMLResponse, name="copilot.lnurl_callback" +) async def lnurl_callback( cp_id: str = Query(None), amount: str = Query(None), comment: str = Query(None) ): @@ -56,26 +57,28 @@ async def lnurl_callback( raise HTTPException( status_code=HTTPStatus.NOT_FOUND, detail="Copilot not found" ) - + print(cp) amount_received = int(amount) if amount_received < 10000: - return LnurlErrorResponse( - reason=f"Amount {round(amount_received / 1000)} is smaller than minimum 10 sats." - ).dict() + raise HTTPException( + status_code=HTTPStatus.FORBIDDEN, + detail="Amount {round(amount_received / 1000)} is smaller than minimum 10 sats.", + ) elif amount_received / 1000 > 10000000: - return LnurlErrorResponse( - reason=f"Amount {round(amount_received / 1000)} is greater than maximum 50000." - ).dict() + raise HTTPException( + status_code=HTTPStatus.FORBIDDEN, + detail="Amount {round(amount_received / 1000)} is greater than maximum 50000.", + ) comment = "" if comment: if len(comment or "") > 300: - return LnurlErrorResponse( - reason=f"Got a comment with {len(comment)} characters, but can only accept 300" - ).dict() + raise HTTPException( + status_code=HTTPStatus.FORBIDDEN, + detail="Got a comment with {len(comment)} characters, but can only accept 300", + ) if len(comment) < 1: comment = "none" - payment_hash, payment_request = await create_invoice( wallet_id=cp.wallet, amount=int(amount_received / 1000), @@ -87,7 +90,8 @@ async def lnurl_callback( ).digest(), extra={"tag": "copilot", "copilot": cp.id, "comment": comment}, ) - resp = LnurlPayActionResponse( - pr=payment_request, success_action=None, disposable=False, routes=[] - ) - return resp.dict() + payResponse = { + "pr": payment_request, + "routes": [], + } + return json.dumps(payResponse) diff --git a/lnbits/extensions/copilot/tasks.py b/lnbits/extensions/copilot/tasks.py index b3b6c65c..bac260aa 100644 --- a/lnbits/extensions/copilot/tasks.py +++ b/lnbits/extensions/copilot/tasks.py @@ -26,6 +26,7 @@ async def wait_for_paid_invoices(): async def on_invoice_paid(payment: Payment) -> None: webhook = None data = None + print("cunt") if "copilot" != payment.extra.get("tag"): # not an copilot invoice return From 0cf11caaadf282ea499ed0cdc8cd8bf1ff29ca4b Mon Sep 17 00:00:00 2001 From: benarc Date: Mon, 18 Oct 2021 10:31:30 +0100 Subject: [PATCH 2/3] copilot payments not triggering animations listener issue --- lnbits/extensions/copilot/lnurl.py | 1 - lnbits/extensions/copilot/tasks.py | 9 ++------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/lnbits/extensions/copilot/lnurl.py b/lnbits/extensions/copilot/lnurl.py index cafb5921..367b1343 100644 --- a/lnbits/extensions/copilot/lnurl.py +++ b/lnbits/extensions/copilot/lnurl.py @@ -57,7 +57,6 @@ async def lnurl_callback( raise HTTPException( status_code=HTTPStatus.NOT_FOUND, detail="Copilot not found" ) - print(cp) amount_received = int(amount) if amount_received < 10000: diff --git a/lnbits/extensions/copilot/tasks.py b/lnbits/extensions/copilot/tasks.py index bac260aa..417f885f 100644 --- a/lnbits/extensions/copilot/tasks.py +++ b/lnbits/extensions/copilot/tasks.py @@ -26,15 +26,10 @@ async def wait_for_paid_invoices(): async def on_invoice_paid(payment: Payment) -> None: webhook = None data = None - print("cunt") if "copilot" != payment.extra.get("tag"): # not an copilot invoice return - if payment.extra.get("wh_status"): - # this webhook has already been sent - return - copilot = await get_copilot(payment.extra.get("copilot", -1)) if not copilot: @@ -71,8 +66,8 @@ async def on_invoice_paid(payment: Payment) -> None: await mark_webhook_sent(payment, -1) if payment.extra.get("comment"): await updater(copilot.id, data, payment.extra.get("comment")) - else: - await updater(copilot.id, data, "none") + + await updater(copilot.id, data, "none") async def mark_webhook_sent(payment: Payment, status: int) -> None: From 0d781f899c92d3632a2b9b4073f55e212020a9d2 Mon Sep 17 00:00:00 2001 From: benarc Date: Mon, 18 Oct 2021 10:41:41 +0100 Subject: [PATCH 3/3] copilot not triggering animations, listeners --- lnbits/extensions/copilot/lnurl.py | 2 +- lnbits/extensions/copilot/tasks.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lnbits/extensions/copilot/lnurl.py b/lnbits/extensions/copilot/lnurl.py index 367b1343..064b4b00 100644 --- a/lnbits/extensions/copilot/lnurl.py +++ b/lnbits/extensions/copilot/lnurl.py @@ -87,7 +87,7 @@ async def lnurl_callback( LnurlPayMetadata(json.dumps([["text/plain", str(cp.lnurl_title)]])) ).encode("utf-8") ).digest(), - extra={"tag": "copilot", "copilot": cp.id, "comment": comment}, + extra={"tag": "copilot", "copilotid": cp.id, "comment": comment}, ) payResponse = { "pr": payment_request, diff --git a/lnbits/extensions/copilot/tasks.py b/lnbits/extensions/copilot/tasks.py index 417f885f..d3b9e218 100644 --- a/lnbits/extensions/copilot/tasks.py +++ b/lnbits/extensions/copilot/tasks.py @@ -29,8 +29,9 @@ async def on_invoice_paid(payment: Payment) -> None: if "copilot" != payment.extra.get("tag"): # not an copilot invoice return + print("cunt") - copilot = await get_copilot(payment.extra.get("copilot", -1)) + copilot = await get_copilot(payment.extra.get("copilotid", -1)) if not copilot: raise HTTPException(