From 4dcf26bcb30eeafb97157a1917d45997ba2a84c9 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sat, 18 Nov 2023 08:14:29 -0300 Subject: [PATCH] Update to c-lightning-REST v0.10.5 (#2109) * Update to c-lightning-REST v0.10.5 * update invoice stream --- lnbits/wallets/corelightningrest.py | 42 +++++++++++++---------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/lnbits/wallets/corelightningrest.py b/lnbits/wallets/corelightningrest.py index f60ab2243..316d21b6a 100644 --- a/lnbits/wallets/corelightningrest.py +++ b/lnbits/wallets/corelightningrest.py @@ -125,9 +125,7 @@ class CoreLightningRestWallet(Wallet): data = r.json() assert "payment_hash" in data assert "bolt11" in data - # NOTE: use payment_hash when corelightning-rest updates and supports it - # return InvoiceResponse(True, data["payment_hash"], data["bolt11"], None) - return InvoiceResponse(True, label, data["bolt11"], None) + return InvoiceResponse(True, data["payment_hash"], data["bolt11"], None) async def pay_invoice(self, bolt11: str, fee_limit_msat: int) -> PaymentResponse: try: @@ -172,13 +170,9 @@ class CoreLightningRestWallet(Wallet): ) async def get_invoice_status(self, checking_id: str) -> PaymentStatus: - # get invoice bolt11 from checking_id - # corelightning-rest wants the "label" here.... - # NOTE: We can get rid of all labels and use payment_hash when - # corelightning-rest updates and supports it r = await self.client.get( f"{self.url}/v1/invoice/listInvoices", - params={"label": checking_id}, + params={"payment_hash": checking_id}, ) try: r.raise_for_status() @@ -192,14 +186,9 @@ class CoreLightningRestWallet(Wallet): return PaymentStatus(None) async def get_payment_status(self, checking_id: str) -> PaymentStatus: - from lnbits.core.services import get_standalone_payment - - payment = await get_standalone_payment(checking_id) - if not payment: - raise ValueError(f"Payment with checking_id {checking_id} not found") r = await self.client.get( f"{self.url}/v1/pay/listPays", - params={"invoice": payment.bolt11}, + params={"payment_hash": checking_id}, ) try: r.raise_for_status() @@ -241,19 +230,24 @@ class CoreLightningRestWallet(Wallet): except Exception: continue logger.trace(f"paid invoice: {inv}") - yield inv["label"] - # NOTE: use payment_hash when corelightning-rest updates - # and supports it + + # NOTE: use payment_hash when corelightning-rest returns it + # when using waitAnyInvoice # payment_hash = inv["payment_hash"] # yield payment_hash # hack to return payment_hash if the above shouldn't work - # r = await self.client.get( - # f"{self.url}/v1/invoice/listInvoices", - # params={"label": inv["label"]}, - # ) - # paid_invoce = r.json() - # logger.trace(f"paid invoice: {paid_invoce}") - # yield paid_invoce["invoices"][0]["payment_hash"] + r = await self.client.get( + f"{self.url}/v1/invoice/listInvoices", + params={"label": inv["label"]}, + ) + paid_invoice = r.json() + logger.trace(f"paid invoice: {paid_invoice}") + assert self.statuses[ + paid_invoice["invoices"][0]["status"] + ], "streamed invoice not paid" + assert "invoices" in paid_invoice, "no invoices in response" + assert len(paid_invoice["invoices"]), "no invoices in response" + yield paid_invoice["invoices"][0]["payment_hash"] except Exception as exc: logger.debug(