|
@ -20,6 +20,7 @@ import Store from 'electron-store' |
|
|
import MenuBuilder from './menu' |
|
|
import MenuBuilder from './menu' |
|
|
import lnd from './lnd' |
|
|
import lnd from './lnd' |
|
|
import config from './lnd/config' |
|
|
import config from './lnd/config' |
|
|
|
|
|
import { mainLog, lndLog, lndLogGetLevel } from './utils/log' |
|
|
|
|
|
|
|
|
let mainWindow = null |
|
|
let mainWindow = null |
|
|
|
|
|
|
|
@ -44,7 +45,7 @@ const installExtensions = async () => { |
|
|
const forceDownload = !!process.env.UPGRADE_EXTENSIONS |
|
|
const forceDownload = !!process.env.UPGRADE_EXTENSIONS |
|
|
const extensions = ['REACT_DEVELOPER_TOOLS', 'REDUX_DEVTOOLS'] |
|
|
const extensions = ['REACT_DEVELOPER_TOOLS', 'REDUX_DEVTOOLS'] |
|
|
|
|
|
|
|
|
return Promise.all(extensions.map(name => installer.default(installer[name], forceDownload))).catch(console.log) |
|
|
return Promise.all(extensions.map(name => installer.default(installer[name], forceDownload))).catch(mainLog.error) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Send the front end event letting them know the gRPC connection is disconnected
|
|
|
// Send the front end event letting them know the gRPC connection is disconnected
|
|
@ -68,7 +69,7 @@ const sendLndSyncing = () => { |
|
|
clearInterval(sendLndSyncingInterval) |
|
|
clearInterval(sendLndSyncingInterval) |
|
|
|
|
|
|
|
|
if (mainWindow) { |
|
|
if (mainWindow) { |
|
|
console.log('SENDING SYNCING') |
|
|
mainLog.info('SENDING SYNCING') |
|
|
startedSync = true |
|
|
startedSync = true |
|
|
mainWindow.webContents.send('lndSyncing') |
|
|
mainWindow.webContents.send('lndSyncing') |
|
|
} |
|
|
} |
|
@ -82,7 +83,7 @@ const sendStartOnboarding = () => { |
|
|
clearInterval(sendStartOnboardingInterval) |
|
|
clearInterval(sendStartOnboardingInterval) |
|
|
|
|
|
|
|
|
if (mainWindow) { |
|
|
if (mainWindow) { |
|
|
console.log('STARTING ONBOARDING') |
|
|
mainLog.info('STARTING ONBOARDING') |
|
|
mainWindow.webContents.send('startOnboarding') |
|
|
mainWindow.webContents.send('startOnboarding') |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -136,7 +137,7 @@ const sendLndSynced = () => { |
|
|
clearInterval(sendLndSyncedInterval) |
|
|
clearInterval(sendLndSyncedInterval) |
|
|
|
|
|
|
|
|
if (mainWindow) { |
|
|
if (mainWindow) { |
|
|
console.log('SENDING SYNCED') |
|
|
mainLog.info('SENDING SYNCED') |
|
|
mainWindow.webContents.send('lndSynced') |
|
|
mainWindow.webContents.send('lndSynced') |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -146,7 +147,12 @@ const sendLndSynced = () => { |
|
|
// Starts the LND node
|
|
|
// Starts the LND node
|
|
|
const startLnd = (alias, autopilot) => { |
|
|
const startLnd = (alias, autopilot) => { |
|
|
const lndConfig = config.lnd() |
|
|
const lndConfig = config.lnd() |
|
|
console.log('lndConfig', lndConfig) |
|
|
mainLog.info('STARTING BUNDLED LND') |
|
|
|
|
|
mainLog.debug(' > lndPath', lndConfig.lndPath) |
|
|
|
|
|
mainLog.debug(' > lightningRpc:', lndConfig.lightningRpc) |
|
|
|
|
|
mainLog.debug(' > lightningHost:', lndConfig.lightningHost) |
|
|
|
|
|
mainLog.debug(' > cert:', lndConfig.cert) |
|
|
|
|
|
mainLog.debug(' > macaroon:', lndConfig.macaroon) |
|
|
|
|
|
|
|
|
const neutrinoArgs = [ |
|
|
const neutrinoArgs = [ |
|
|
'--bitcoin.active', |
|
|
'--bitcoin.active', |
|
@ -161,31 +167,37 @@ const startLnd = (alias, autopilot) => { |
|
|
|
|
|
|
|
|
const neutrino = spawn(lndConfig.lndPath, neutrinoArgs) |
|
|
const neutrino = spawn(lndConfig.lndPath, neutrinoArgs) |
|
|
.on('error', (error) => { |
|
|
.on('error', (error) => { |
|
|
console.log(`lnd error: ${error}`) |
|
|
lndLog.error(`lnd error: ${error}`) |
|
|
dialog.showMessageBox({ |
|
|
dialog.showMessageBox({ |
|
|
type: 'error', |
|
|
type: 'error', |
|
|
message: `lnd error: ${error}` |
|
|
message: `lnd error: ${error}` |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
.on('close', (code) => { |
|
|
.on('close', (code) => { |
|
|
console.log(`lnd shutting down ${code}`) |
|
|
lndLog.info(`lnd shutting down ${code}`) |
|
|
app.quit() |
|
|
app.quit() |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
// Listen for when neutrino prints out data
|
|
|
// Listen for when neutrino prints odata to stderr.
|
|
|
|
|
|
neutrino.stderr.pipe(split2()).on('data', (line) => { |
|
|
|
|
|
if (process.env.NODE_ENV === 'development') { |
|
|
|
|
|
lndLog[lndLogGetLevel(line)](line) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
// Listen for when neutrino prints data to stdout.
|
|
|
neutrino.stdout.pipe(split2()).on('data', (line) => { |
|
|
neutrino.stdout.pipe(split2()).on('data', (line) => { |
|
|
if (process.env.NODE_ENV === 'development') { |
|
|
if (process.env.NODE_ENV === 'development') { |
|
|
console.log(line) |
|
|
lndLog[lndLogGetLevel(line)](line) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// If the gRPC proxy has started we can start ours
|
|
|
// If the gRPC proxy has started we can start ours
|
|
|
if (line.includes('gRPC proxy started')) { |
|
|
if (line.includes('gRPC proxy started')) { |
|
|
const certInterval = setInterval(() => { |
|
|
const certInterval = setInterval(() => { |
|
|
console.log('lndConfig', lndConfig) |
|
|
|
|
|
if (fs.existsSync(lndConfig.cert)) { |
|
|
if (fs.existsSync(lndConfig.cert)) { |
|
|
clearInterval(certInterval) |
|
|
clearInterval(certInterval) |
|
|
|
|
|
|
|
|
console.log('CERT EXISTS, STARTING WALLET UNLOCKER') |
|
|
mainLog.info('CERT EXISTS, STARTING WALLET UNLOCKER') |
|
|
startWalletUnlocker() |
|
|
startWalletUnlocker() |
|
|
|
|
|
|
|
|
if (mainWindow) { |
|
|
if (mainWindow) { |
|
@ -196,7 +208,7 @@ const startLnd = (alias, autopilot) => { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (line.includes('gRPC proxy started') && !line.includes('password')) { |
|
|
if (line.includes('gRPC proxy started') && !line.includes('password')) { |
|
|
console.log('WALLET OPENED, STARTING LIGHTNING GRPC CONNECTION') |
|
|
mainLog.info('WALLET OPENED, STARTING LIGHTNING GRPC CONNECTION') |
|
|
sendLndSyncing() |
|
|
sendLndSyncing() |
|
|
startGrpc() |
|
|
startGrpc() |
|
|
} |
|
|
} |
|
@ -210,7 +222,7 @@ const startLnd = (alias, autopilot) => { |
|
|
// When LND is all caught up to the blockchain
|
|
|
// When LND is all caught up to the blockchain
|
|
|
if (line.includes('Chain backend is fully synced')) { |
|
|
if (line.includes('Chain backend is fully synced')) { |
|
|
// Log that LND is caught up to the current block height
|
|
|
// Log that LND is caught up to the current block height
|
|
|
console.log('NEUTRINO IS SYNCED') |
|
|
mainLog.info('NEUTRINO IS SYNCED') |
|
|
|
|
|
|
|
|
// Let the front end know we have stopped syncing LND
|
|
|
// Let the front end know we have stopped syncing LND
|
|
|
sendLndSynced() |
|
|
sendLndSynced() |
|
@ -272,7 +284,7 @@ app.on('ready', async () => { |
|
|
|
|
|
|
|
|
sendGrpcDisconnected() |
|
|
sendGrpcDisconnected() |
|
|
|
|
|
|
|
|
console.log('LOOKING FOR LOCAL LND') |
|
|
mainLog.info('LOOKING FOR EXISTING LND PROCESS') |
|
|
// Check to see if an LND process is running.
|
|
|
// Check to see if an LND process is running.
|
|
|
lookup({ command: 'lnd' }, (err, results) => { |
|
|
lookup({ command: 'lnd' }, (err, results) => { |
|
|
// There was an error checking for the LND process.
|
|
|
// There was an error checking for the LND process.
|
|
@ -280,13 +292,14 @@ app.on('ready', async () => { |
|
|
throw new Error(err) |
|
|
throw new Error(err) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// No LND process was found.
|
|
|
|
|
|
if (!results.length) { |
|
|
if (!results.length) { |
|
|
|
|
|
// An LND process was found, no need to start our own.
|
|
|
|
|
|
mainLog.info('EXISTING LND PROCESS NOT FOUND') |
|
|
// Let the application know onboarding has started.
|
|
|
// Let the application know onboarding has started.
|
|
|
sendStartOnboarding() |
|
|
sendStartOnboarding() |
|
|
} else { |
|
|
} else { |
|
|
// An LND process was found, no need to start our own.
|
|
|
// An LND process was found, no need to start our own.
|
|
|
console.log('LND ALREADY RUNNING') |
|
|
mainLog.info('FOUND EXISTING LND PROCESS') |
|
|
startGrpc() |
|
|
startGrpc() |
|
|
mainWindow.webContents.send('successfullyCreatedWallet') |
|
|
mainWindow.webContents.send('successfullyCreatedWallet') |
|
|
} |
|
|
} |
|
@ -295,8 +308,6 @@ app.on('ready', async () => { |
|
|
// Start LND
|
|
|
// Start LND
|
|
|
// once the onboarding has enough information, start or connect to LND.
|
|
|
// once the onboarding has enough information, start or connect to LND.
|
|
|
ipcMain.on('startLnd', (event, options = {}) => { |
|
|
ipcMain.on('startLnd', (event, options = {}) => { |
|
|
console.log('STARTING LND', options) |
|
|
|
|
|
|
|
|
|
|
|
const store = new Store({ name: 'connection' }) |
|
|
const store = new Store({ name: 'connection' }) |
|
|
store.store = { |
|
|
store.store = { |
|
|
type: options.connectionType, |
|
|
type: options.connectionType, |
|
@ -307,12 +318,20 @@ app.on('ready', async () => { |
|
|
autopilot: options.autopilot |
|
|
autopilot: options.autopilot |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
console.log('SAVED CONFIG TO:', store.path, 'AS', store.store) |
|
|
mainLog.info('GOT LND CONFIG') |
|
|
|
|
|
mainLog.debug(' > connectionType:', options.connectionType) |
|
|
|
|
|
mainLog.debug(' > connectionHost:', options.connectionHost) |
|
|
|
|
|
mainLog.debug(' > connectionCert:', options.connectionCert) |
|
|
|
|
|
mainLog.debug(' > connectionMacaroon:', options.connectionMacaroon) |
|
|
|
|
|
mainLog.debug(' > alias:', options.alias) |
|
|
|
|
|
mainLog.debug(' > autopilot:', options.autopilot) |
|
|
|
|
|
|
|
|
|
|
|
mainLog.info('SAVED LND CONFIG TO:', store.path) |
|
|
|
|
|
|
|
|
if (options.connectionType === 'local') { |
|
|
if (options.connectionType === 'local') { |
|
|
startLnd(options.alias, options.autopilot) |
|
|
startLnd(options.alias, options.autopilot) |
|
|
} else { |
|
|
} else { |
|
|
console.log('USING CUSTOM LND') |
|
|
mainLog.info('CONNECTING TO CUSTOM LND INSTANCE') |
|
|
startGrpc() |
|
|
startGrpc() |
|
|
mainWindow.webContents.send('successfullyCreatedWallet') |
|
|
mainWindow.webContents.send('successfullyCreatedWallet') |
|
|
} |
|
|
} |
|
|