Skip to content

Commit

Permalink
allow tlsCert to be undefined if Loop is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
openoms committed Oct 27, 2022
1 parent 653cf88 commit d4dfe0f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
21 changes: 12 additions & 9 deletions src/config/process.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getCronConfig } from "@config"

import { ConfigError } from "./error"
import { getCronConfig} from "@config"

type TwilioConfig = {
accountSid: string
Expand Down Expand Up @@ -103,20 +104,22 @@ export const LND_HEALTH_REFRESH_TIME_MS = parseInt(
10,
)

export const getLoopConfig = getCronConfig().swapEnabled ? () => {
if (!process.env.LND1_LOOP_TLS) throw new ConfigError("Missing LND1_LOOP_TLS config")
if (!process.env.LND2_LOOP_TLS) throw new ConfigError("Missing LND2_LOOP_TLS config")
if (!process.env.LND1_LOOP_MACAROON)
throw new ConfigError("Missing LND1_LOOP_MACAROON config")
if (!process.env.LND2_LOOP_MACAROON)
throw new ConfigError("Missing LND2_LOOP_MACAROON config")
export const getLoopConfig = () => {
if (getCronConfig().swapEnabled) {
if (!process.env.LND1_LOOP_TLS) throw new ConfigError("Missing LND1_LOOP_TLS config")
if (!process.env.LND2_LOOP_TLS) throw new ConfigError("Missing LND2_LOOP_TLS config")
if (!process.env.LND1_LOOP_MACAROON)
throw new ConfigError("Missing LND1_LOOP_MACAROON config")
if (!process.env.LND2_LOOP_MACAROON)
throw new ConfigError("Missing LND2_LOOP_MACAROON config")
}
return {
lnd1LoopTls: process.env.LND1_LOOP_TLS,
lnd1LoopMacaroon: process.env.LND1_LOOP_MACAROON as Macaroon,
lnd2LoopTls: process.env.LND2_LOOP_TLS,
lnd2LoopMacaroon: process.env.LND2_LOOP_MACAROON as Macaroon,
}
} : null
}

export const getKratosMasterPhonePassword = () => {
if (!process.env.KRATOS_MASTER_PHONE_PASSWORD) {
Expand Down
2 changes: 1 addition & 1 deletion src/domain/swap/index.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type SwapConfig = {

type LoopdConfig = {
macaroon: Macaroon
tlsCert: string
tlsCert?: string
grpcEndpoint: string
btcNetwork: BtcNetwork
lndInstanceName: string
Expand Down
5 changes: 5 additions & 0 deletions src/services/loopd/loop-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import {
OutTermsResponse,
} from "./protos/loop_pb"

import { ConfigError } from "src/config/error"

export const LoopService = ({
macaroon,
tlsCert,
Expand All @@ -41,6 +43,9 @@ export const LoopService = ({
lndInstanceName,
}: LoopdConfig): ISwapService => {
const mac = Buffer.from(macaroon, "base64").toString("hex") as Macaroon
if (!tlsCert) {
throw new ConfigError("missing LOOP_TLS")
}
const tls = Buffer.from(tlsCert, "base64")
const swapClient: ServiceClient = createClient(mac, tls, grpcEndpoint)

Expand Down

0 comments on commit d4dfe0f

Please sign in to comment.