Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit c071bd5

Browse files
committed
Cleanup grpc client init to prevent race condition.
Closes #436
1 parent 7b8f525 commit c071bd5

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

public/grpc-client.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,20 @@ module.exports.init = async function({
4646
lndSettingsDir,
4747
macaroonsEnabled,
4848
}) {
49-
const credentials = await getCredentials(lndSettingsDir);
50-
const protoPath = path.join(__dirname, '..', 'assets', 'rpc.proto');
51-
const { lnrpc } = grpc.load(protoPath);
49+
let credentials;
50+
let protoPath;
5251
let metadata;
53-
if (macaroonsEnabled) {
54-
metadata = getMetadata(lndSettingsDir);
55-
}
56-
52+
let lnrpc;
5753
let unlocker;
58-
ipcMain.on('unlockInit', event => {
54+
let lnd;
55+
56+
ipcMain.on('unlockInit', async event => {
57+
credentials = await getCredentials(lndSettingsDir);
58+
protoPath = path.join(__dirname, '..', 'assets', 'rpc.proto');
59+
lnrpc = grpc.load(protoPath).lnrpc;
60+
if (macaroonsEnabled) {
61+
metadata = getMetadata(lndSettingsDir);
62+
}
5963
unlocker = new lnrpc.WalletUnlocker(`localhost:${lndPort}`, credentials);
6064
grpc.waitForClientReady(unlocker, Infinity, err => {
6165
event.sender.send('unlockReady', { err });
@@ -67,7 +71,6 @@ module.exports.init = async function({
6771
event.sender.send('unlockClosed', {});
6872
});
6973

70-
let lnd;
7174
ipcMain.on('lndInit', event => {
7275
lnd = new lnrpc.Lightning(`localhost:${lndPort}`, credentials);
7376
grpc.waitForClientReady(lnd, Infinity, err => {

0 commit comments

Comments
 (0)