From d337bf3ee2919821b2128afc5336f7557bee6ff4 Mon Sep 17 00:00:00 2001 From: softsimon Date: Tue, 21 Mar 2023 15:50:33 +0900 Subject: [PATCH] Turn off LN if Macaroon is missing --- backend/src/api/lightning/lnd/lnd-api.ts | 32 ++++++++++++------------ 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/backend/src/api/lightning/lnd/lnd-api.ts b/backend/src/api/lightning/lnd/lnd-api.ts index fb5991111..7db792178 100644 --- a/backend/src/api/lightning/lnd/lnd-api.ts +++ b/backend/src/api/lightning/lnd/lnd-api.ts @@ -10,22 +10,22 @@ class LndApi implements AbstractLightningApi { axiosConfig: AxiosRequestConfig = {}; constructor() { - if (config.LIGHTNING.ENABLED) { - try { - const macaroon = fs.readFileSync(config.LND.MACAROON_PATH).toString('hex'); - this.axiosConfig = { - headers: { - 'Grpc-Metadata-macaroon': macaroon - }, - httpsAgent: new Agent({ - ca: fs.readFileSync(config.LND.TLS_CERT_PATH) - }), - timeout: config.LND.TIMEOUT - }; - } catch (e) { - logger.err(`Could not initialize LND Macaroon/TLS Cert. Disabling LIGHTNING. ` + (e instanceof Error ? e.message : e)); - config.LIGHTNING.ENABLED = false; - } + if (!config.LIGHTNING.ENABLED) { + return; + } + try { + this.axiosConfig = { + headers: { + 'Grpc-Metadata-macaroon': fs.readFileSync(config.LND.MACAROON_PATH).toString('hex'), + }, + httpsAgent: new Agent({ + ca: fs.readFileSync(config.LND.TLS_CERT_PATH) + }), + timeout: config.LND.TIMEOUT + }; + } catch (e) { + logger.err(`Could not initialize LND Macaroon/TLS Cert. Disabling LIGHTNING. ` + (e instanceof Error ? e.message : e)); + config.LIGHTNING.ENABLED = false; } }