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
+19 -10
View File
@@ -58,7 +58,16 @@ environ["GRPC_SSL_CIPHER_SUITES"] = "HIGH+ECDSA"
class LndWallet(Wallet):
def __init__(self):
endpoint = settings.lnd_grpc_endpoint
if not settings.lnd_grpc_endpoint:
raise ValueError("cannot initialize LndWallet: missing lnd_grpc_endpoint")
if not settings.lnd_grpc_port:
raise ValueError("cannot initialize LndWallet: missing lnd_grpc_port")
cert_path = settings.lnd_grpc_cert or settings.lnd_cert
if not cert_path:
raise ValueError(
"cannot initialize LndWallet: missing lnd_grpc_cert or lnd_cert"
)
macaroon = (
settings.lnd_grpc_macaroon
@@ -67,24 +76,24 @@ class LndWallet(Wallet):
or settings.lnd_grpc_invoice_macaroon
or settings.lnd_invoice_macaroon
)
encrypted_macaroon = settings.lnd_grpc_macaroon_encrypted
if encrypted_macaroon:
macaroon = AESCipher(description="macaroon decryption").decrypt(
encrypted_macaroon
)
if not macaroon:
raise ValueError(
"cannot initialize LndWallet: "
"missing lnd_grpc_macaroon or lnd_grpc_admin_macaroon or "
"lnd_admin_macaroon or lnd_grpc_invoice_macaroon or "
"lnd_invoice_macaroon or lnd_grpc_macaroon_encrypted"
)
cert_path = settings.lnd_grpc_cert or settings.lnd_cert
if not endpoint or not macaroon or not cert_path or not settings.lnd_grpc_port:
raise Exception("cannot initialize lndrest")
endpoint = settings.lnd_grpc_endpoint
self.endpoint = endpoint[:-1] if endpoint.endswith("/") else endpoint
self.port = int(settings.lnd_grpc_port)
self.cert_path = settings.lnd_grpc_cert or settings.lnd_cert
self.macaroon = load_macaroon(macaroon)
self.cert_path = cert_path
cert = open(self.cert_path, "rb").read()
cert = open(cert_path, "rb").read()
creds = grpc.ssl_channel_credentials(cert)
auth_creds = grpc.metadata_call_credentials(self.metadata_callback)
composite_creds = grpc.composite_channel_credentials(creds, auth_creds)