From 00ec6f2af390b081ed2c9e90ace37d6f1041e0b4 Mon Sep 17 00:00:00 2001 From: benarc Date: Wed, 3 Nov 2021 09:49:52 +0000 Subject: [PATCH 1/4] added NOT_FOUND to check payment endpoint, rather than OK --- lnbits/core/views/api.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lnbits/core/views/api.py b/lnbits/core/views/api.py index 894b4a444..02769f79b 100644 --- a/lnbits/core/views/api.py +++ b/lnbits/core/views/api.py @@ -329,7 +329,9 @@ async def api_payment(payment_hash): await check_invoice_status(payment.wallet_id, payment_hash) payment = await get_standalone_payment(payment_hash) if not payment: - return {"message": "Payment does not exist."} + raise HTTPException( + status_code=HTTPStatus.NOT_FOUND, detail="Payment does not exist." + ) elif not payment.pending: return {"paid": True, "preimage": payment.preimage} From 573ad3fb73a07af33334cf3591a9f18124b59009 Mon Sep 17 00:00:00 2001 From: benarc Date: Wed, 3 Nov 2021 10:02:21 +0000 Subject: [PATCH 2/4] Added a try to fix lnbits funding source errors --- lnbits/wallets/lnbits.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lnbits/wallets/lnbits.py b/lnbits/wallets/lnbits.py index 638fb7c1c..6a1bd02b5 100644 --- a/lnbits/wallets/lnbits.py +++ b/lnbits/wallets/lnbits.py @@ -98,16 +98,18 @@ class LNbitsWallet(Wallet): return PaymentResponse(ok, checking_id, fee_msat, error_message) async def get_invoice_status(self, checking_id: str) -> PaymentStatus: - async with httpx.AsyncClient() as client: - r = await client.get( - url=f"{self.endpoint}/api/v1/payments/{checking_id}", headers=self.key - ) - - if r.is_error: + try: + async with httpx.AsyncClient() as client: + r = await client.get( + url=f"{self.endpoint}/api/v1/payments/{checking_id}", + headers=self.key, + ) + if r.is_error: + return PaymentStatus(None) + return PaymentStatus(r.json()["paid"]) + except: return PaymentStatus(None) - return PaymentStatus(r.json()["paid"]) - async def get_payment_status(self, checking_id: str) -> PaymentStatus: async with httpx.AsyncClient() as client: r = await client.get( From c734526bc1a9975f4f0bc90cd7938715aa0661c8 Mon Sep 17 00:00:00 2001 From: benarc Date: Wed, 3 Nov 2021 10:12:14 +0000 Subject: [PATCH 3/4] reverted exception --- lnbits/core/views/api.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lnbits/core/views/api.py b/lnbits/core/views/api.py index 02769f79b..894b4a444 100644 --- a/lnbits/core/views/api.py +++ b/lnbits/core/views/api.py @@ -329,9 +329,7 @@ async def api_payment(payment_hash): await check_invoice_status(payment.wallet_id, payment_hash) payment = await get_standalone_payment(payment_hash) if not payment: - raise HTTPException( - status_code=HTTPStatus.NOT_FOUND, detail="Payment does not exist." - ) + return {"message": "Payment does not exist."} elif not payment.pending: return {"paid": True, "preimage": payment.preimage} From abff990ec3714e747d1566de1fd218b1043c5d6c Mon Sep 17 00:00:00 2001 From: benarc Date: Wed, 3 Nov 2021 10:29:39 +0000 Subject: [PATCH 4/4] Changed lnbits wallet check to detail from message --- lnbits/core/views/api.py | 6 ++++-- lnbits/wallets/lnbits.py | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lnbits/core/views/api.py b/lnbits/core/views/api.py index 894b4a444..553e1b903 100644 --- a/lnbits/core/views/api.py +++ b/lnbits/core/views/api.py @@ -324,12 +324,14 @@ async def api_payments_sse( @core_app.get("/api/v1/payments/{payment_hash}") async def api_payment(payment_hash): - payment = await get_standalone_payment(payment_hash) await check_invoice_status(payment.wallet_id, payment_hash) payment = await get_standalone_payment(payment_hash) if not payment: - return {"message": "Payment does not exist."} + raise HTTPException( + status_code=HTTPStatus.NOT_FOUND, + detail="Payment does not exist.", + ) elif not payment.pending: return {"paid": True, "preimage": payment.preimage} diff --git a/lnbits/wallets/lnbits.py b/lnbits/wallets/lnbits.py index 6a1bd02b5..70d7b141d 100644 --- a/lnbits/wallets/lnbits.py +++ b/lnbits/wallets/lnbits.py @@ -45,7 +45,7 @@ class LNbitsWallet(Wallet): ) if r.is_error: - return StatusResponse(data["message"], 0) + return StatusResponse(data["detail"], 0) return StatusResponse(None, data["balance"]) @@ -73,7 +73,7 @@ class LNbitsWallet(Wallet): ) if r.is_error: - error_message = r.json()["message"] + error_message = r.json()["detail"] else: data = r.json() checking_id, payment_request = data["checking_id"], data["payment_request"] @@ -90,7 +90,7 @@ class LNbitsWallet(Wallet): ok, checking_id, fee_msat, error_message = not r.is_error, None, 0, None if r.is_error: - error_message = r.json()["message"] + error_message = r.json()["detail"] else: data = r.json() checking_id = data["checking_id"]