Browse Source

fix: get correct LND payment_hash

fee_issues
Eneko Illarramendi 5 years ago
parent
commit
6d019bcb2b
  1. 11
      lnbits/wallets/lnd.py
  2. 10
      lnbits/wallets/lntxbot.py

11
lnbits/wallets/lnd.py

@ -15,12 +15,13 @@ class LndWallet(Wallet):
r = post(
url=f"{self.endpoint}/v1/invoices",
headers=self.auth_admin,
json={"value": f"{amount}", "description_hash": memo}, # , "private": True},
json={"value": f"{amount}", "description_hash": memo, "private": True},
)
if r.ok:
data = r.json()
payment_hash, payment_request = data["r_hash"], data["payment_request"]
payment_request = r.json()["payment_request"]
decoded = get(url=f"{self.endpoint}/v1/payreq/{payment_request}", headers=self.auth_admin)
payment_hash, payment_request = decoded.json()["payment_hash"], payment_request
return InvoiceResponse(r, payment_hash, payment_request)
@ -28,9 +29,9 @@ class LndWallet(Wallet):
raise NotImplementedError
def get_invoice_status(self, payment_hash: str, wait: bool = True) -> TxStatus:
r = get(url=f"{self.endpoint}/v1/invoice", headers=self.auth_admin, params={"r_hash": payment_hash})
r = get(url=f"{self.endpoint}/v1/invoice/{payment_hash}", headers=self.auth_admin)
if not r.ok:
if not r.ok or "settled" not in r.json():
return TxStatus(r, None)
return TxStatus(r, r.json()["settled"])

10
lnbits/wallets/lntxbot.py

@ -27,11 +27,12 @@ class LntxbotWallet(Wallet):
def get_invoice_status(self, payment_hash: str, wait: bool = True) -> TxStatus:
wait = "true" if wait else "false"
r = post(url=f"{self.endpoint}/invoicestatus/{payment_hash}?wait={wait}", headers=self.auth_invoice)
data = r.json()
if not r.ok or "error" in data:
if not r.ok or "error" in r.json():
return TxStatus(r, None)
data = r.json()
if "preimage" not in data or not data["preimage"]:
return TxStatus(r, False)
@ -39,9 +40,8 @@ class LntxbotWallet(Wallet):
def get_payment_status(self, payment_hash: str) -> TxStatus:
r = post(url=f"{self.endpoint}/paymentstatus/{payment_hash}", headers=self.auth_invoice)
data = r.json()
if not r.ok or "error" in data:
if not r.ok or "error" in r.json():
return TxStatus(r, None)
return TxStatus(r, {"complete": True, "failed": False, "unknown": None}[data.get("status", "unknown")])
return TxStatus(r, {"complete": True, "failed": False, "unknown": None}[r.json().get("status", "unknown")])

Loading…
Cancel
Save