refactor __init__ functions of Wallets (funding sources)

- better error messages when a conf variable is not provided
- unify approaches among different source files
This commit is contained in:
Pavol Rusnak
2024-01-22 10:06:22 -06:00
parent a3b7c76523
commit 824a8fa7c8
12 changed files with 131 additions and 69 deletions
+9 -3
View File
@@ -20,14 +20,20 @@ class LNbitsWallet(Wallet):
"""https://github.com/lnbits/lnbits"""
def __init__(self):
self.endpoint = settings.lnbits_endpoint
if not settings.lnbits_endpoint:
raise ValueError("cannot initialize LNbitsWallet: missing lnbits_endpoint")
key = (
settings.lnbits_key
or settings.lnbits_admin_key
or settings.lnbits_invoice_key
)
if not self.endpoint or not key:
raise Exception("cannot initialize lnbits wallet")
if not key:
raise ValueError(
"cannot initialize LNbitsWallet: "
"missing lnbits_key or lnbits_admin_key or lnbits_invoice_key"
)
endpoint = settings.lnbits_endpoint
self.endpoint = endpoint[:-1] if endpoint.endswith("/") else endpoint
self.headers = {"X-Api-Key": key, "User-Agent": settings.user_agent}
self.client = httpx.AsyncClient(base_url=self.endpoint, headers=self.headers)