diff --git a/ADVANCED.md b/ADVANCED.md index 937f564c..111af5fc 100644 --- a/ADVANCED.md +++ b/ADVANCED.md @@ -40,8 +40,6 @@ yarn Zap installs `lnd` for you as part of the installation process. Zap will automatically start the internal `lnd` daemon for you when you select the `default` connection type during the on-boarding process. In this mode we run `lnd` as a light client called `neutrino` (BIP 157 & BIP 158) which allows us to run `lnd` without requiring a Bitcoin full node on your system - Instead, Zap will connect to one Zap's hosted BTC full nodes. -**_Note:_** _If you already have `lnd` running on your localhost Zap will detect this and connect to it automatically when you start the app. In this case, the internal `lnd` will not be used._ - ### Option 2: custom: To setup your own `lnd` for use with Zap please follow the instructions on the [lnd installation](https://github.com/lightningnetwork/lnd/blob/master/docs/INSTALL.md) page. Select the `custom` connection type during the on-boarding process to use your own `lnd` with Zap. diff --git a/app/lnd/index.js b/app/lnd/index.js index 638e0c2d..4a87eda3 100644 --- a/app/lnd/index.js +++ b/app/lnd/index.js @@ -1,7 +1,6 @@ import config from './config' import lightning from './lib/lightning' import walletUnlocker from './lib/walletUnlocker' -import { isLndRunning } from './lib/util' import subscribe from './subscribe' import methods from './methods' import walletUnlockerMethods from './walletUnlockerMethods' @@ -31,6 +30,5 @@ const initWalletUnlocker = () => { export default { initLnd, - initWalletUnlocker, - isLndRunning + initWalletUnlocker } diff --git a/app/main.dev.js b/app/main.dev.js index 1bea9506..b104cef9 100644 --- a/app/main.dev.js +++ b/app/main.dev.js @@ -11,22 +11,11 @@ import { mainLog } from './utils/log' import MenuBuilder from './menu' import ZapController from './zap' import ZapUpdater from './updater' -import lnd from './lnd' // Set up a couple of timers to track the app startup progress. mainLog.time('Time until app is ready') mainLog.time('Time until lnd process lookup finished') -// Determine wether we should start our own lnd process or connect to one that is already running. -const zapMode = lnd - .isLndRunning() - .then(res => { - mainLog.debug('lnd already running: %s', res) - mainLog.timeEnd('Time until lnd process lookup finished') - return res ? 'external' : 'internal' - }) - .catch(mainLog.error) - /** * Initialize Zap as soon as electron is ready. */ @@ -53,7 +42,7 @@ app.on('ready', () => { updater.init() // Initialise the application. - const zap = new ZapController(mainWindow, zapMode) + const zap = new ZapController(mainWindow) zap.init() // Initialise the application menus. diff --git a/app/package.json b/app/package.json index 86b0ae8b..9c8d20f9 100644 --- a/app/package.json +++ b/app/package.json @@ -15,7 +15,6 @@ "license": "MIT", "dependencies": { "grpc": "^1.13.0", - "ps-node": "^0.1.6", "react-icons": "^2.2.5" } } diff --git a/app/yarn.lock b/app/yarn.lock index 5c8af1df..fdc5096a 100644 --- a/app/yarn.lock +++ b/app/yarn.lock @@ -81,10 +81,6 @@ concat-map@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" -connected-domain@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/connected-domain/-/connected-domain-1.0.0.tgz#bfe77238c74be453a79f0cb6058deeb4f2358e93" - console-control-strings@^1.0.0, console-control-strings@~1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e" @@ -434,12 +430,6 @@ protobufjs@^5.0.3: glob "^7.0.5" yargs "^3.10.0" -ps-node@^0.1.6: - version "0.1.6" - resolved "https://registry.yarnpkg.com/ps-node/-/ps-node-0.1.6.tgz#9af67a99d7b1d0132e51a503099d38a8d2ace2c3" - dependencies: - table-parser "^0.1.3" - rc@^1.1.7: version "1.2.8" resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.8.tgz#cd924bf5200a075b83c188cd6b9e211b7fc0d3ed" @@ -544,12 +534,6 @@ strip-json-comments@~2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a" -table-parser@^0.1.3: - version "0.1.3" - resolved "https://registry.yarnpkg.com/table-parser/-/table-parser-0.1.3.tgz#0441cfce16a59481684c27d1b5a67ff15a43c7b0" - dependencies: - connected-domain "^1.0.0" - tar@^4: version "4.4.4" resolved "https://registry.yarnpkg.com/tar/-/tar-4.4.4.tgz#ec8409fae9f665a4355cc3b4087d0820232bb8cd" diff --git a/app/zap.js b/app/zap.js index f0fdfaa8..fb7ebfb8 100644 --- a/app/zap.js +++ b/app/zap.js @@ -3,6 +3,7 @@ import Store from 'electron-store' import lnd from './lnd' import Neutrino from './lnd/lib/neutrino' import { mainLog } from './utils/log' +import { isLndRunning } from './lnd/lib/util' const grpcSslCipherSuites = connectionType => (connectionType === 'btcpayserver' @@ -36,14 +37,9 @@ const grpcSslCipherSuites = connectionType => class ZapController { /** * Create a new ZapController instance. - * @param {BrowserWindow} mainWindow BrowserWindow instance to interact with - * @param {String|Promise} mode String or Promise that resolves to the desired run mode. Valid options are: - * - 'internal': start a new lnd process. - * - 'external': connect to an existing lnd process. + * @param {BrowserWindow} mainWindow BrowserWindow instance to interact with. */ - constructor(mainWindow, mode) { - this.mode = mode - + constructor(mainWindow) { // Variable to hold the main window instance. this.mainWindow = mainWindow @@ -73,24 +69,10 @@ class ZapController { this.mainWindow.show() this.mainWindow.focus() mainLog.timeEnd('Time until app is visible') - mainLog.time('Time until we know the run mode') - - Promise.resolve(this.mode) - .then(mode => { - const timeUntilWeKnowTheRunMode = mainLog.timeEnd('Time until we know the run mode') - return setTimeout(async () => { - if (mode === 'external') { - // If lnd is already running, create and subscribe to the Lightning grpc object. - await this.startLightningWallet() - this.sendMessage('successfullyCreatedWallet') - } else { - // Otherwise, start the onboarding process. - this.sendMessage('startOnboarding') - mainLog.timeEnd('Time until onboarding has started') - } - }, timeUntilWeKnowTheRunMode < this.splashScreenTime ? this.splashScreenTime : 0) - }) - .catch(mainLog.error) + + return setTimeout(async () => { + this.sendMessage('startOnboarding') + }, this.splashScreenTime) }) this.mainWindow.on('closed', () => { @@ -232,42 +214,51 @@ class ZapController { // If the requested connection type is a local one then start up a new lnd instance. if (cleanOptions.type === 'local') { - mainLog.info('Starting new lnd instance') - mainLog.info(' > alias:', cleanOptions.alias) - mainLog.info(' > autopilot:', cleanOptions.autopilot) - this.startLnd(cleanOptions.alias, cleanOptions.autopilot) + return isLndRunning().then(res => { + if (res) { + mainLog.error('lnd already running: %s', res) + dialog.showMessageBox({ + type: 'error', + message: 'Unable to start lnd because it is already running.' + }) + return app.quit() + } + mainLog.info('Starting new lnd instance') + mainLog.info(' > alias:', cleanOptions.alias) + mainLog.info(' > autopilot:', cleanOptions.autopilot) + return this.startLnd(cleanOptions.alias, cleanOptions.autopilot) + }) } + // Otherwise attempt to connect to an lnd instance using user supplied connection details. - else { - mainLog.info('Connecting to custom lnd instance') - mainLog.info(' > host:', cleanOptions.host) - mainLog.info(' > cert:', cleanOptions.cert) - mainLog.info(' > macaroon:', cleanOptions.macaroon) - this.startLightningWallet() - .then(() => this.sendMessage('successfullyCreatedWallet')) - .catch(e => { - const errors = {} - // There was a problem connectig to the host. - if (e.code === 'LND_GRPC_HOST_ERROR') { - errors.host = e.message - } - // There was a problem accessing loading the ssl cert. - if (e.code === 'LND_GRPC_CERT_ERROR') { - errors.cert = e.message - } - // There was a problem accessing loading the macaroon file. - else if (e.code === 'LND_GRPC_MACAROON_ERROR') { - errors.macaroon = e.message - } - // Other error codes such as UNAVAILABLE most likely indicate that there is a problem with the host. - else { - errors.host = `Unable to connect to host: ${e.details || e.message}` - } - - // Notify the app of errors. - return this.sendMessage('startLndError', errors) - }) - } + mainLog.info('Connecting to custom lnd instance') + mainLog.info(' > host:', cleanOptions.host) + mainLog.info(' > cert:', cleanOptions.cert) + mainLog.info(' > macaroon:', cleanOptions.macaroon) + this.startLightningWallet() + .then(() => this.sendMessage('successfullyCreatedWallet')) + .catch(e => { + const errors = {} + // There was a problem connectig to the host. + if (e.code === 'LND_GRPC_HOST_ERROR') { + errors.host = e.message + } + // There was a problem accessing loading the ssl cert. + if (e.code === 'LND_GRPC_CERT_ERROR') { + errors.cert = e.message + } + // There was a problem accessing loading the macaroon file. + else if (e.code === 'LND_GRPC_MACAROON_ERROR') { + errors.macaroon = e.message + } + // Other error codes such as UNAVAILABLE most likely indicate that there is a problem with the host. + else { + errors.host = `Unable to connect to host: ${e.details || e.message}` + } + + // Notify the app of errors. + return this.sendMessage('startLndError', errors) + }) }) } } diff --git a/package.json b/package.json index d42b7ea4..8b4ffd71 100644 --- a/package.json +++ b/package.json @@ -252,7 +252,6 @@ "minimist": "^1.2.0", "node-sass": "^4.9.0", "prettier": "^1.13.5", - "ps-node": "^0.1.6", "react-addons-test-utils": "^15.6.0", "react-test-renderer": "^15.6.1", "redux-logger": "^3.0.6", @@ -286,6 +285,7 @@ "lodash.get": "^4.4.2", "moment": "^2.22.2", "prop-types": "^15.5.10", + "ps-node": "^0.1.6", "qrcode.react": "0.8.0", "react": "^15.6.1", "react-dom": "^15.6.1",