mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-03-10 09:19:42 +01:00
uncomment webhook_listerner and add TODO
This commit is contained in:
parent
9c8a79eb9b
commit
abfee29676
2 changed files with 46 additions and 40 deletions
|
@ -1,8 +1,12 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import json
|
||||||
|
from http import HTTPStatus
|
||||||
from typing import AsyncGenerator, Dict, Optional
|
from typing import AsyncGenerator, Dict, Optional
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
from fastapi import HTTPException
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
from lnbits.settings import settings
|
from lnbits.settings import settings
|
||||||
|
|
||||||
|
@ -133,27 +137,29 @@ class LNPayWallet(Wallet):
|
||||||
value = await self.queue.get()
|
value = await self.queue.get()
|
||||||
yield value
|
yield value
|
||||||
|
|
||||||
# async def webhook_listener(self):
|
async def webhook_listener(self):
|
||||||
# text: str = await request.get_data()
|
# TODO: request.get_data is undefined, was it something with Flask or quart?
|
||||||
# try:
|
# probably issue introduced when refactoring?
|
||||||
# data = json.loads(text)
|
text: str = await request.get_data() # type: ignore
|
||||||
# except json.decoder.JSONDecodeError:
|
try:
|
||||||
# logger.error(f"got something wrong on lnpay webhook endpoint: {text[:200]}")
|
data = json.loads(text)
|
||||||
# data = None
|
except json.decoder.JSONDecodeError:
|
||||||
# if (
|
logger.error(f"got something wrong on lnpay webhook endpoint: {text[:200]}")
|
||||||
# type(data) is not dict
|
data = None
|
||||||
# or "event" not in data
|
if (
|
||||||
# or data["event"].get("name") != "wallet_receive"
|
type(data) is not dict
|
||||||
# ):
|
or "event" not in data
|
||||||
# raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
or data["event"].get("name") != "wallet_receive"
|
||||||
|
):
|
||||||
|
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
||||||
|
|
||||||
# lntx_id = data["data"]["wtx"]["lnTx"]["id"]
|
lntx_id = data["data"]["wtx"]["lnTx"]["id"]
|
||||||
# async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
# r = await client.get(
|
r = await client.get(
|
||||||
# f"{self.endpoint}/lntx/{lntx_id}?fields=settled", headers=self.auth
|
f"{self.endpoint}/lntx/{lntx_id}?fields=settled", headers=self.auth
|
||||||
# )
|
)
|
||||||
# data = r.json()
|
data = r.json()
|
||||||
# if data["settled"]:
|
if data["settled"]:
|
||||||
# await self.queue.put(lntx_id)
|
await self.queue.put(lntx_id)
|
||||||
|
|
||||||
# raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import hmac
|
||||||
# import hmac
|
from http import HTTPStatus
|
||||||
# from http import HTTPStatus
|
|
||||||
from typing import AsyncGenerator, Optional
|
from typing import AsyncGenerator, Optional
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
from fastapi import HTTPException
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
from lnbits.settings import settings
|
from lnbits.settings import settings
|
||||||
|
|
||||||
|
@ -17,9 +18,6 @@ from .base import (
|
||||||
Wallet,
|
Wallet,
|
||||||
)
|
)
|
||||||
|
|
||||||
# from fastapi import Request, HTTPException
|
|
||||||
# from loguru import logger
|
|
||||||
|
|
||||||
|
|
||||||
class OpenNodeWallet(Wallet):
|
class OpenNodeWallet(Wallet):
|
||||||
"""https://developers.opennode.com/"""
|
"""https://developers.opennode.com/"""
|
||||||
|
@ -142,17 +140,19 @@ class OpenNodeWallet(Wallet):
|
||||||
value = await self.queue.get()
|
value = await self.queue.get()
|
||||||
yield value
|
yield value
|
||||||
|
|
||||||
# async def webhook_listener(self):
|
async def webhook_listener(self):
|
||||||
# data = await request.form
|
# TODO: request.form is undefined, was it something with Flask or quart?
|
||||||
# if "status" not in data or data["status"] != "paid":
|
# probably issue introduced when refactoring?
|
||||||
# raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
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"]
|
charge_id = data["id"]
|
||||||
# x = hmac.new(self.auth["Authorization"].encode("ascii"), digestmod="sha256")
|
x = hmac.new(self.auth["Authorization"].encode("ascii"), digestmod="sha256")
|
||||||
# x.update(charge_id.encode("ascii"))
|
x.update(charge_id.encode("ascii"))
|
||||||
# if x.hexdigest() != data["hashed_order"]:
|
if x.hexdigest() != data["hashed_order"]:
|
||||||
# logger.error("invalid webhook, not from opennode")
|
logger.error("invalid webhook, not from opennode")
|
||||||
# raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
||||||
|
|
||||||
# await self.queue.put(charge_id)
|
await self.queue.put(charge_id)
|
||||||
# raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
||||||
|
|
Loading…
Add table
Reference in a new issue