uncomment webhook_listerner and add TODO

This commit is contained in:
dni ⚡
2023-04-04 07:34:50 +02:00
parent 9c8a79eb9b
commit abfee29676
2 changed files with 46 additions and 40 deletions
+28 -22
View File
@@ -1,8 +1,12 @@
import asyncio
import hashlib
import json
from http import HTTPStatus
from typing import AsyncGenerator, Dict, Optional
import httpx
from fastapi import HTTPException
from loguru import logger
from lnbits.settings import settings
@@ -133,27 +137,29 @@ class LNPayWallet(Wallet):
value = await self.queue.get()
yield value
# async def webhook_listener(self):
# text: str = await request.get_data()
# try:
# data = json.loads(text)
# except json.decoder.JSONDecodeError:
# logger.error(f"got something wrong 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)
async def webhook_listener(self):
# TODO: request.get_data is undefined, was it something with Flask or quart?
# probably issue introduced when refactoring?
text: str = await request.get_data() # type: ignore
try:
data = json.loads(text)
except json.decoder.JSONDecodeError:
logger.error(f"got something wrong 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"]
# async with httpx.AsyncClient() as client:
# r = await client.get(
# f"{self.endpoint}/lntx/{lntx_id}?fields=settled", headers=self.auth
# )
# data = r.json()
# if data["settled"]:
# await self.queue.put(lntx_id)
lntx_id = data["data"]["wtx"]["lnTx"]["id"]
async with httpx.AsyncClient() as client:
r = await client.get(
f"{self.endpoint}/lntx/{lntx_id}?fields=settled", headers=self.auth
)
data = r.json()
if data["settled"]:
await self.queue.put(lntx_id)
# raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)