diff --git a/app/generate_certs.sh b/app/generate_certs.sh index 7ee3adb6..1705f48b 100644 --- a/app/generate_certs.sh +++ b/app/generate_certs.sh @@ -1,8 +1,20 @@ # Generate Node.js compatible certs -echo >> file.txt -echo "HERE CREATING COMPATIBLE CERTS" +echo >> gang.txt +echo "here!" + +# If Lnd folder doesn't exist we have to create it +if [ ! -d ~/Library/Application\ Support/Lnd ]; then + mkdir -p ~/Library/Application\ Support/Lnd; +fi + +# Generate compatible certs openssl ecparam -genkey -name prime256v1 -out ~/Library/Application\ Support/Lnd/tls.key openssl req -new -sha256 -key ~/Library/Application\ Support/Lnd/tls.key -out ~/Library/Application\ Support/Lnd/csr.csr -subj '/CN=localhost/O=lnd' openssl req -x509 -sha256 -days 3650 -key ~/Library/Application\ Support/Lnd/tls.key -in ~/Library/Application\ Support/Lnd/csr.csr -out ~/Library/Application\ Support/Lnd/tls.cert rm ~/Library/Application\ Support/Lnd/csr.csr -echo "DONE CREATING COMPATIBLE CERTS YO" \ No newline at end of file + +# Linux +# openssl ecparam -genkey -name prime256v1 -out ~/.lnd/tls.key +# openssl req -new -sha256 -key ~/.lnd/tls.key -out ~/.lnd/csr.csr -subj '/CN=localhost/O=lnd' +# openssl req -x509 -sha256 -days 3650 -key ~/.lnd/tls.key -in ~/.lnd/csr.csr -out ~/.lnd/tls.cert +# rm ~/.lnd/csr.csr \ No newline at end of file diff --git a/app/main.dev.js b/app/main.dev.js index ee2a0492..6d7af44e 100644 --- a/app/main.dev.js +++ b/app/main.dev.js @@ -98,25 +98,22 @@ app.on('ready', async () => { const menuBuilder = new MenuBuilder(mainWindow); menuBuilder.buildMenu(); - // Check to see if LND is running. If not, start it. + // Where we will store the neutrino process if need be let neutrino = null + + // Check to see if and LND process is running lookup({ command: 'lnd' }, (err, results) => { + // There was an error checking for the LND process if (err) { throw new Error( err ) } + // No LND process was found if (!results.length) { - const lndCertPath = `/Users/${userInfo().username}/Library/Application Support/Lnd/tls.cert` - if (!fs.existsSync(lndCertPath)) { - console.log('GENERATING CERTS') - spawn( - 'npm', - ['run', 'generate_certs'], - { shell: true } - ) - } - // Alert user that LND is starting - console.log('STARTING LND') + // Run a bash script that checks for the LND folder and generates Node.js compatible certs + console.log('CHECKING/GENERATING CERTS') + exec('sh generate_certs.sh') - // Start LND + // After the certs are generated, it's time to start LND + console.log('STARTING LND') neutrino = spawn( 'lnd', [ @@ -131,18 +128,22 @@ app.on('ready', async () => { ) .on('close', code => console.log(`lnd shutting down ${code}`)) + // Listen for when neutrino prints out data neutrino.stdout.on('data', data => { + // Data stored in variable line, log line to the console let line = data.toString('utf8') - console.log('line: ', line) + console.log(line) + // When LND is all caught up to the blockchain if (line.includes('Done catching up block hashes')) { - console.log('CERT EXISTS AND DONE CATCHING UP BLOCK HASHES') + // Log that LND is caught up to the current block height + console.log('DONE CATCHING UP BLOCK HASHES') + // Call lnd lnd((lndSubscribe, lndMethods) => { - console.log('lndSubscribe: ', lndSubscribe) - console.log('lndMethods: ', lndMethods) - + // Subscribe to bi-directional streams lndSubscribe(mainWindow) + // Listen for all gRPC restful methods ipcMain.on('lnd', (event, { msg, data }) => { lndMethods(event, msg, data) }) @@ -150,19 +151,18 @@ app.on('ready', async () => { } }) } else { + // An LND process was found, no need to start our own console.log('LND ALREADY RUNNING') - setTimeout(() => { - lnd((lndSubscribe, lndMethods) => { - console.log('lndSubscribe: ', lndSubscribe) - console.log('lndMethods: ', lndMethods) - - lndSubscribe(mainWindow) - - ipcMain.on('lnd', (event, { msg, data }) => { - lndMethods(event, msg, data) - }) + // Call lnd + lnd((lndSubscribe, lndMethods) => { + // Subscribe to bi-directional streams + lndSubscribe(mainWindow) + + // Listen for all gRPC restful methods + ipcMain.on('lnd', (event, { msg, data }) => { + lndMethods(event, msg, data) }) - }, 10000) + }) } }) diff --git a/gang.txt b/gang.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/gang.txt @@ -0,0 +1 @@ + diff --git a/resources/binaries/lnd b/resources/binaries/lnd index 3918450a..3d0cae9b 100755 Binary files a/resources/binaries/lnd and b/resources/binaries/lnd differ