lndrest: account for when there are pending checking_ids from other sources.

This commit is contained in:
fiatjaf 2020-10-05 22:16:28 -03:00
parent 5ead82f57c
commit bb965e4119

View File

@ -37,12 +37,7 @@ class LndRestWallet(Wallet):
else: else:
data["memo"] = memo or "" data["memo"] = memo or ""
r = httpx.post( r = httpx.post(url=f"{self.endpoint}/v1/invoices", headers=self.auth_invoice, verify=self.auth_cert, json=data,)
url=f"{self.endpoint}/v1/invoices",
headers=self.auth_invoice,
verify=self.auth_cert,
json=data,
)
if r.is_error: if r.is_error:
error_message = r.text error_message = r.text
@ -83,11 +78,12 @@ class LndRestWallet(Wallet):
def get_invoice_status(self, checking_id: str) -> PaymentStatus: def get_invoice_status(self, checking_id: str) -> PaymentStatus:
checking_id = checking_id.replace("_", "/") checking_id = checking_id.replace("_", "/")
r = httpx.get( r = httpx.get(
url=f"{self.endpoint}/v1/invoice/{checking_id}", url=f"{self.endpoint}/v1/invoice/{checking_id}", headers=self.auth_invoice, verify=self.auth_cert,
headers=self.auth_invoice,
verify=self.auth_cert,
) )
if not r or r.json()["settled"] == False:
if not r or not r.json().get("settled"):
# this must also work when checking_id is not a hex recognizable by lnd
# it will return an error and no "settled" attribute on the object
return PaymentStatus(None) return PaymentStatus(None)
return PaymentStatus(r.json()["settled"]) return PaymentStatus(r.json()["settled"])