Update to c-lightning-REST v0.10.5 (#2109)

* Update to c-lightning-REST v0.10.5
* update invoice stream
This commit is contained in:
callebtc
2023-11-18 08:14:29 -03:00
committed by GitHub
parent d5ae1e3d6a
commit 4dcf26bcb3

View File

@ -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(