diff --git a/lib/BaseClient.ts b/lib/BaseClient.ts index 7ed9f3f46..f882db81c 100644 --- a/lib/BaseClient.ts +++ b/lib/BaseClient.ts @@ -2,6 +2,7 @@ import Logger from './Logger'; import { EventEmitter } from 'events'; enum ClientStatus { + NotInitialized, Disabled, Disconnected, ConnectionVerified, @@ -12,7 +13,7 @@ enum ClientStatus { * A base class to represent a client for an external service such as LND or Raiden. */ abstract class BaseClient extends EventEmitter { - protected status: ClientStatus = ClientStatus.Disabled; + protected status: ClientStatus = ClientStatus.NotInitialized; constructor(protected logger: Logger) { super(); diff --git a/lib/Xud.ts b/lib/Xud.ts index 471d3d991..4edcab8e4 100644 --- a/lib/Xud.ts +++ b/lib/Xud.ts @@ -70,15 +70,11 @@ class Xud extends EventEmitter { this.db = new DB(loggers.db, this.config.dbpath); await this.db.init(this.config.initdb); - // setup LND clients and connect if configured + // setup LND clients and initialize this.lndbtcClient = new LndClient(this.config.lndbtc, loggers.lnd); - if (!this.lndbtcClient.isDisabled()) { - initPromises.push(this.lndbtcClient.init()); - } + initPromises.push(this.lndbtcClient.init()); this.lndltcClient = new LndClient(this.config.lndltc, loggers.lnd); - if (!this.lndltcClient.isDisabled()) { - initPromises.push(this.lndltcClient.init()); - } + initPromises.push(this.lndltcClient.init()); // setup raiden client and connect if configured this.raidenClient = new RaidenClient(this.config.raiden, loggers.raiden); diff --git a/lib/lndclient/LndClient.ts b/lib/lndclient/LndClient.ts index 3a4883b47..21db22767 100644 --- a/lib/lndclient/LndClient.ts +++ b/lib/lndclient/LndClient.ts @@ -72,37 +72,36 @@ class LndClient extends BaseClient { /** Initializes the client for calls to lnd and verifies that we can connect to it. */ public init = async () => { - let shouldEnable = true; const { disable, certpath, macaroonpath, nomacaroons, host, port } = this.config; + let shouldDisable = disable; - if (disable) { - shouldEnable = false; - } if (!(await exists(certpath))) { this.logger.error('could not find lnd certificate, is lnd installed?'); - shouldEnable = false; + shouldDisable = true; } if (!nomacaroons && !(await exists(macaroonpath))) { this.logger.error('could not find lnd macaroon, is lnd installed?'); - shouldEnable = false; + shouldDisable = true; } - if (shouldEnable) { - assert(this.cltvDelta > 0, 'cltvdelta must be a positive number'); - this.uri = `${host}:${port}`; - const lndCert = await readFile(certpath); - this.credentials = grpc.credentials.createSsl(lndCert); - - this.meta = new grpc.Metadata(); - if (!nomacaroons) { - const adminMacaroon = await readFile(macaroonpath); - this.meta.add('macaroon', adminMacaroon.toString('hex')); - } else { - this.logger.info(`macaroons are disabled for lnd at ${this.uri}`); - } - // set status as disconnected until we can verify the connection - this.setStatus(ClientStatus.Disconnected); - await this.verifyConnection(); + if (shouldDisable) { + return; + } + + assert(this.cltvDelta > 0, 'cltvdelta must be a positive number'); + this.uri = `${host}:${port}`; + const lndCert = await readFile(certpath); + this.credentials = grpc.credentials.createSsl(lndCert); + + this.meta = new grpc.Metadata(); + if (!nomacaroons) { + const adminMacaroon = await readFile(macaroonpath); + this.meta.add('macaroon', adminMacaroon.toString('hex')); + } else { + this.logger.info(`macaroons are disabled for lnd at ${this.uri}`); } + // set status as disconnected until we can verify the connection + this.setStatus(ClientStatus.Disconnected); + return this.verifyConnection(); } public get pubKey() { diff --git a/lib/raidenclient/RaidenClient.ts b/lib/raidenclient/RaidenClient.ts index b01239211..cd71bc271 100644 --- a/lib/raidenclient/RaidenClient.ts +++ b/lib/raidenclient/RaidenClient.ts @@ -112,8 +112,8 @@ class RaidenClient extends BaseClient { this.port = port; this.host = host; - if (!disable) { - this.setStatus(ClientStatus.Disconnected); + if (disable) { + this.setStatus(ClientStatus.Disabled); } }