Browse Source

Update lntxbot.py

fee_issues
Arc 5 years ago
committed by GitHub
parent
commit
4c8b9c322b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      lnbits/wallets/lntxbot.py

28
lnbits/wallets/lntxbot.py

@ -1,6 +1,7 @@
from requests import Response, post from requests import Response, get, post
from flask import jsonify
from .base import InvoiceResponse, TxStatus, Wallet from .base import InvoiceResponse, TxStatus, Wallet, PaymentResponse
import json
class LntxbotWallet(Wallet): class LntxbotWallet(Wallet):
@ -21,27 +22,34 @@ class LntxbotWallet(Wallet):
return InvoiceResponse(r, payment_hash, payment_request) return InvoiceResponse(r, payment_hash, payment_request)
def pay_invoice(self, bolt11: str) -> Response: def pay_invoice(self, bolt11: str) -> PaymentResponse:
return post(url=f"{self.endpoint}/payinvoice", headers=self.auth_admin, json={"invoice": bolt11}) fee_msat = None
r = post(url=f"{self.endpoint}/payinvoice", headers=self.auth_admin, json={"invoice": bolt11})
return PaymentResponse(r)
def get_invoice_status(self, payment_hash: str, wait: bool = True) -> TxStatus: def get_invoice_status(self, payment_hash: str, wait: bool = True) -> TxStatus:
wait = "true" if wait else "false" wait = "true" if wait else "false"
r = post(url=f"{self.endpoint}/invoicestatus/{payment_hash}?wait={wait}", headers=self.auth_invoice) 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 r.json(): if not r.ok or "error" in data:
return TxStatus(r, None) return TxStatus(r, None)
data = r.json()
if "preimage" not in data or not data["preimage"]: if "preimage" not in data or not data["preimage"]:
return TxStatus(r, False) return TxStatus(r, False)
return TxStatus(r, True) return TxStatus(r, True)
def get_payment_status(self, payment_hash: str) -> TxStatus: def get_payment_status(self, payment_hash: str) -> TxStatus:
r = post(url=f"{self.endpoint}/paymentstatus/{payment_hash}", headers=self.auth_invoice) r = post(url=f"{self.endpoint}/paymentstatus/{payment_hash}", headers=self.auth_invoice)
data = r.json()
if not r.ok or "error" in r.json(): if not r.ok or "error" in data:
return TxStatus(r, None) return TxStatus(r, None)
return TxStatus(r, {"complete": True, "failed": False, "unknown": None}[r.json().get("status", "unknown")]) return TxStatus(r, {"complete": True, "failed": False, "unknown": None}[data.get("status", "unknown")])

Loading…
Cancel
Save