Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 });
});
});
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 });
});
});
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);
});
});
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);
}
});
}
const serverReady = cb =>
grpc.waitForClientReady(connection, Infinity, cb)
global.connection = connection
return await new Promise((resolve, reject) => {
grpc.waitForClientReady(client, deadline, function(err) {
if (err) {
reject(err);
} else {
resolve(client);
}
});
});
};
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);
}
});
}
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);
}
});
};