How to use the grpc.waitForClientReady function in grpc

To help you get started, we’ve selected a few 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 lightninglabs / lightning-app / public / grpc-client.js View on Github external
ipcMain.on('unlockInit', async event => {
    credentials = await getCredentials(lndSettingsDir);
    protoPath = path.join(__dirname, '..', 'assets', 'rpc.proto');
    const options = {
      keepCase: false,
      longs: Number,
      enums: String,
      defaults: true,
      oneofs: true,
    };
    const packageDef = protoLoader.loadSync(protoPath, options);
    lnrpc = grpc.loadPackageDefinition(packageDef).lnrpc;
    unlocker = new lnrpc.WalletUnlocker(`localhost:${lndPort}`, credentials);
    grpc.waitForClientReady(unlocker, Infinity, err => {
      event.sender.send('unlockReady', { err });
    });
  });
github lightninglabs / lightning-app / public / grpc-client.js View on Github external
ipcMain.on('lndInit', event => {
    const macaroonCreds = getMacaroonCreds(lndSettingsDir, network);
    credentials = grpc.credentials.combineChannelCredentials(
      credentials,
      macaroonCreds
    );
    lnd = new lnrpc.Lightning(`localhost:${lndPort}`, credentials);
    grpc.waitForClientReady(lnd, Infinity, err => {
      event.sender.send('lndReady', { err });
    });
  });
github LightningPeach / peach-wallet-desktop / server / binaries / Lnd.js View on Github external
const getRpcService = async (name, service) => new Promise((resolve, reject) => {
    const certPath = path.join(settings.get.lndPath, name, LND_CERT_FILE);
    const sslCreds = grpc.credentials.createSsl(fs.readFileSync(certPath));
    const client = new lnRpcDescriptor.lnrpc[service](localLndRpcIp, sslCreds);
    logger.info({ func: getRpcService }, `Will start waiting for grpc connection with params: ${name}, ${service}`);
    ipcSend("setLndInitStatus", `Wait for ${service} service in LND`);
    grpc.waitForClientReady(client, Infinity, (err) => {
        logger.debug({ func: getRpcService }, `Error while waiting: ${err}`);
        if (err) {
            logger.error({ func: getRpcService }, err);
            reject(err);
        }
        if (service === "Lightning" && !settings.get.lnd.no_macaroons) {
            resolve({ client, metadata: getMacaroonMeta(name) });
        }
        resolve(client);
    });
});
github decred / decrediton / app / middleware / grpc / loader.js View on Github external
export function loader(request, cb) {
  var cert = getCert();
  var creds = grpc.credentials.createSsl(cert);
  var loader = new services.WalletLoaderServiceClient(request.address + ':' + request.port, creds);

  var deadline = new Date();
  var deadlineInSeconds = 2;
  deadline.setSeconds(deadline.getSeconds()+deadlineInSeconds);
  grpc.waitForClientReady(loader, deadline, function(err) {
    if (err) {
      return cb(null, err);
    } else {
      return cb(loader);
    }
  });
}
github lightninglabs / lightning-app / apps / desktop / main.dev.js View on Github external
const serverReady = cb =>
       grpc.waitForClientReady(connection, Infinity, cb)
      global.connection = connection
github decred / decrediton / app / middleware / ln / client.js View on Github external
return await new Promise((resolve, reject) => {
    grpc.waitForClientReady(client, deadline, function(err) {
      if (err) {
        reject(err);
      } else {
        resolve(client);
      }
    });
  });
};
github decred / decrediton / app / middleware / grpc / version.js View on Github external
export function getVersionService(address, port, cb) {
  var cert = getCert();
  if (cert == '') {
    return cb(null, 'Unable to load dcrwallet certificate.  dcrwallet not running?');
  }
  var creds = grpc.credentials.createSsl(cert);
  var version = new services.VersionServiceClient(address + ':' + port, creds);

  var deadline = new Date();
  var deadlineInSeconds = 2;
  deadline.setSeconds(deadline.getSeconds()+deadlineInSeconds);
  grpc.waitForClientReady(version, deadline, function(err) {
    if (err) {
      return cb(null, err);
    } else {
      return cb(version);
    }
  });
}
github decred / decrediton / app / middleware / grpc / client.js View on Github external
const getServiceClient = (clientClass) => (isTestNet, walletPath, address, port, cb) => {
  var cert = getWalletCert(getWalletPath(isTestNet, walletPath));
  if (cert == "") {
    return cb(null, "Unable to load dcrwallet certificate.  dcrwallet not running?");
  }
  var creds = grpc.credentials.createSsl(cert);
  var client = new clientClass(address + ":" + port, creds);

  var deadline = new Date();
  var deadlineInSeconds = 30;
  deadline.setSeconds(deadline.getSeconds()+deadlineInSeconds);
  grpc.waitForClientReady(client, deadline, function(err) {
    if (err) {
      return cb(null, err);
    } else {
      return cb(client);
    }
  });
};