mirror of
https://github.com/lnbits/lnbits.git
synced 2025-03-30 04:32:01 +02:00
Update clightning.py
This commit is contained in:
parent
0ca5586465
commit
377b0c9d47
@ -7,28 +7,29 @@ import random
|
|||||||
class CLightningWallet(Wallet):
|
class CLightningWallet(Wallet):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
l1 = LightningRpc(getenv("CLIGHTNING_RPC"))
|
self.l1 = LightningRpc(getenv("CLIGHTNING_RPC"))
|
||||||
|
|
||||||
def create_invoice(self, amount: int, memo: str = "") -> InvoiceResponse:
|
def create_invoice(self, amount: int, memo: str = "") -> InvoiceResponse:
|
||||||
|
print(self.l1)
|
||||||
label = "lbl{}".format(random.random())
|
label = "lbl{}".format(random.random())
|
||||||
r = l1.invoice(amount*1000, label, memo, exposeprivatechannels=True)
|
r = self.l1.invoice(amount*1000, label, memo, exposeprivatechannels=True)
|
||||||
print(r)
|
print(r)
|
||||||
ok, checking_id, payment_request, error_message = True, r["payment_hash"], r["bolt11"], None
|
ok, checking_id, payment_request, error_message = True, r["payment_hash"], r["bolt11"], None
|
||||||
return InvoiceResponse(ok, checking_id, payment_request, error_message)
|
return InvoiceResponse(ok, checking_id, payment_request, error_message)
|
||||||
|
|
||||||
def pay_invoice(self, bolt11: str) -> PaymentResponse:
|
def pay_invoice(self, bolt11: str) -> PaymentResponse:
|
||||||
r = l1.pay(bolt11)
|
r = self.l1.pay(bolt11)
|
||||||
ok, checking_id, fee_msat, error_message = True, None, None, None
|
ok, checking_id, fee_msat, error_message = True, None, None, None
|
||||||
return PaymentResponse(ok, checking_id, fee_msat, error_message)
|
return PaymentResponse(ok, checking_id, fee_msat, error_message)
|
||||||
|
|
||||||
def get_invoice_status(self, checking_id: str) -> PaymentStatus:
|
def get_invoice_status(self, checking_id: str) -> PaymentStatus:
|
||||||
r = l1.listinvoices(checking_id)
|
r = self.l1.listinvoices(checking_id)
|
||||||
if r['invoices'][0]['status'] == 'unpaid':
|
if r['invoices'][0]['status'] == 'unpaid':
|
||||||
return PaymentStatus(False)
|
return PaymentStatus(False)
|
||||||
return PaymentStatus(True)
|
return PaymentStatus(True)
|
||||||
|
|
||||||
def get_payment_status(self, checking_id: str) -> PaymentStatus:
|
def get_payment_status(self, checking_id: str) -> PaymentStatus:
|
||||||
r = l1.listsendpays(checking_id)
|
r = self.l1.listsendpays(checking_id)
|
||||||
if not r.ok:
|
if not r.ok:
|
||||||
return PaymentStatus(r, None)
|
return PaymentStatus(r, None)
|
||||||
payments = [p for p in r.json()["payments"] if p["payment_hash"] == payment_hash]
|
payments = [p for p in r.json()["payments"] if p["payment_hash"] == payment_hash]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user