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
This commit is contained in:
dni ⚡
2024-02-21 08:07:13 +01:00
committed by Pavol Rusnak
parent b6dc66b070
commit e419c74ebb
5 changed files with 0 additions and 66 deletions

View File

@@ -61,7 +61,6 @@ from .tasks import (
check_pending_payments, check_pending_payments,
internal_invoice_listener, internal_invoice_listener,
invoice_listener, invoice_listener,
webhook_handler,
) )
@@ -465,10 +464,6 @@ def get_db_vendor_name():
def register_async_tasks(app): def register_async_tasks(app):
@app.route("/wallet/webhook")
async def webhook_listener():
return await webhook_handler()
@app.on_event("startup") @app.on_event("startup")
async def listeners(): async def listeners():
create_permanent_task(check_pending_payments) create_permanent_task(check_pending_payments)

View File

@@ -6,7 +6,6 @@ import uuid
from http import HTTPStatus from http import HTTPStatus
from typing import Dict, List, Optional from typing import Dict, List, Optional
from fastapi.exceptions import HTTPException
from loguru import logger from loguru import logger
from py_vapid import Vapid from py_vapid import Vapid
from pywebpush import WebPushException, webpush 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 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) internal_invoice_queue: asyncio.Queue = asyncio.Queue(0)

View File

@@ -126,7 +126,3 @@ class AlbyWallet(Wallet):
while True: while True:
value = await self.queue.get() value = await self.queue.get()
yield value yield value
async def webhook_listener(self):
logger.error("Alby webhook listener disabled")
return

View File

@@ -147,28 +147,3 @@ class LNPayWallet(Wallet):
while True: while True:
value = await self.queue.get() value = await self.queue.get()
yield value 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)

View File

@@ -80,7 +80,6 @@ class OpenNodeWallet(Wallet):
json={ json={
"amount": amount, "amount": amount,
"description": memo or "", "description": memo or "",
# "callback_url": url_for("/webhook_listener", _external=True),
}, },
timeout=40, timeout=40,
) )
@@ -144,22 +143,3 @@ class OpenNodeWallet(Wallet):
while True: while True:
value = await self.queue.get() value = await self.queue.get()
yield value 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)