[Wallets] CLN: fix pending state check (#1770)

* better checking

* flake8 fix

* make format

* invoices scope are function for tests

* invoice back to sessionbut keep real_invoice for now

* make format

* comment

* get payment by checking id and test
This commit is contained in:
callebtc
2023-07-24 12:00:41 +02:00
committed by GitHub
parent f478c1848a
commit 11fec7a889
3 changed files with 135 additions and 6 deletions
+10 -5
View File
@@ -161,15 +161,18 @@ class CoreLightningWallet(Wallet):
return PaymentStatus(True)
elif invoice_resp["status"] == "unpaid":
return PaymentStatus(None)
logger.warning(f"supplied an invalid checking_id: {checking_id}")
elif invoice_resp["status"] == "expired":
return PaymentStatus(False)
else:
logger.warning(f"supplied an invalid checking_id: {checking_id}")
return PaymentStatus(None)
async def get_payment_status(self, checking_id: str) -> PaymentStatus:
try:
r = self.ln.call("listpays", {"payment_hash": checking_id})
r = self.ln.listpays(payment_hash=checking_id)
except:
return PaymentStatus(None)
if not r["pays"]:
if "pays" not in r or not r["pays"]:
return PaymentStatus(None)
payment_resp = r["pays"][-1]
@@ -183,8 +186,10 @@ class CoreLightningWallet(Wallet):
return PaymentStatus(True, fee_msat, payment_resp["preimage"])
elif status == "failed":
return PaymentStatus(False)
return PaymentStatus(None)
logger.warning(f"supplied an invalid checking_id: {checking_id}")
else:
return PaymentStatus(None)
else:
logger.warning(f"supplied an invalid checking_id: {checking_id}")
return PaymentStatus(None)
async def paid_invoices_stream(self) -> AsyncGenerator[str, None]: