2018-05-18 19:48:28 +00:00
|
|
|
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;
|
2018-05-18 19:48:28 +00:00
|
|
|
|
|
|
|
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,
|
2018-06-22 12:52:15 +00:00
|
|
|
this.blockchainReady.bind(this),
|
|
|
|
this.blockchainExit.bind(this)
|
2018-05-22 18:13:56 +00:00
|
|
|
);
|
|
|
|
|
2018-05-18 19:48:28 +00:00
|
|
|
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
|
|
|
|
2018-06-22 12:52:15 +00:00
|
|
|
blockchainExit() {
|
|
|
|
// tell our parent process that geth has exited
|
|
|
|
blockchainProcess.send({result: constants.blockchain.blockchainExit});
|
|
|
|
}
|
|
|
|
|
2018-05-30 14:52:15 +00:00
|
|
|
kill() {
|
|
|
|
this.blockchain.kill();
|
|
|
|
}
|
2018-05-18 19:48:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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});
|
2018-05-18 19:48:28 +00:00
|
|
|
}
|
|
|
|
});
|