How to use the lnd-grpc.getLatestProtoVersion function in lnd-grpc

To help you get started, we’ve selected a few lnd-grpc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LN-Zap / zap-desktop / services / grpc / lightning / lightning.js View on Github external
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,
      })
    }
  }
github LN-Zap / zap-desktop / services / grpc / grpcService.js View on Github external
async establishConnection(options = {}) {
    const { version, useMacaroon, waitForMacaroon } = options
    const { host, cert, macaroon, protoPath } = this.lndConfig

    // Find the most recent rpc.proto file
    const versionToUse = version || (await lndgrpc.getLatestProtoVersion({ path: protoPath }))
    const filepath = join(protoPath, `${versionToUse}.proto`)
    grpcLog.info(`Establishing gRPC connection to ${this.serviceName} with proto file %s`, filepath)

    // Load gRPC package definition as a gRPC object hierarchy.
    const packageDefinition = await load(filepath, grpcOptions)
    const rpc = loadPackageDefinition(packageDefinition)

    // Create ssl credentials to use with the gRPC client.
    let creds = await createSslCreds(cert)

    // Add macaroon to crenentials if service requires macaroons.
    if (useMacaroon) {
      // If we are trying to connect to the internal lnd, wait up to 20 seconds for the macaroon to be generated.
      if (waitForMacaroon) {
        await waitForFile(macaroon, 20000)
      }
github LN-Zap / zap-desktop / app / lib / lnd / walletUnlocker.js View on Github external
async establishConnection() {
    const { host, cert } = this.lndConfig

    // Find the most recent rpc.proto file
    const version = await lndgrpc.getLatestProtoVersion({ path: lndGpcProtoPath() })
    const filepath = join(lndGpcProtoPath(), `${version}.proto`)
    mainLog.debug('Establishing gRPC connection with proto file %s', filepath)

    // Load gRPC package definition as a gRPC object hierarchy.
    const packageDefinition = await load(filepath, grpcOptions)
    const rpc = loadPackageDefinition(packageDefinition)

    // Create ssl credentials to use with the gRPC client.
    const sslCreds = await createSslCreds(cert)

    // Create a new gRPC client instance.
    this.service = new rpc.lnrpc.WalletUnlocker(host, sslCreds)

    // Wait upto 20 seconds for the gRPC connection to be established.
    return new Promise((resolve, reject) => {
      this.service.waitForReady(getDeadline(20), err => {

lnd-grpc

Repository of lnd rpc protocol files and utilities for working with them

MIT
Latest version published 1 year ago

Package Health Score

39 / 100
Full package analysis