mirror of
https://github.com/lnbits/lnbits.git
synced 2025-08-02 06:52:28 +02:00
Update lndrest.py
This commit is contained in:
@@ -10,12 +10,12 @@ class LndRestWallet(Wallet):
|
||||
|
||||
def __init__(self):
|
||||
|
||||
endpoint = getenv("LND_REST_ENDPOINT") + ":" + getenv("LND_REST_PORT")
|
||||
endpoint = getenv("LND_REST_ENDPOINT")
|
||||
self.endpoint = endpoint[:-1] if endpoint.endswith("/") else endpoint
|
||||
print(self.endpoint)
|
||||
self.auth_admin = getenv("LND_REST_ADMIN_MACAROON")
|
||||
self.auth_invoice = getenv("LND_REST_INVOICE_MACAROON")
|
||||
self.auth_read = getenv("LND_REST_READ_MACAROON")
|
||||
self.auth_admin = {"Grpc-Metadata-macaroon": getenv("LND_REST_ADMIN_MACAROON")}
|
||||
self.auth_invoice = {"Grpc-Metadata-macaroon": getenv("LND_REST_INVOICE_MACAROON")}
|
||||
self.auth_read = {"Grpc-Metadata-macaroon": getenv("LND_REST_READ_MACAROON")}
|
||||
self.auth_cert = getenv("LND_REST_CERT")
|
||||
|
||||
|
||||
@@ -23,11 +23,10 @@ class LndRestWallet(Wallet):
|
||||
|
||||
r = post(
|
||||
url=f"{self.endpoint}/v1/invoices",
|
||||
headers=self.auth_admin, verify=False,
|
||||
headers=self.auth_invoice, verify=self.auth_cert,
|
||||
json={"value": amount, "memo": memo, "private": True},
|
||||
)
|
||||
print(r)
|
||||
|
||||
print(self.auth_invoice)
|
||||
|
||||
ok, checking_id, payment_request, error_message = r.ok, None, None, None
|
||||
|
||||
@@ -35,8 +34,8 @@ class LndRestWallet(Wallet):
|
||||
data = r.json()
|
||||
payment_request = data["payment_request"]
|
||||
|
||||
r = get(url=f"{self.endpoint}/v1/payreq/{payment_request}", headers=self.auth_read, verify=False,)
|
||||
|
||||
r = get(url=f"{self.endpoint}/v1/payreq/{payment_request}", headers=self.auth_read, verify=self.auth_cert,)
|
||||
print(r)
|
||||
if r.ok:
|
||||
dataa = r.json()
|
||||
checking_id = dataa["payment_hash"]
|
||||
@@ -47,7 +46,7 @@ class LndRestWallet(Wallet):
|
||||
|
||||
|
||||
def pay_invoice(self, bolt11: str) -> PaymentResponse:
|
||||
r = post(url=f"{self.endpoint}/v2/withdrawals", headers=self.auth_admin, json={"type": "ln", "address": bolt11})
|
||||
r = post(url=f"{self.endpoint}/v2/withdrawals", headers=self.auth_admin, verify=self.auth_cert, json={"type": "ln", "address": bolt11})
|
||||
ok, checking_id, fee_msat, error_message = r.ok, None, 0, None
|
||||
|
||||
if r.ok:
|
||||
@@ -60,7 +59,7 @@ class LndRestWallet(Wallet):
|
||||
|
||||
|
||||
def get_invoice_status(self, checking_id: str) -> PaymentStatus:
|
||||
r = get(url=f"{self.endpoint}/v1/charge/{checking_id}", headers=self.auth_invoice)
|
||||
r = get(url=f"{self.endpoint}/v1/charge/{checking_id}", headers=self.auth_invoice, verify=self.auth_cert)
|
||||
|
||||
if not r.ok:
|
||||
return PaymentStatus(None)
|
||||
@@ -69,10 +68,10 @@ class LndRestWallet(Wallet):
|
||||
return PaymentStatus(statuses[r.json()["data"]["status"]])
|
||||
|
||||
def get_payment_status(self, checking_id: str) -> PaymentStatus:
|
||||
r = get(url=f"{self.endpoint}/v1/withdrawal/{checking_id}", headers=self.auth_admin)
|
||||
r = get(url=f"{self.endpoint}/v1/withdrawal/{checking_id}", headers=self.auth_admin, verify=self.auth_cert)
|
||||
|
||||
if not r.ok:
|
||||
return PaymentStatus(None)
|
||||
|
||||
statuses = {0: None, 1: True, -1: False}
|
||||
return PaymentStatus(statuses[r.json()["data"]["status"]])
|
||||
return PaymentStatus(statuses[r.json()["data"]["status"]])
|
||||
|
Reference in New Issue
Block a user