Browse Source

fix(refactor): refactor and add comments

renovate/lint-staged-8.x
Jack Mallers 7 years ago
parent
commit
0c63eb44b1
  1. 18
      app/generate_certs.sh
  2. 46
      app/main.dev.js
  3. 1
      gang.txt
  4. BIN
      resources/binaries/lnd

18
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"
# 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

46
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(() => {
// 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)
})
})
}, 10000)
}
})

1
gang.txt

@ -0,0 +1 @@

BIN
resources/binaries/lnd

Binary file not shown.
Loading…
Cancel
Save