mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-03-15 12:20:21 +01:00
Update lntxbot.py
This commit is contained in:
parent
364ab472d2
commit
4c8b9c322b
1 changed files with 19 additions and 11 deletions
|
@ -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)
|
||||||
|
|
||||||
if not r.ok or "error" in r.json():
|
|
||||||
return TxStatus(r, None)
|
|
||||||
|
|
||||||
data = r.json()
|
data = r.json()
|
||||||
|
|
||||||
|
if not r.ok or "error" in data:
|
||||||
|
return TxStatus(r, None)
|
||||||
|
|
||||||
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…
Add table
Reference in a new issue