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
+8 -4
View File
@@ -28,12 +28,16 @@ class UnknownError(Exception):
class SparkWallet(Wallet):
def __init__(self):
assert settings.spark_url, "spark url does not exist"
self.url = settings.spark_url.replace("/rpc", "")
if not settings.spark_url:
raise ValueError("cannot initialize SparkWallet: missing spark_url")
if not settings.spark_token:
raise ValueError("cannot initialize SparkWallet: missing spark_token")
url = settings.spark_url.replace("/rpc", "")
self.token = settings.spark_token
assert self.token, "spark wallet token does not exist"
headers = {"X-Access": self.token, "User-Agent": settings.user_agent}
self.client = httpx.AsyncClient(base_url=self.url, headers=headers)
self.client = httpx.AsyncClient(base_url=url, headers=headers)
async def cleanup(self):
try: