From 067ba386688292ef1dc1163ce1103da47127f250 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Thu, 25 May 2023 04:19:45 -0700 Subject: [PATCH] Fix exceptions for no CLN nodes --- api/lightning/cln.py | 9 +++++---- api/lightning/node.py | 8 ++++---- api/utils.py | 17 +++++++++++------ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/api/lightning/cln.py b/api/lightning/cln.py index 70d398c5..564fb1f2 100755 --- a/api/lightning/cln.py +++ b/api/lightning/cln.py @@ -19,17 +19,18 @@ from . import primitives_pb2 as primitives__pb2 ####### # Load the client's certificate and key -with open(os.path.join(config("CLN_DIR"), "client.pem"), "rb") as f: +CLN_DIR = config("CLN_DIR", cast=str, default="/cln/testnet/") +with open(os.path.join(CLN_DIR, "client.pem"), "rb") as f: client_cert = f.read() -with open(os.path.join(config("CLN_DIR"), "client-key.pem"), "rb") as f: +with open(os.path.join(CLN_DIR, "client-key.pem"), "rb") as f: client_key = f.read() # Load the server's certificate -with open(os.path.join(config("CLN_DIR"), "server.pem"), "rb") as f: +with open(os.path.join(CLN_DIR, "server.pem"), "rb") as f: server_cert = f.read() -CLN_GRPC_HOST = config("CLN_GRPC_HOST") +CLN_GRPC_HOST = config("CLN_GRPC_HOST", cast=str, default="localhost:9999") DISABLE_ONCHAIN = config("DISABLE_ONCHAIN", cast=bool, default=True) MAX_SWAP_AMOUNT = config("MAX_SWAP_AMOUNT", cast=int, default=500000) diff --git a/api/lightning/node.py b/api/lightning/node.py index c8af6010..5a71105c 100644 --- a/api/lightning/node.py +++ b/api/lightning/node.py @@ -1,16 +1,16 @@ from decouple import config -LN_vendor = config("LNVENDOR", cast=str, default="LND") +LNVENDOR = config("LNVENDOR", cast=str, default="LND") -if LN_vendor == "LND": +if LNVENDOR == "LND": from api.lightning.lnd import LNDNode LNNode = LNDNode -elif LN_vendor == "CLN": +elif LNVENDOR == "CLN": from api.lightning.cln import CLNNode LNNode = CLNNode else: raise ValueError( - f'Invalid Lightning Node vendor: {LN_vendor}. Must be either "LND" or "CLN"' + f'Invalid Lightning Node vendor: {LNVENDOR}. Must be either "LND" or "CLN"' ) diff --git a/api/utils.py b/api/utils.py index dc6455f8..6348e43e 100644 --- a/api/utils.py +++ b/api/utils.py @@ -14,6 +14,7 @@ logger = logging.getLogger("api.utils") TOR_PROXY = config("TOR_PROXY", default="127.0.0.1:9050") USE_TOR = config("USE_TOR", cast=bool, default=True) +LNVENDOR = config("LNVENDOR", cast=str, default="LND") def get_session(): @@ -144,10 +145,12 @@ lnd_version_cache = {} @ring.dict(lnd_version_cache, expire=3600) def get_lnd_version(): + try: + from api.lightning.lnd import LNDNode - from api.lightning.lnd import LNDNode - - return LNDNode.get_version() + return LNDNode.get_version() + except Exception: + return None cln_version_cache = {} @@ -155,10 +158,12 @@ cln_version_cache = {} @ring.dict(cln_version_cache, expire=3600) def get_cln_version(): + try: + from api.lightning.cln import CLNNode - from api.lightning.cln import CLNNode - - return CLNNode.get_version() + return CLNNode.get_version() + except Exception: + return None robosats_commit_cache = {}