diff --git a/lib/i18n/locales/en.json b/lib/i18n/locales/en.json index 75427395d..020f31e6a 100644 --- a/lib/i18n/locales/en.json +++ b/lib/i18n/locales/en.json @@ -128,6 +128,10 @@ "Error while downloading the file": "Error while downloading the file", "Error while loading the content of ": "Error while loading the content of ", "no contracts found": "no contracts found", + "IPFS node detected": "IPFS node detected", + "No process file for this storage type exists. Please start the process locally.": "No process file for this storage type exists. Please start the process locally.", + "Starting swarm process": "Starting swarm process", + "Storage process for swarm ended before the end of this process. Code: 0": "Storage process for swarm ended before the end of this process. Code: 0", "DApp path length is too long: \"": "DApp path length is too long: \"", "This is known to cause issues with some applications, please consider reducing your DApp path's length to 66 characters or less.": "This is known to cause issues with some applications, please consider reducing your DApp path's length to 66 characters or less.", "DApp path length is too long: ": "DApp path length is too long: ", diff --git a/lib/index.js b/lib/index.js index 4b2fd38d7..d511e9ffa 100644 --- a/lib/index.js +++ b/lib/index.js @@ -339,7 +339,8 @@ class Embark { if (!serviceCheckResult.status || serviceCheckResult.status === 'off') { const storageProcessesLauncher = new StorageProcessesLauncher({ logger: engine.logger, - events: engine.events + events: engine.events, + storageConfig: engine.config.storageConfig }); return storageProcessesLauncher.launchProcess(platform.toLowerCase(), (err) => { if (err) { diff --git a/lib/processes/storageProcesses/storageProcessesLauncher.js b/lib/processes/storageProcesses/storageProcessesLauncher.js index 10048e665..965673409 100644 --- a/lib/processes/storageProcesses/storageProcessesLauncher.js +++ b/lib/processes/storageProcesses/storageProcessesLauncher.js @@ -7,6 +7,7 @@ class StorageProcessesLauncher { constructor(options) { this.logger = options.logger; this.events = options.events; + this.storageConfig = options.storageConfig; this.processes = {}; } @@ -32,9 +33,16 @@ class StorageProcessesLauncher { silent: true, exitCallback: self.processExited.bind(this, storageName) }); - self.processes[storageName].send({action: constants.blockchain.init, options: {}}); + self.processes[storageName].send({action: constants.blockchain.init, options: {storageConfig: self.storageConfig}}); - callback(); + self.processes[storageName].on('result', constants.storage.initiated, (msg) => { + if (msg.error) { + self.processes[storageName].disconnect(); + delete self.processes[storageName]; + return callback(msg.error); + } + callback(); + }); }); } } diff --git a/lib/processes/storageProcesses/swarm.js b/lib/processes/storageProcesses/swarm.js new file mode 100644 index 000000000..db413fa2a --- /dev/null +++ b/lib/processes/storageProcesses/swarm.js @@ -0,0 +1,34 @@ +const shelljs = require('shelljs'); +const ProcessWrapper = require('../../process/processWrapper'); +const constants = require('../../constants'); + +let swarmProcess; + +class SwarmProcess extends ProcessWrapper { + constructor(options) { + super(); + this.storageConfig = options.storageConfig; + } + + startSwarmDaemon() { + if (!this.storageConfig.account || !this.storageConfig.account.address || !this.storageConfig.password) { + return 'Account address and password are needed in the storage config to start the Swarm process'; + } + shelljs.exec(`${this.storageConfig.swarmPath || 'swarm'} --bzzaccount ${this.storageConfig.account.address} --password ${this.storageConfig.password}`, {silent: true}, (err, _stdout, _stderr) => { + if (err) { + console.error(err); + process.exit(1); + } + process.exit(); + }); + } +} + +process.on('message', (msg) => { + if (msg.action === constants.storage.init) { + swarmProcess = new SwarmProcess(msg.options); + const error = swarmProcess.startSwarmDaemon(); + + swarmProcess.send({result: constants.storage.initiated, error}); + } +});