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
+7 -5
View File
@@ -30,15 +30,17 @@ class UnknownError(Exception):
class EclairWallet(Wallet):
def __init__(self):
url = settings.eclair_url
passw = settings.eclair_pass
if not url or not passw:
raise Exception("cannot initialize eclair")
if not settings.eclair_url:
raise ValueError("cannot initialize EclairWallet: missing eclair_url")
if not settings.eclair_pass:
raise ValueError("cannot initialize EclairWallet: missing eclair_pass")
url = settings.eclair_url
self.url = url[:-1] if url.endswith("/") else url
self.ws_url = f"ws://{urllib.parse.urlsplit(self.url).netloc}/ws"
encodedAuth = base64.b64encode(f":{passw}".encode())
password = settings.eclair_pass
encodedAuth = base64.b64encode(f":{password}".encode())
auth = str(encodedAuth, "utf-8")
self.headers = {
"Authorization": f"Basic {auth}",