remove hold invoices stream

should be same as paid invoices
This commit is contained in:
dni ⚡
2025-07-09 15:04:10 +02:00
parent 12f2b267ae
commit f69c558ae3
3 changed files with 0 additions and 66 deletions

View File

@@ -159,11 +159,6 @@ class Wallet(ABC):
async def cancel_hold_invoice(self, payment_hash: str) -> InvoiceResponse:
raise UnsupportedError()
def hold_invoices_stream(
self, payment_hash: str, webhook: str
) -> AsyncGenerator[str, None]:
raise UnsupportedError()
async def paid_invoices_stream(self) -> AsyncGenerator[str, None]:
while settings.lnbits_running:
for invoice in self.pending_invoices:

View File

@@ -6,7 +6,6 @@ from os import environ
from typing import Optional
import grpc
import httpx
from loguru import logger
import lnbits.wallets.lnd_grpc_files.invoices_pb2 as invoices
@@ -363,23 +362,3 @@ class LndWallet(Wallet):
)
# If we reach here, the invoice was successfully canceled
return InvoiceResponse(True, checking_id=payment_hash)
async def hold_invoices_stream(
self, payment_hash: str, webhook: str
) -> AsyncGenerator[str, None]:
rhash = base64.urlsafe_b64encode(bytes.fromhex(payment_hash))
request = invoicesrpc.SubscribeSingleInvoiceRequest(r_hash=rhash) # type: ignore
async for response in self.invoicesrpc.SubscribeSingleInvoice(request):
if response.state not in ["ACCEPTED", "CANCELED"]:
continue
logger.debug(
f"Hold invoice state changed: {response.state}, "
f"payment_hash: {payment_hash}"
)
async with httpx.AsyncClient() as client:
try:
logger.debug("sending hold webhook", webhook, str(response))
await client.post(webhook, json=response, timeout=10)
except (httpx.ConnectError, httpx.RequestError):
logger.debug("error sending hold webhook")
yield payment_hash

View File

@@ -383,43 +383,3 @@ class LndRestWallet(Wallet):
return InvoiceResponse(ok=True, checking_id=payment_hash)
except httpx.HTTPStatusError as exc:
return InvoiceResponse(ok=False, error_message=exc.response.text)
async def hold_invoices_stream(
self, payment_hash: str, webhook: str
) -> AsyncGenerator[str, None]:
try:
print(webhook)
rhash_hex = bytes.fromhex(payment_hash)
rhash = base64.urlsafe_b64encode(rhash_hex)
url = f"{self.endpoint}/v2/invoices/subscribe/{rhash.decode()}"
async with self.client.stream("GET", url, timeout=None) as r:
async for line in r.aiter_lines():
try:
inv = json.loads(line)["result"]
if inv["state"] not in ["ACCEPTED", "CANCELED"]:
continue
except Exception as exc:
logger.debug(exc)
continue
# dispatch webhook
inv["payment_hash"] = payment_hash
yield payment_hash
# await LndRestWallet.dispatch_hold_webhook(webhook, inv)
except Exception as exc:
logger.error(
f"""
lost connection to lnd hold invoices stream: '{exc}',
retrying in 5 seconds
"""
)
await asyncio.sleep(5)
# async def dispatch_hold_webhook(self, webhook, inv):
# async with httpx.AsyncClient() as client:
# try:
# logger.debug("sending hold webhook", webhook, str(inv))
# await client.post(webhook, json=inv, timeout=40) # type: ignore
# except (httpx.ConnectError, httpx.RequestError):
# logger.debug("error sending hold webhook")