2018-05-22 21:34:54 +00:00
|
|
|
const ProcessLauncher = require('../process/processLauncher');
|
|
|
|
const utils = require('../utils/utils.js');
|
|
|
|
const constants = require('../constants');
|
|
|
|
|
2018-05-23 12:40:09 +00:00
|
|
|
class BlockchainProcessLauncher {
|
2018-05-22 21:34:54 +00:00
|
|
|
|
|
|
|
constructor (options) {
|
|
|
|
this.events = options.events;
|
|
|
|
this.logger = options.logger;
|
|
|
|
this.normalizeInput = options.normalizeInput;
|
|
|
|
this.blockchainConfig = options.blockchainConfig;
|
|
|
|
this.locale = options.locale;
|
2018-05-23 15:52:07 +00:00
|
|
|
this.isDev = options.isDev;
|
2018-05-22 21:34:54 +00:00
|
|
|
}
|
|
|
|
|
2018-05-23 15:06:58 +00:00
|
|
|
processEnded(code) {
|
|
|
|
this.logger.error('Blockchain process ended before the end of this process. Code: ' + code);
|
|
|
|
}
|
|
|
|
|
2018-05-22 21:34:54 +00:00
|
|
|
startBlockchainNode() {
|
|
|
|
this.logger.info('Starting Blockchain node in another process'.cyan);
|
|
|
|
|
|
|
|
this.blockchainProcess = new ProcessLauncher({
|
|
|
|
modulePath: utils.joinPath(__dirname, '../cmds/blockchain/blockchainProcess.js'),
|
|
|
|
logger: this.logger,
|
|
|
|
events: this.events,
|
|
|
|
normalizeInput: this.normalizeInput,
|
2018-05-23 15:06:58 +00:00
|
|
|
silent: true,
|
|
|
|
exitCallback: this.processEnded.bind(this)
|
2018-05-22 21:34:54 +00:00
|
|
|
});
|
|
|
|
this.blockchainProcess.send({
|
|
|
|
action: constants.blockchain.init, options: {
|
|
|
|
blockchainConfig: this.blockchainConfig,
|
|
|
|
//client: this.client,
|
|
|
|
// TODO: assume for now it's geth
|
|
|
|
client: 'geth',
|
|
|
|
env: this.env,
|
2018-05-23 15:52:07 +00:00
|
|
|
isDev: this.isDev,
|
2018-05-22 21:34:54 +00:00
|
|
|
locale: this.locale
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.blockchainProcess.once('result', constants.blockchain.blockchainReady, () => {
|
|
|
|
this.logger.info('Blockchain node is ready'.cyan);
|
2018-05-23 12:40:09 +00:00
|
|
|
this.events.emit(constants.blockchain.blockchainReady);
|
2018-05-22 21:34:54 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-05-23 12:40:09 +00:00
|
|
|
module.exports = BlockchainProcessLauncher;
|