Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async onBeforeConnect() {
// Establish a connection.
const { useMacaroon, waitForMacaroon } = this._getConnectionSettings()
await this.establishConnection({ useMacaroon, waitForMacaroon })
// Once connected, make a call to getInfo in order to determine the api version.
const info = await this.getInfo()
grpcLog.info('Connected to Lightning gRPC:', info)
// Determine most relevant proto version and reconnect using the right rpc.proto if we need to.
const { protoPath } = this.lndConfig
const [closestProtoVersion, latestProtoVersion] = await Promise.all([
lndgrpc.getClosestProtoVersion(info.version, { path: protoPath }),
lndgrpc.getLatestProtoVersion({ path: protoPath }),
])
if (closestProtoVersion !== latestProtoVersion) {
grpcLog.info(
'Found better match. Reconnecting using rpc.proto version: %s',
closestProtoVersion
)
this.service.close()
await this.establishConnection({
version: closestProtoVersion,
useMacaroon,
waitForMacaroon,
})
}
}