embark/lib/modules/blockchain_process/blockchainProcessLauncher.js

63 lines
2.0 KiB
JavaScript
Raw Normal View History

2018-07-27 21:33:50 +00:00
const ProcessLauncher = require('../../core/processes/processLauncher');
2018-07-20 12:21:23 +00:00
const utils = require('../../utils/utils.js');
const constants = require('../../constants');
2018-05-22 21:34:54 +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
}
processEnded(code) {
this.logger.error(__('Blockchain process ended before the end of this process. Try running blockchain in a separate process using `$ embark blockchain`. Code: %s', code));
}
2018-05-22 21:34:54 +00:00
startBlockchainNode() {
2018-05-28 15:54:31 +00:00
this.logger.info(__('Starting Blockchain node in another process').cyan);
2018-05-22 21:34:54 +00:00
this.blockchainProcess = new ProcessLauncher({
2018-07-20 14:12:57 +00:00
modulePath: utils.joinPath(__dirname, './blockchainProcess.js'),
2018-05-22 21:34:54 +00:00
logger: this.logger,
events: this.events,
silent: this.logger.logLevel !== 'trace',
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, () => {
2018-05-28 15:54:31 +00:00
this.logger.info(__('Blockchain node is ready').cyan);
this.events.emit(constants.blockchain.blockchainReady);
2018-05-22 21:34:54 +00:00
});
2018-05-30 14:52:15 +00:00
this.blockchainProcess.once('result', constants.blockchain.blockchainExit, () => {
// telle everyone that our blockchain process (ie geth) died
this.events.emit(constants.blockchain.blockchainExit);
// then kill off the blockchain process
this.blockchainProcess.kill();
});
2018-05-30 14:52:15 +00:00
this.events.on('exit', () => {
this.blockchainProcess.send('exit');
});
2018-05-22 21:34:54 +00:00
}
}
module.exports = BlockchainProcessLauncher;