Merge pull request #465 from embark-framework/features/ipfs-process
Processes everywhere
This commit is contained in:
commit
4aa33935b0
|
@ -1,11 +1,12 @@
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
const shelljs = require('shelljs');
|
const child_process = require('child_process');
|
||||||
|
const _ = require('underscore');
|
||||||
|
|
||||||
const fs = require('../../core/fs.js');
|
const fs = require('../../core/fs.js');
|
||||||
|
|
||||||
const GethCommands = require('./geth_commands.js');
|
const GethCommands = require('./geth_commands.js');
|
||||||
|
|
||||||
/*eslint complexity: ["error", 35]*/
|
/*eslint complexity: ["error", 36]*/
|
||||||
var Blockchain = function(options) {
|
var Blockchain = function(options) {
|
||||||
this.blockchainConfig = options.blockchainConfig;
|
this.blockchainConfig = options.blockchainConfig;
|
||||||
this.env = options.env || 'development';
|
this.env = options.env || 'development';
|
||||||
|
@ -54,6 +55,20 @@ var Blockchain = function(options) {
|
||||||
this.config.datadir = fs.embarkPath(".embark/development/datadir");
|
this.config.datadir = fs.embarkPath(".embark/development/datadir");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const spaceMessage = 'The path for %s in blockchain config contains spaces, please remove them';
|
||||||
|
if (this.config.datadir && this.config.datadir.indexOf(' ') > 0) {
|
||||||
|
console.error(__(spaceMessage, 'datadir'));
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
if (this.config.account.password && this.config.account.password.indexOf(' ') > 0) {
|
||||||
|
console.error(__(spaceMessage, 'account.password'));
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
if (this.config.genesisBlock && this.config.genesisBlock.indexOf(' ') > 0) {
|
||||||
|
console.error(__(spaceMessage, 'genesisBlock'));
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
|
||||||
this.client = new options.client({config: this.config, env: this.env, isDev: this.isDev});
|
this.client = new options.client({config: this.config, env: this.env, isDev: this.isDev});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -62,7 +77,7 @@ Blockchain.prototype.runCommand = function(cmd, options, callback) {
|
||||||
if (this.blockchainConfig.silent) {
|
if (this.blockchainConfig.silent) {
|
||||||
options.silent = true;
|
options.silent = true;
|
||||||
}
|
}
|
||||||
return shelljs.exec(cmd, options, callback);
|
return child_process.exec(cmd, options, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockchain.prototype.run = function() {
|
Blockchain.prototype.run = function() {
|
||||||
|
@ -95,44 +110,53 @@ Blockchain.prototype.run = function() {
|
||||||
next();
|
next();
|
||||||
},
|
},
|
||||||
function getMainCommand(next) {
|
function getMainCommand(next) {
|
||||||
self.client.mainCommand(address, function(cmd) {
|
self.client.mainCommand(address, function(cmd, args) {
|
||||||
next(null, cmd);
|
next(null, cmd, args);
|
||||||
});
|
}, true);
|
||||||
}
|
}
|
||||||
], function (err, cmd) {
|
], function (err, cmd, args) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const child = self.runCommand(cmd, {}, (err, stdout, _stderr) => {
|
args = _.compact(args);
|
||||||
if (err && self.env === 'development' && stdout.indexOf('Failed to unlock') > 0) {
|
self.child = child_process.spawn(cmd, args, {cwd: process.cwd()});
|
||||||
// console.error is captured and sent to the console output regardless of silent setting
|
|
||||||
|
self.child.on('error', (err) => {
|
||||||
|
err = err.toString();
|
||||||
|
console.error('Blockchain error: ', err);
|
||||||
|
if (self.env === 'development' && err.indexOf('Failed to unlock') > 0) {
|
||||||
console.error('\n' + __('Development blockchain has changed to use the --dev option.').yellow);
|
console.error('\n' + __('Development blockchain has changed to use the --dev option.').yellow);
|
||||||
console.error(__('You can reset your workspace to fix the problem with').yellow + ' embark reset'.cyan);
|
console.error(__('You can reset your workspace to fix the problem with').yellow + ' embark reset'.cyan);
|
||||||
console.error(__('Otherwise, you can change your data directory in blockchain.json (datadir)').yellow);
|
console.error(__('Otherwise, you can change your data directory in blockchain.json (datadir)').yellow);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (self.onReadyCallback) {
|
self.child.stdout.on('data', (data) => {
|
||||||
// Geth logs appear in stderr somehow
|
console.log(`Geth error: ${data}`);
|
||||||
let lastMessage;
|
});
|
||||||
child.stderr.on('data', (data) => {
|
// Geth logs appear in stderr somehow
|
||||||
if (!self.readyCalled && data.indexOf('Mapped network port') > -1) {
|
self.child.stderr.on('data', (data) => {
|
||||||
self.readyCalled = true;
|
data = data.toString();
|
||||||
self.onReadyCallback();
|
if (self.onReadyCallback && !self.readyCalled && data.indexOf('WebSocket endpoint opened') > -1) {
|
||||||
}
|
self.readyCalled = true;
|
||||||
lastMessage = data;
|
self.onReadyCallback();
|
||||||
console.log('Geth: ' + data);
|
}
|
||||||
});
|
console.log('Geth: ' + data);
|
||||||
child.on('exit', (code) => {
|
});
|
||||||
if (code) {
|
self.child.on('exit', (code) => {
|
||||||
console.error('Geth exited with error code ' + 1);
|
if (code) {
|
||||||
console.error(lastMessage);
|
console.error('Geth exited with error code ' + code);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Blockchain.prototype.kill = function() {
|
||||||
|
if (this.child) {
|
||||||
|
this.child.kill();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Blockchain.prototype.checkPathLength = function() {
|
Blockchain.prototype.checkPathLength = function() {
|
||||||
let dappPath = fs.dappPath('');
|
let dappPath = fs.dappPath('');
|
||||||
if (dappPath.length > 66) {
|
if (dappPath.length > 66) {
|
||||||
|
@ -145,7 +169,7 @@ Blockchain.prototype.checkPathLength = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockchain.prototype.isClientInstalled = function(callback) {
|
Blockchain.prototype.isClientInstalled = function(callback) {
|
||||||
let versionCmd = this.client.determineVersion();
|
let versionCmd = this.client.determineVersionCommand();
|
||||||
this.runCommand(versionCmd, {}, (err, stdout, stderr) => {
|
this.runCommand(versionCmd, {}, (err, stdout, stderr) => {
|
||||||
if (err || stderr || !stdout || stdout.indexOf("not found") >= 0) {
|
if (err || stderr || !stdout || stdout.indexOf("not found") >= 0) {
|
||||||
return callback('Geth not found');
|
return callback('Geth not found');
|
||||||
|
|
|
@ -30,9 +30,16 @@ class BlockchainProcess extends ProcessWrapper {
|
||||||
blockchainReady() {
|
blockchainReady() {
|
||||||
blockchainProcess.send({result: constants.blockchain.blockchainReady});
|
blockchainProcess.send({result: constants.blockchain.blockchainReady});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kill() {
|
||||||
|
this.blockchain.kill();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
process.on('message', (msg) => {
|
process.on('message', (msg) => {
|
||||||
|
if (msg === 'exit') {
|
||||||
|
return blockchainProcess.kill();
|
||||||
|
}
|
||||||
if (msg.action === constants.blockchain.init) {
|
if (msg.action === constants.blockchain.init) {
|
||||||
blockchainProcess = new BlockchainProcess(msg.options);
|
blockchainProcess = new BlockchainProcess(msg.options);
|
||||||
return blockchainProcess.send({result: constants.blockchain.initiated});
|
return blockchainProcess.send({result: constants.blockchain.initiated});
|
||||||
|
|
|
@ -12,75 +12,75 @@ class GethCommands {
|
||||||
|
|
||||||
commonOptions() {
|
commonOptions() {
|
||||||
let config = this.config;
|
let config = this.config;
|
||||||
let cmd = "";
|
let cmd = [];
|
||||||
|
|
||||||
cmd += this.determineNetworkType(config);
|
cmd.push(this.determineNetworkType(config));
|
||||||
|
|
||||||
if (config.datadir) {
|
if (config.datadir) {
|
||||||
cmd += "--datadir=\"" + config.datadir + "\" ";
|
cmd.push(`--datadir=${config.datadir}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.light) {
|
if (config.light) {
|
||||||
cmd += "--light ";
|
cmd.push("--light");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.fast) {
|
if (config.fast) {
|
||||||
cmd += "--fast ";
|
cmd.push("--fast");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.account && config.account.password) {
|
if (config.account && config.account.password) {
|
||||||
cmd += "--password " + config.account.password + " ";
|
cmd.push(`--password=${config.account.password}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Number.isInteger(config.verbosity) && config.verbosity >=0 && config.verbosity <= 5) {
|
if (Number.isInteger(config.verbosity) && config.verbosity >=0 && config.verbosity <= 5) {
|
||||||
cmd += "--verbosity " + config.verbosity + " ";
|
cmd.push("--verbosity=" + config.verbosity);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
determineVersion() {
|
determineVersionCommand() {
|
||||||
return this.geth_bin + " version";
|
return this.geth_bin + " version";
|
||||||
}
|
}
|
||||||
|
|
||||||
determineNetworkType(config) {
|
determineNetworkType(config) {
|
||||||
let cmd = "";
|
let cmd;
|
||||||
if (config.networkType === 'testnet') {
|
if (config.networkType === 'testnet') {
|
||||||
cmd += "--testnet ";
|
cmd = "--testnet ";
|
||||||
} else if (config.networkType === 'olympic') {
|
} else if (config.networkType === 'olympic') {
|
||||||
cmd += "--olympic ";
|
cmd = "--olympic ";
|
||||||
} else if (config.networkType === 'custom') {
|
} else if (config.networkType === 'custom') {
|
||||||
cmd += "--networkid " + config.networkId + " ";
|
cmd = "--networkid=" + config.networkId;
|
||||||
}
|
}
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
initGenesisCommmand() {
|
initGenesisCommmand() {
|
||||||
let config = this.config;
|
let config = this.config;
|
||||||
let cmd = this.geth_bin + " " + this.commonOptions();
|
let cmd = this.geth_bin + " " + this.commonOptions().join(' ');
|
||||||
|
|
||||||
if (config.genesisBlock) {
|
if (config.genesisBlock) {
|
||||||
cmd += "init \"" + config.genesisBlock + "\" ";
|
cmd += " init \"" + config.genesisBlock + "\" ";
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
newAccountCommand() {
|
newAccountCommand() {
|
||||||
return this.geth_bin + " " + this.commonOptions() + "account new ";
|
return this.geth_bin + " " + this.commonOptions().join(' ') + " account new ";
|
||||||
}
|
}
|
||||||
|
|
||||||
listAccountsCommand() {
|
listAccountsCommand() {
|
||||||
return this.geth_bin + " " + this.commonOptions() + "account list ";
|
return this.geth_bin + " " + this.commonOptions().join(' ') + " account list ";
|
||||||
}
|
}
|
||||||
|
|
||||||
determineRpcOptions(config) {
|
determineRpcOptions(config) {
|
||||||
let cmd = "";
|
let cmd = [];
|
||||||
|
|
||||||
cmd += "--port " + config.port + " ";
|
cmd.push("--port=" + config.port);
|
||||||
cmd += "--rpc ";
|
cmd.push("--rpc");
|
||||||
cmd += "--rpcport " + config.rpcPort + " ";
|
cmd.push("--rpcport=" + config.rpcPort);
|
||||||
cmd += "--rpcaddr " + config.rpcHost + " ";
|
cmd.push("--rpcaddr=" + config.rpcHost);
|
||||||
if (config.rpcCorsDomain) {
|
if (config.rpcCorsDomain) {
|
||||||
if (config.rpcCorsDomain === '*') {
|
if (config.rpcCorsDomain === '*') {
|
||||||
console.log('==================================');
|
console.log('==================================');
|
||||||
|
@ -88,7 +88,7 @@ class GethCommands {
|
||||||
console.log(__('make sure you know what you are doing'));
|
console.log(__('make sure you know what you are doing'));
|
||||||
console.log('==================================');
|
console.log('==================================');
|
||||||
}
|
}
|
||||||
cmd += "--rpccorsdomain=\"" + config.rpcCorsDomain + "\" ";
|
cmd.push("--rpccorsdomain=" + config.rpcCorsDomain);
|
||||||
} else {
|
} else {
|
||||||
console.log('==================================');
|
console.log('==================================');
|
||||||
console.log(__('warning: cors is not set'));
|
console.log(__('warning: cors is not set'));
|
||||||
|
@ -99,12 +99,12 @@ class GethCommands {
|
||||||
}
|
}
|
||||||
|
|
||||||
determineWsOptions(config) {
|
determineWsOptions(config) {
|
||||||
let cmd = "";
|
let cmd = [];
|
||||||
|
|
||||||
if (config.wsRPC) {
|
if (config.wsRPC) {
|
||||||
cmd += "--ws ";
|
cmd.push("--ws");
|
||||||
cmd += "--wsport " + config.wsPort + " ";
|
cmd.push("--wsport=" + config.wsPort);
|
||||||
cmd += "--wsaddr " + config.wsHost + " ";
|
cmd.push("--wsaddr=" + config.wsHost);
|
||||||
if (config.wsOrigins) {
|
if (config.wsOrigins) {
|
||||||
if (config.wsOrigins === '*') {
|
if (config.wsOrigins === '*') {
|
||||||
console.log('==================================');
|
console.log('==================================');
|
||||||
|
@ -112,7 +112,7 @@ class GethCommands {
|
||||||
console.log(__('make sure you know what you are doing'));
|
console.log(__('make sure you know what you are doing'));
|
||||||
console.log('==================================');
|
console.log('==================================');
|
||||||
}
|
}
|
||||||
cmd += "--wsorigins \"" + config.wsOrigins + "\" ";
|
cmd.push("--wsorigins=" + config.wsOrigins);
|
||||||
} else {
|
} else {
|
||||||
console.log('==================================');
|
console.log('==================================');
|
||||||
console.log(__('warning: wsOrigins is not set'));
|
console.log(__('warning: wsOrigins is not set'));
|
||||||
|
@ -129,44 +129,54 @@ class GethCommands {
|
||||||
let rpc_api = (this.config.rpcApi || ['eth', 'web3', 'net']);
|
let rpc_api = (this.config.rpcApi || ['eth', 'web3', 'net']);
|
||||||
let ws_api = (this.config.wsApi || ['eth', 'web3', 'net']);
|
let ws_api = (this.config.wsApi || ['eth', 'web3', 'net']);
|
||||||
|
|
||||||
|
let args = [];
|
||||||
|
|
||||||
async.series([
|
async.series([
|
||||||
function commonOptions(callback) {
|
function commonOptions(callback) {
|
||||||
let cmd = self.commonOptions();
|
let cmd = self.commonOptions();
|
||||||
|
args = args.concat(cmd);
|
||||||
callback(null, cmd);
|
callback(null, cmd);
|
||||||
},
|
},
|
||||||
function rpcOptions(callback) {
|
function rpcOptions(callback) {
|
||||||
let cmd = self.determineRpcOptions(self.config);
|
let cmd = self.determineRpcOptions(self.config);
|
||||||
|
args = args.concat(cmd);
|
||||||
callback(null, cmd);
|
callback(null, cmd);
|
||||||
},
|
},
|
||||||
function wsOptions(callback) {
|
function wsOptions(callback) {
|
||||||
let cmd = self.determineWsOptions(self.config);
|
let cmd = self.determineWsOptions(self.config);
|
||||||
|
args = args.concat(cmd);
|
||||||
callback(null, cmd);
|
callback(null, cmd);
|
||||||
},
|
},
|
||||||
function dontGetPeers(callback) {
|
function dontGetPeers(callback) {
|
||||||
if (config.nodiscover) {
|
if (config.nodiscover) {
|
||||||
|
args.push("--nodiscover");
|
||||||
return callback(null, "--nodiscover");
|
return callback(null, "--nodiscover");
|
||||||
}
|
}
|
||||||
callback(null, "");
|
callback(null, "");
|
||||||
},
|
},
|
||||||
function vmDebug(callback) {
|
function vmDebug(callback) {
|
||||||
if (config.vmdebug) {
|
if (config.vmdebug) {
|
||||||
|
args.push("--vmdebug");
|
||||||
return callback(null, "--vmdebug");
|
return callback(null, "--vmdebug");
|
||||||
}
|
}
|
||||||
callback(null, "");
|
callback(null, "");
|
||||||
},
|
},
|
||||||
function maxPeers(callback) {
|
function maxPeers(callback) {
|
||||||
let cmd = "--maxpeers " + config.maxpeers;
|
let cmd = "--maxpeers=" + config.maxpeers;
|
||||||
|
args.push(cmd);
|
||||||
callback(null, cmd);
|
callback(null, cmd);
|
||||||
},
|
},
|
||||||
function mining(callback) {
|
function mining(callback) {
|
||||||
if (config.mineWhenNeeded || config.mine) {
|
if (config.mineWhenNeeded || config.mine) {
|
||||||
return callback(null, "--mine ");
|
args.push("--mine");
|
||||||
|
return callback(null, "--mine");
|
||||||
}
|
}
|
||||||
callback("");
|
callback("");
|
||||||
},
|
},
|
||||||
function bootnodes(callback) {
|
function bootnodes(callback) {
|
||||||
if (config.bootnodes && config.bootnodes !== "" && config.bootnodes !== []) {
|
if (config.bootnodes && config.bootnodes !== "" && config.bootnodes !== []) {
|
||||||
return callback(null, "--bootnodes " + config.bootnodes);
|
args.push("--bootnodes=" + config.bootnodes);
|
||||||
|
return callback(null, "--bootnodes=" + config.bootnodes);
|
||||||
}
|
}
|
||||||
callback("");
|
callback("");
|
||||||
},
|
},
|
||||||
|
@ -176,15 +186,18 @@ class GethCommands {
|
||||||
if (ws_api.indexOf('shh') === -1) {
|
if (ws_api.indexOf('shh') === -1) {
|
||||||
ws_api.push('shh');
|
ws_api.push('shh');
|
||||||
}
|
}
|
||||||
|
args.push("--shh");
|
||||||
return callback(null, "--shh ");
|
return callback(null, "--shh ");
|
||||||
}
|
}
|
||||||
callback("");
|
callback("");
|
||||||
},
|
},
|
||||||
function rpcApi(callback) {
|
function rpcApi(callback) {
|
||||||
callback(null, '--rpcapi "' + rpc_api.join(',') + '"');
|
args.push('--rpcapi=' + rpc_api.join(','));
|
||||||
|
callback(null, '--rpcapi=' + rpc_api.join(','));
|
||||||
},
|
},
|
||||||
function wsApi(callback) {
|
function wsApi(callback) {
|
||||||
callback(null, '--wsapi "' + ws_api.join(',') + '"');
|
args.push('--wsapi=' + ws_api.join(','));
|
||||||
|
callback(null, '--wsapi=' + ws_api.join(','));
|
||||||
},
|
},
|
||||||
function accountToUnlock(callback) {
|
function accountToUnlock(callback) {
|
||||||
let accountAddress = "";
|
let accountAddress = "";
|
||||||
|
@ -194,33 +207,37 @@ class GethCommands {
|
||||||
accountAddress = address;
|
accountAddress = address;
|
||||||
}
|
}
|
||||||
if (accountAddress && !self.isDev) {
|
if (accountAddress && !self.isDev) {
|
||||||
|
args.push("--unlock=" + accountAddress);
|
||||||
return callback(null, "--unlock=" + accountAddress);
|
return callback(null, "--unlock=" + accountAddress);
|
||||||
}
|
}
|
||||||
callback(null, "");
|
callback(null, "");
|
||||||
},
|
},
|
||||||
function gasLimit(callback) {
|
function gasLimit(callback) {
|
||||||
if (config.targetGasLimit) {
|
if (config.targetGasLimit) {
|
||||||
return callback(null, "--targetgaslimit " + config.targetGasLimit);
|
args.push("--targetgaslimit=" + config.targetGasLimit);
|
||||||
|
return callback(null, "--targetgaslimit=" + config.targetGasLimit);
|
||||||
}
|
}
|
||||||
callback(null, "");
|
callback(null, "");
|
||||||
},
|
},
|
||||||
function mineWhenNeeded(callback) {
|
function mineWhenNeeded(callback) {
|
||||||
if (config.mineWhenNeeded && !self.isDev) {
|
if (config.mineWhenNeeded && !self.isDev) {
|
||||||
|
args.push("js .embark/" + self.env + "/js/mine.js");
|
||||||
return callback(null, "js .embark/" + self.env + "/js/mine.js");
|
return callback(null, "js .embark/" + self.env + "/js/mine.js");
|
||||||
}
|
}
|
||||||
callback(null, "");
|
callback(null, "");
|
||||||
},
|
},
|
||||||
function isDev(callback) {
|
function isDev(callback) {
|
||||||
if (self.isDev) {
|
if (self.isDev) {
|
||||||
|
args.push('--dev');
|
||||||
return callback(null, '--dev');
|
return callback(null, '--dev');
|
||||||
}
|
}
|
||||||
callback(null, '');
|
callback(null, '');
|
||||||
}
|
}
|
||||||
], function (err, results) {
|
], function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw new Error(err.message);
|
throw new Error(err.message);
|
||||||
}
|
}
|
||||||
done(self.geth_bin + " " + results.join(" "));
|
return done(self.geth_bin, args);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
"contractConfigChanged": "contractConfigChanged"
|
"contractConfigChanged": "contractConfigChanged"
|
||||||
},
|
},
|
||||||
"process": {
|
"process": {
|
||||||
|
"processLaunchRequest": "process:launch-request",
|
||||||
|
"processLaunchComplete": "process:launch-complete",
|
||||||
"log": "log",
|
"log": "log",
|
||||||
"events": {
|
"events": {
|
||||||
"on": "on",
|
"on": "on",
|
||||||
|
@ -34,5 +36,9 @@
|
||||||
"blockchainReady": "blockchainReady",
|
"blockchainReady": "blockchainReady",
|
||||||
"init": "init",
|
"init": "init",
|
||||||
"initiated": "initiated"
|
"initiated": "initiated"
|
||||||
|
},
|
||||||
|
"storage": {
|
||||||
|
"init": "init",
|
||||||
|
"initiated": "initiated"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,13 +109,14 @@ class Blockchain {
|
||||||
|
|
||||||
registerServiceCheck() {
|
registerServiceCheck() {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
const NO_NODE = 'noNode';
|
||||||
|
|
||||||
this.addCheck('Ethereum', function (cb) {
|
this.addCheck('Ethereum', function (cb) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function checkNodeConnection(next) {
|
function checkNodeConnection(next) {
|
||||||
self.assertNodeConnection(true, (err) => {
|
self.assertNodeConnection(true, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(true, {name: "No Blockchain node found", status: 'off'});
|
return next(NO_NODE, {name: "No Blockchain node found", status: 'off'});
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
@ -137,13 +138,12 @@ class Blockchain {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
], (err, statusObj) => {
|
], (err, statusObj) => {
|
||||||
if (err && err !== true) {
|
if (err && err !== NO_NODE) {
|
||||||
self.logger.error(err);
|
return cb(err);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
cb(statusObj);
|
cb(statusObj);
|
||||||
});
|
});
|
||||||
});
|
}, 5000, 'off');
|
||||||
}
|
}
|
||||||
|
|
||||||
registerRequests() {
|
registerRequests() {
|
||||||
|
|
|
@ -45,7 +45,7 @@ class Engine {
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
if (this.interceptLogs || this.interceptLogs === undefined) {
|
if (this.interceptLogs || this.interceptLogs === undefined) {
|
||||||
// this.doInterceptLogs();
|
this.doInterceptLogs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,9 +44,9 @@ ServicesMonitor.prototype.initCheck = function (checkName) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
ServicesMonitor.prototype.addCheck = function (checkName, checkFn, time) {
|
ServicesMonitor.prototype.addCheck = function (checkName, checkFn, time, initialState) {
|
||||||
this.logger.trace('add check: ' + checkName);
|
this.logger.trace('add check: ' + checkName);
|
||||||
this.checkList[checkName] = {fn: checkFn, interval: time || 5000};
|
this.checkList[checkName] = {fn: checkFn, interval: time || 5000, status: initialState};
|
||||||
|
|
||||||
if (this.working) {
|
if (this.working) {
|
||||||
this.initCheck(checkName);
|
this.initCheck(checkName);
|
||||||
|
|
|
@ -330,6 +330,7 @@ class Dashboard {
|
||||||
let self = this;
|
let self = this;
|
||||||
|
|
||||||
this.input.key(["C-c"], function () {
|
this.input.key(["C-c"], function () {
|
||||||
|
self.events.emit('exit');
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -138,5 +138,9 @@
|
||||||
"open another console in the same directory and run": "open another console in the same directory and run",
|
"open another console in the same directory and run": "open another console in the same directory and run",
|
||||||
"For more info go to http://embark.status.im": "For more info go to http://embark.status.im",
|
"For more info go to http://embark.status.im": "For more info go to http://embark.status.im",
|
||||||
"%s is not installed on your machine": "%s is not installed on your machine",
|
"%s is not installed on your machine": "%s is not installed on your machine",
|
||||||
"You can install it by visiting: %s": "You can install it by visiting: %s"
|
"You can install it by visiting: %s": "You can install it by visiting: %s",
|
||||||
|
"IPFS node is offline": "IPFS node is offline",
|
||||||
|
"Starting ipfs process": "Starting ipfs process",
|
||||||
|
"ipfs process started": "ipfs process started",
|
||||||
|
"IPFS node detected": "IPFS node detected"
|
||||||
}
|
}
|
104
lib/index.js
104
lib/index.js
|
@ -1,6 +1,7 @@
|
||||||
let async = require('async');
|
let async = require('async');
|
||||||
const constants = require('./constants');
|
const constants = require('./constants');
|
||||||
const _ = require('underscore');
|
const _ = require('underscore');
|
||||||
|
const StorageProcessesLauncher = require('./processes/storageProcesses/storageProcessesLauncher');
|
||||||
// require("./utils/debug_util.js")(__filename, async);
|
// require("./utils/debug_util.js")(__filename, async);
|
||||||
|
|
||||||
require('colors');
|
require('colors');
|
||||||
|
@ -66,6 +67,42 @@ class Embark {
|
||||||
templateGenerator.generate(destinationFolder, name);
|
templateGenerator.generate(destinationFolder, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_checkStorageEndpoint(engine, platform, callback) {
|
||||||
|
let checkFn;
|
||||||
|
_.find(engine.servicesMonitor.checkList, (value, key) => {
|
||||||
|
if(key.toLowerCase() === platform.toLowerCase()){
|
||||||
|
checkFn = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!checkFn || typeof checkFn.fn !== 'function') {
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
checkFn.fn(function (serviceCheckResult) {
|
||||||
|
if (!serviceCheckResult.status || serviceCheckResult.status === 'off') {
|
||||||
|
return callback('No node');
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_startStorageNode(engine, platform, callback) {
|
||||||
|
const storageProcessesLauncher = new StorageProcessesLauncher({
|
||||||
|
logger: engine.logger,
|
||||||
|
events: engine.events,
|
||||||
|
storageConfig: engine.config.storageConfig,
|
||||||
|
webServerConfig: engine.config.webServerConfig
|
||||||
|
});
|
||||||
|
return storageProcessesLauncher.launchProcess(platform.toLowerCase(), (err) => {
|
||||||
|
if (err) {
|
||||||
|
engine.logger.error(err);
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
run(options) {
|
run(options) {
|
||||||
let self = this;
|
let self = this;
|
||||||
self.context = options.context || [constants.contexts.run, constants.contexts.build];
|
self.context = options.context || [constants.contexts.run, constants.contexts.build];
|
||||||
|
@ -135,21 +172,33 @@ class Embark {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Check storage
|
||||||
|
const platform = engine.config.storageConfig.provider;
|
||||||
|
self._checkStorageEndpoint(engine, platform, (err) => {
|
||||||
|
if (!err) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self._startStorageNode(engine, platform, (err) => {
|
||||||
|
if (err) {
|
||||||
|
engine.logger.error('Error while starting a storage process for ' + platform);
|
||||||
|
engine.logger.error(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
engine.events.on('outputDone', function () {
|
engine.events.on('outputDone', function () {
|
||||||
engine.logger.info((__("Looking for documentation? You can find it at") + " ").cyan + "http://embark.status.im/docs/".green.underline + ".".cyan);
|
engine.logger.info((__("Looking for documentation? You can find it at") + " ").cyan + "http://embark.status.im/docs/".green.underline + ".".cyan);
|
||||||
engine.logger.info(__("Ready").underline);
|
engine.logger.info(__("Ready").underline);
|
||||||
engine.events.emit("status", __("Ready").green);
|
engine.events.emit("status", __("Ready").green);
|
||||||
});
|
});
|
||||||
engine.deployManager.deployContracts(function (err) {
|
if (options.runWebserver) {
|
||||||
engine.startService("fileWatcher");
|
engine.startService("webServer", {
|
||||||
if (options.runWebserver) {
|
host: options.serverHost,
|
||||||
engine.startService("webServer", {
|
port: options.serverPort
|
||||||
host: options.serverHost,
|
});
|
||||||
port: options.serverPort
|
}
|
||||||
});
|
engine.startService("fileWatcher");
|
||||||
}
|
callback();
|
||||||
callback(err);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
], function (err, _result) {
|
], function (err, _result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -285,7 +334,7 @@ class Embark {
|
||||||
}
|
}
|
||||||
|
|
||||||
upload(options) {
|
upload(options) {
|
||||||
|
const self = this;
|
||||||
this.context = options.context || [constants.contexts.upload, constants.contexts.build];
|
this.context = options.context || [constants.contexts.upload, constants.contexts.build];
|
||||||
|
|
||||||
let engine = new Engine({
|
let engine = new Engine({
|
||||||
|
@ -324,21 +373,26 @@ class Embark {
|
||||||
callback();
|
callback();
|
||||||
},
|
},
|
||||||
function checkStorageService(callback){
|
function checkStorageService(callback){
|
||||||
let checkFn;
|
|
||||||
_.find(engine.servicesMonitor.checkList, (value, key) => {
|
const errorObj = {message: __('Cannot upload: {{platform}} node is not running on {{protocol}}://{{host}}:{{port}}.', {platform: platform, protocol: engine.config.storageConfig.protocol, host: engine.config.storageConfig.host, port: engine.config.storageConfig.port})};
|
||||||
if(key.toLowerCase() === platform.toLowerCase()){
|
|
||||||
checkFn = value;
|
self._checkStorageEndpoint(engine, platform, function (err) {
|
||||||
return true;
|
if (!err) {
|
||||||
|
return callback();
|
||||||
}
|
}
|
||||||
});
|
self._startStorageNode(engine, platform, (err) => {
|
||||||
if (!checkFn || typeof checkFn.fn !== 'function') {
|
if (err) {
|
||||||
return callback();
|
engine.logger.error(err);
|
||||||
}
|
return callback(errorObj);
|
||||||
checkFn.fn(function (serviceCheckResult) {
|
}
|
||||||
if (!serviceCheckResult.status || serviceCheckResult.status === 'off') {
|
// Check endpoint again to see if really did start
|
||||||
return callback({message: __('Cannot upload: {{platform}} node is not running on {{protocol}}://{{host}}:{{port}}.', {platform: platform, protocol: engine.config.storageConfig.protocol, host: engine.config.storageConfig.host, port: engine.config.storageConfig.port})});
|
self._checkStorageEndpoint(engine, platform, (err) => {
|
||||||
}
|
if (err) {
|
||||||
callback();
|
return callback(errorObj);
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function setupStoragePlugin(callback){
|
function setupStoragePlugin(callback){
|
||||||
|
|
|
@ -101,8 +101,7 @@ class Pipeline {
|
||||||
const webpackProcess = new ProcessLauncher({
|
const webpackProcess = new ProcessLauncher({
|
||||||
modulePath: utils.joinPath(__dirname, 'webpackProcess.js'),
|
modulePath: utils.joinPath(__dirname, 'webpackProcess.js'),
|
||||||
logger: self.logger,
|
logger: self.logger,
|
||||||
events: self.events,
|
events: self.events
|
||||||
normalizeInput: utils.normalizeInput
|
|
||||||
});
|
});
|
||||||
webpackProcess.send({action: constants.pipeline.init, options: {}});
|
webpackProcess.send({action: constants.pipeline.init, options: {}});
|
||||||
webpackProcess.send({action: constants.pipeline.build, file, importsList});
|
webpackProcess.send({action: constants.pipeline.build, file, importsList});
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
const child_process = require('child_process');
|
const child_process = require('child_process');
|
||||||
const constants = require('../constants');
|
const constants = require('../constants');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const utils = require('../utils/utils');
|
||||||
|
|
||||||
class ProcessLauncher {
|
class ProcessLauncher {
|
||||||
|
|
||||||
|
@ -9,7 +10,6 @@ class ProcessLauncher {
|
||||||
* @param {Object} options Options tp start the process
|
* @param {Object} options Options tp start the process
|
||||||
* * modulePath {String} Absolute path to the module to fork
|
* * modulePath {String} Absolute path to the module to fork
|
||||||
* * logger {Object} Logger
|
* * logger {Object} Logger
|
||||||
* * normalizeInput {Function} Function to normalize logs
|
|
||||||
* * events {Function} Events Emitter instance
|
* * events {Function} Events Emitter instance
|
||||||
* @return {ProcessLauncher} The ProcessLauncher instance
|
* @return {ProcessLauncher} The ProcessLauncher instance
|
||||||
*/
|
*/
|
||||||
|
@ -17,7 +17,6 @@ class ProcessLauncher {
|
||||||
this.name = path.basename(options.modulePath);
|
this.name = path.basename(options.modulePath);
|
||||||
this.process = child_process.fork(options.modulePath);
|
this.process = child_process.fork(options.modulePath);
|
||||||
this.logger = options.logger;
|
this.logger = options.logger;
|
||||||
this.normalizeInput = options.normalizeInput;
|
|
||||||
this.events = options.events;
|
this.events = options.events;
|
||||||
this.silent = options.silent;
|
this.silent = options.silent;
|
||||||
this.exitCallback = options.exitCallback;
|
this.exitCallback = options.exitCallback;
|
||||||
|
@ -55,9 +54,9 @@ class ProcessLauncher {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.logger[msg.type]) {
|
if (this.logger[msg.type]) {
|
||||||
return this.logger[msg.type](this.normalizeInput(msg.message));
|
return this.logger[msg.type](utils.normalizeInput(msg.message));
|
||||||
}
|
}
|
||||||
this.logger.debug(this.normalizeInput(msg.message));
|
this.logger.debug(utils.normalizeInput(msg.message));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle event calls from the child process
|
// Handle event calls from the child process
|
||||||
|
|
|
@ -30,6 +30,7 @@ class ProcessWrapper {
|
||||||
|
|
||||||
context.console.log = this._log.bind(this, 'log');
|
context.console.log = this._log.bind(this, 'log');
|
||||||
context.console.warn = this._log.bind(this, 'warn');
|
context.console.warn = this._log.bind(this, 'warn');
|
||||||
|
context.console.error = this._log.bind(this, 'error');
|
||||||
context.console.info = this._log.bind(this, 'info');
|
context.console.info = this._log.bind(this, 'info');
|
||||||
context.console.debug = this._log.bind(this, 'debug');
|
context.console.debug = this._log.bind(this, 'debug');
|
||||||
context.console.trace = this._log.bind(this, 'trace');
|
context.console.trace = this._log.bind(this, 'trace');
|
||||||
|
|
|
@ -14,17 +14,16 @@ class BlockchainProcessLauncher {
|
||||||
}
|
}
|
||||||
|
|
||||||
processEnded(code) {
|
processEnded(code) {
|
||||||
this.logger.error('Blockchain process ended before the end of this process. Code: ' + code);
|
this.logger.error(__('Blockchain process ended before the end of this process. Code: %s', code));
|
||||||
}
|
}
|
||||||
|
|
||||||
startBlockchainNode() {
|
startBlockchainNode() {
|
||||||
this.logger.info('Starting Blockchain node in another process'.cyan);
|
this.logger.info(__('Starting Blockchain node in another process').cyan);
|
||||||
|
|
||||||
this.blockchainProcess = new ProcessLauncher({
|
this.blockchainProcess = new ProcessLauncher({
|
||||||
modulePath: utils.joinPath(__dirname, '../cmds/blockchain/blockchainProcess.js'),
|
modulePath: utils.joinPath(__dirname, '../cmds/blockchain/blockchainProcess.js'),
|
||||||
logger: this.logger,
|
logger: this.logger,
|
||||||
events: this.events,
|
events: this.events,
|
||||||
normalizeInput: this.normalizeInput,
|
|
||||||
silent: this.logger.logLevel !== 'trace',
|
silent: this.logger.logLevel !== 'trace',
|
||||||
exitCallback: this.processEnded.bind(this)
|
exitCallback: this.processEnded.bind(this)
|
||||||
});
|
});
|
||||||
|
@ -41,9 +40,13 @@ class BlockchainProcessLauncher {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.blockchainProcess.once('result', constants.blockchain.blockchainReady, () => {
|
this.blockchainProcess.once('result', constants.blockchain.blockchainReady, () => {
|
||||||
this.logger.info('Blockchain node is ready'.cyan);
|
this.logger.info(__('Blockchain node is ready').cyan);
|
||||||
this.events.emit(constants.blockchain.blockchainReady);
|
this.events.emit(constants.blockchain.blockchainReady);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.events.on('exit', () => {
|
||||||
|
this.blockchainProcess.send('exit');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
const child_process = require('child_process');
|
||||||
|
const ProcessWrapper = require('../../process/processWrapper');
|
||||||
|
const constants = require('../../constants');
|
||||||
|
|
||||||
|
let ipfsProcess; // eslint-disable-line no-unused-vars
|
||||||
|
|
||||||
|
class IPFSProcess extends ProcessWrapper {
|
||||||
|
constructor(_options) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.checkIPFSVersion();
|
||||||
|
this.startIPFSDaemon();
|
||||||
|
}
|
||||||
|
|
||||||
|
checkIPFSVersion() {
|
||||||
|
child_process.exec('ipfs --version', {silent: true}, (err, stdout, _stderr) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const match = stdout.match(/[0-9]+\.[0-9]+\.[0-9]+/);
|
||||||
|
if (match[0]) {
|
||||||
|
const versions = match[0].split('.');
|
||||||
|
if (versions[0] <= 0 && versions[1] <= 4 && versions[2] <= 14) {
|
||||||
|
console.error(`You are using IPFS version ${match[0]} which has an issue with processes.`);
|
||||||
|
console.error(`Please update to IPFS version 0.4.15 or more recent: https://github.com/ipfs/ipfs-update`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
startIPFSDaemon() {
|
||||||
|
const self = this;
|
||||||
|
this.child = child_process.spawn('ipfs', ['daemon']);
|
||||||
|
|
||||||
|
this.child.on('error', (err) => {
|
||||||
|
err = err.toString();
|
||||||
|
console.error('IPFS error: ', err);
|
||||||
|
});
|
||||||
|
this.child.stderr.on('data', (data) => {
|
||||||
|
data = data.toString();
|
||||||
|
console.log(`IPFS error: ${data}`);
|
||||||
|
});
|
||||||
|
this.child.stdout.on('data', (data) => {
|
||||||
|
data = data.toString();
|
||||||
|
if (!self.readyCalled && data.indexOf('Daemon is ready') > -1) {
|
||||||
|
self.readyCalled = true;
|
||||||
|
self.send({result: constants.storage.initiated});
|
||||||
|
}
|
||||||
|
console.log('IPFS: ' + data);
|
||||||
|
});
|
||||||
|
this.child.on('exit', (code) => {
|
||||||
|
if (code) {
|
||||||
|
console.error('IPFS exited with error code ' + code);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
kill() {
|
||||||
|
if (this.child) {
|
||||||
|
this.child.kill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
process.on('message', (msg) => {
|
||||||
|
if (msg === 'exit') {
|
||||||
|
return ipfsProcess.kill();
|
||||||
|
}
|
||||||
|
if (msg.action === constants.storage.init) {
|
||||||
|
ipfsProcess = new IPFSProcess(msg.options);
|
||||||
|
}
|
||||||
|
});
|
|
@ -0,0 +1,63 @@
|
||||||
|
const fs = require('../../core/fs');
|
||||||
|
const utils = require('../../utils/utils');
|
||||||
|
const ProcessLauncher = require('../../process/processLauncher');
|
||||||
|
const constants = require('../../constants');
|
||||||
|
|
||||||
|
class StorageProcessesLauncher {
|
||||||
|
constructor(options) {
|
||||||
|
this.logger = options.logger;
|
||||||
|
this.events = options.events;
|
||||||
|
this.storageConfig = options.storageConfig;
|
||||||
|
this.webServerConfig = options.webServerConfig;
|
||||||
|
this.processes = {};
|
||||||
|
|
||||||
|
this.events.on('exit', () => {
|
||||||
|
Object.keys(this.processes).forEach(processName => {
|
||||||
|
this.processes[processName].send('exit');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
processExited(storageName, code) {
|
||||||
|
this.logger.error(__(`Storage process for ${storageName} ended before the end of this process. Code: ${code}`));
|
||||||
|
}
|
||||||
|
|
||||||
|
launchProcess(storageName, callback) {
|
||||||
|
const self = this;
|
||||||
|
if (self.processes[storageName]) {
|
||||||
|
return callback(__('Storage process already started'));
|
||||||
|
}
|
||||||
|
const filePath = utils.joinPath(__dirname, `./${storageName}.js`);
|
||||||
|
fs.access(filePath, (err) => {
|
||||||
|
if (err) {
|
||||||
|
return callback(__('No process file for this storage type exists. Please start the process locally.'));
|
||||||
|
}
|
||||||
|
self.logger.info(__(`Starting ${storageName} process`).cyan);
|
||||||
|
self.processes[storageName] = new ProcessLauncher({
|
||||||
|
modulePath: filePath,
|
||||||
|
logger: self.logger,
|
||||||
|
events: self.events,
|
||||||
|
silent: true,
|
||||||
|
exitCallback: self.processExited.bind(this, storageName)
|
||||||
|
});
|
||||||
|
self.processes[storageName].send({
|
||||||
|
action: constants.blockchain.init, options: {
|
||||||
|
storageConfig: self.storageConfig,
|
||||||
|
webServerConfig: self.webServerConfig
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
self.processes[storageName].on('result', constants.storage.initiated, (msg) => {
|
||||||
|
if (msg.error) {
|
||||||
|
self.processes[storageName].disconnect();
|
||||||
|
delete self.processes[storageName];
|
||||||
|
return callback(msg.error);
|
||||||
|
}
|
||||||
|
self.logger.info(__(`${storageName} process started`).cyan);
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = StorageProcessesLauncher;
|
|
@ -0,0 +1,75 @@
|
||||||
|
const child_process = require('child_process');
|
||||||
|
const ProcessWrapper = require('../../process/processWrapper');
|
||||||
|
const constants = require('../../constants');
|
||||||
|
const fs = require('../../core/fs');
|
||||||
|
|
||||||
|
let swarmProcess;
|
||||||
|
|
||||||
|
class SwarmProcess extends ProcessWrapper {
|
||||||
|
constructor(options) {
|
||||||
|
super();
|
||||||
|
this.storageConfig = options.storageConfig;
|
||||||
|
this.webServerConfig = options.webServerConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
startSwarmDaemon() {
|
||||||
|
const self = this;
|
||||||
|
if (!this.storageConfig.account || !this.storageConfig.account.address || !this.storageConfig.account.password) {
|
||||||
|
return 'Account address and password are needed in the storage config to start the Swarm process';
|
||||||
|
}
|
||||||
|
let corsDomain = 'http://localhost:8000';
|
||||||
|
if (self.webServerConfig && self.webServerConfig && self.webServerConfig.host && self.webServerConfig.port) {
|
||||||
|
corsDomain = `http://${self.webServerConfig.host}:${self.webServerConfig.port}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const args = [
|
||||||
|
`--bzzaccount=${this.storageConfig.account.address}`,
|
||||||
|
`--password=${fs.dappPath(this.storageConfig.account.password)}`,
|
||||||
|
`--corsdomain=${corsDomain}`
|
||||||
|
];
|
||||||
|
this.child = child_process.spawn(this.storageConfig.swarmPath || 'swarm', args);
|
||||||
|
|
||||||
|
this.child.on('error', (err) => {
|
||||||
|
err = err.toString();
|
||||||
|
console.error('Swarm error: ', err);
|
||||||
|
});
|
||||||
|
this.child.stdout.on('data', (data) => {
|
||||||
|
data = data.toString();
|
||||||
|
console.log(`Swarm error: ${data}`);
|
||||||
|
});
|
||||||
|
// Swarm logs appear in stderr somehow
|
||||||
|
this.child.stderr.on('data', (data) => {
|
||||||
|
data = data.toString();
|
||||||
|
if (!self.readyCalled && data.indexOf('Swarm http proxy started') > -1) {
|
||||||
|
self.readyCalled = true;
|
||||||
|
self.send({result: constants.storage.initiated});
|
||||||
|
}
|
||||||
|
console.log('Swarm: ' + data);
|
||||||
|
});
|
||||||
|
this.child.on('exit', (code) => {
|
||||||
|
if (code) {
|
||||||
|
console.error('Swarm exited with error code ' + code);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
kill() {
|
||||||
|
if (this.child) {
|
||||||
|
this.child.kill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
process.on('message', (msg) => {
|
||||||
|
if (msg === 'exit') {
|
||||||
|
return swarmProcess.kill();
|
||||||
|
}
|
||||||
|
if (msg.action === constants.storage.init) {
|
||||||
|
swarmProcess = new SwarmProcess(msg.options);
|
||||||
|
const error = swarmProcess.startSwarmDaemon();
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
swarmProcess.send({result: constants.storage.initiated, error});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue