From e419c74ebb5bbd09ceb6f08fc1d27a04701797c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Wed, 21 Feb 2024 08:07:13 +0100 Subject: [PATCH] refactor: remove unused webhook handler for wallets it was only used in lnpay, opennode and alby which all had it disabled anayways with a pretty old TODO, so i guess the feature is disabled for a y ear now and nobody used it, so i just removed it --- lnbits/app.py | 5 ----- lnbits/tasks.py | 12 ------------ lnbits/wallets/alby.py | 4 ---- lnbits/wallets/lnpay.py | 25 ------------------------- lnbits/wallets/opennode.py | 20 -------------------- 5 files changed, 66 deletions(-) diff --git a/lnbits/app.py b/lnbits/app.py index 431c7ac19..8e0c00900 100644 --- a/lnbits/app.py +++ b/lnbits/app.py @@ -61,7 +61,6 @@ from .tasks import ( check_pending_payments, internal_invoice_listener, invoice_listener, - webhook_handler, ) @@ -465,10 +464,6 @@ def get_db_vendor_name(): def register_async_tasks(app): - @app.route("/wallet/webhook") - async def webhook_listener(): - return await webhook_handler() - @app.on_event("startup") async def listeners(): create_permanent_task(check_pending_payments) diff --git a/lnbits/tasks.py b/lnbits/tasks.py index 10e5bb7b3..e5ee72f61 100644 --- a/lnbits/tasks.py +++ b/lnbits/tasks.py @@ -6,7 +6,6 @@ import uuid from http import HTTPStatus from typing import Dict, List, Optional -from fastapi.exceptions import HTTPException from loguru import logger from py_vapid import Vapid from pywebpush import WebPushException, webpush @@ -75,17 +74,6 @@ def register_invoice_listener(send_chan: asyncio.Queue, name: Optional[str] = No invoice_listeners[name] = send_chan -async def webhook_handler(): - """ - Returns the webhook_handler for the selected wallet if present. Used by API. - """ - WALLET = get_wallet_class() - handler = getattr(WALLET, "webhook_listener", None) - if handler: - return await handler() - raise HTTPException(status_code=HTTPStatus.NO_CONTENT) - - internal_invoice_queue: asyncio.Queue = asyncio.Queue(0) diff --git a/lnbits/wallets/alby.py b/lnbits/wallets/alby.py index 7b7507739..2b6ebc483 100644 --- a/lnbits/wallets/alby.py +++ b/lnbits/wallets/alby.py @@ -126,7 +126,3 @@ class AlbyWallet(Wallet): while True: value = await self.queue.get() yield value - - async def webhook_listener(self): - logger.error("Alby webhook listener disabled") - return diff --git a/lnbits/wallets/lnpay.py b/lnbits/wallets/lnpay.py index 727dee013..65d04ea5d 100644 --- a/lnbits/wallets/lnpay.py +++ b/lnbits/wallets/lnpay.py @@ -147,28 +147,3 @@ class LNPayWallet(Wallet): while True: value = await self.queue.get() yield value - - async def webhook_listener(self): - logger.error("LNPay webhook listener disabled.") - return - # TODO: request.get_data is undefined, was it something with Flask or quart? - # probably issue introduced when refactoring? - # text: str = await request.get_data() - # try: - # data = json.loads(text) - # except json.decoder.JSONDecodeError: - # logger.error(f"error on lnpay webhook endpoint: {text[:200]}") - # data = None - # if ( - # type(data) is not dict - # or "event" not in data - # or data["event"].get("name") != "wallet_receive" - # ): - # raise HTTPException(status_code=HTTPStatus.NO_CONTENT) - - # lntx_id = data["data"]["wtx"]["lnTx"]["id"] - # r = await self.client.get(f"/lntx/{lntx_id}?fields=settled") - # data = r.json() - # if data["settled"]: - # await self.queue.put(lntx_id) - # raise HTTPException(status_code=HTTPStatus.NO_CONTENT) diff --git a/lnbits/wallets/opennode.py b/lnbits/wallets/opennode.py index 7f20447b0..d71d2aec6 100644 --- a/lnbits/wallets/opennode.py +++ b/lnbits/wallets/opennode.py @@ -80,7 +80,6 @@ class OpenNodeWallet(Wallet): json={ "amount": amount, "description": memo or "", - # "callback_url": url_for("/webhook_listener", _external=True), }, timeout=40, ) @@ -144,22 +143,3 @@ class OpenNodeWallet(Wallet): while True: value = await self.queue.get() yield value - - async def webhook_listener(self): - logger.error("webhook listener for opennode is disabled.") - return - # TODO: request.form is undefined, was it something with Flask or quart? - # probably issue introduced when refactoring? - # data = await request.form # type: ignore - # if "status" not in data or data["status"] != "paid": - # raise HTTPException(status_code=HTTPStatus.NO_CONTENT) - - # charge_id = data["id"] - # x = hmac.new(self.key.encode("ascii"), digestmod="sha256") - # x.update(charge_id.encode("ascii")) - # if x.hexdigest() != data["hashed_order"]: - # logger.error("invalid webhook, not from opennode") - # raise HTTPException(status_code=HTTPStatus.NO_CONTENT) - - # await self.queue.put(charge_id) - # raise HTTPException(status_code=HTTPStatus.NO_CONTENT)