fix: description_hash as an optional param to create_invoice.

fixes https://github.com/lnbits/lnbits/issues/74
This commit is contained in:
fiatjaf
2020-08-30 23:54:50 -03:00
parent 660d56d400
commit 68b0adfe66
11 changed files with 77 additions and 50 deletions
+11 -6
View File
@@ -1,4 +1,5 @@
from os import getenv
from typing import Optional, Dict
from requests import post
from .base import InvoiceResponse, PaymentResponse, PaymentStatus, Wallet
@@ -13,12 +14,16 @@ class LntxbotWallet(Wallet):
self.auth_admin = {"Authorization": f"Basic {getenv('LNTXBOT_ADMIN_KEY')}"}
self.auth_invoice = {"Authorization": f"Basic {getenv('LNTXBOT_INVOICE_KEY')}"}
def create_invoice(self, amount: int, memo: str = "", description_hash: bytes = b"") -> InvoiceResponse:
r = post(
url=f"{self.endpoint}/addinvoice",
headers=self.auth_invoice,
json={"amt": str(amount), "memo": memo, "description_hash": description_hash.hex()},
)
def create_invoice(
self, amount: int, memo: Optional[str] = None, description_hash: Optional[bytes] = None
) -> InvoiceResponse:
data: Dict = {"amt": str(amount)}
if description_hash:
data["description_hash"] = description_hash.hex()
else:
data["memo"] = memo or ""
r = post(url=f"{self.endpoint}/addinvoice", headers=self.auth_invoice, json=data,)
ok, checking_id, payment_request, error_message = r.ok, None, None, None
if r.ok: