embark/lib/cmds/blockchain/blockchainProcess.js

48 lines
1.2 KiB
JavaScript
Raw Normal View History

const ProcessWrapper = require('../../process/processWrapper');
const BlockchainClient = require('./blockchain');
const i18n = require('../../i18n/i18n.js');
2018-05-22 18:13:56 +00:00
const constants = require('../../constants');
let blockchainProcess;
class BlockchainProcess extends ProcessWrapper {
constructor(options) {
super();
this.blockchainConfig = options.blockchainConfig;
this.client = options.client;
this.env = options.env;
this.isDev = options.isDev;
i18n.setOrDetectLocale(options.locale);
2018-05-22 18:13:56 +00:00
this.blockchainConfig.silent = true;
this.blockchain = BlockchainClient(
this.blockchainConfig,
this.client,
this.env,
this.isDev,
this.blockchainReady.bind(this)
);
this.blockchain.run();
}
2018-05-22 18:13:56 +00:00
blockchainReady() {
blockchainProcess.send({result: constants.blockchain.blockchainReady});
}
2018-05-30 14:52:15 +00:00
kill() {
this.blockchain.kill();
}
}
process.on('message', (msg) => {
2018-05-30 14:52:15 +00:00
if (msg === 'exit') {
return blockchainProcess.kill();
}
2018-05-22 18:13:56 +00:00
if (msg.action === constants.blockchain.init) {
blockchainProcess = new BlockchainProcess(msg.options);
return blockchainProcess.send({result: constants.blockchain.initiated});
}
});