diff --git a/lnbits/wallets/base.py b/lnbits/wallets/base.py index 43fa8eb09..38bfc0e2f 100644 --- a/lnbits/wallets/base.py +++ b/lnbits/wallets/base.py @@ -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: diff --git a/lnbits/wallets/lndgrpc.py b/lnbits/wallets/lndgrpc.py index cc8054eb2..4730eb623 100644 --- a/lnbits/wallets/lndgrpc.py +++ b/lnbits/wallets/lndgrpc.py @@ -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 diff --git a/lnbits/wallets/lndrest.py b/lnbits/wallets/lndrest.py index 3a9badc3b..d86a0ac1a 100644 --- a/lnbits/wallets/lndrest.py +++ b/lnbits/wallets/lndrest.py @@ -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")