2017-12-16 20:39:30 +00:00
|
|
|
let utils = require('../../utils/utils.js');
|
2018-04-02 19:06:56 +00:00
|
|
|
let fs = require('../../core/fs.js');
|
2017-12-16 20:39:30 +00:00
|
|
|
let currentSolcVersion = require('../../../package.json').dependencies.solc;
|
2018-07-27 21:33:50 +00:00
|
|
|
const ProcessLauncher = require('../../core/processes/processLauncher.js');
|
2018-05-31 17:32:02 +00:00
|
|
|
const uuid = require('uuid/v1');
|
2017-02-25 00:27:27 +00:00
|
|
|
|
2017-03-30 11:12:39 +00:00
|
|
|
class SolcW {
|
2017-02-25 00:27:27 +00:00
|
|
|
|
Process logs API refactor
There are three separate instances of process log APIs: embark logs, blockchain logs (when in standalone mode), and child process logs (storage, communication, blockchain, etc). Each one was repeating the implementation of creating a process log API endpoint. This commit centralises the API declaration by using the class `ProcessLogsApi`.
`ProcessLogsApi` is started for all three components mentioned above: blockchain (in standalone) in the `BlockchainListener` module, embark in the `EmbarkListener` module, and for all child processes in the `ProcessLauncher`.
These listeners have two functions:
1. Create the process logs API endpoints for `get` and `ws`, and
2. Ensure that all logs are logged through the `LogHandler`, which normalises the output of the log and ensures each log has a timestamp and id (used in the cockpit for log ordering).
Also, this commit moved the pipeline in to a module, so that the `embark` object could be passed to the `ProcessLogsApi` (to be used for registering API endpoints).
2018-10-24 05:54:09 +00:00
|
|
|
constructor(embark, options) {
|
|
|
|
this.embark = embark;
|
2017-07-05 22:26:44 +00:00
|
|
|
this.logger = options.logger;
|
2017-12-30 21:48:53 +00:00
|
|
|
this.events = options.events;
|
2018-06-04 19:36:43 +00:00
|
|
|
this.ipc = options.ipc;
|
2018-05-16 22:09:56 +00:00
|
|
|
this.compilerLoaded = false;
|
|
|
|
this.solcProcess = null;
|
2018-06-14 23:37:52 +00:00
|
|
|
this.useDashboard = options.useDashboard;
|
2017-07-05 12:35:51 +00:00
|
|
|
}
|
|
|
|
|
2017-03-30 11:12:39 +00:00
|
|
|
load_compiler(done) {
|
2017-12-30 21:48:53 +00:00
|
|
|
const self = this;
|
2018-06-05 20:13:17 +00:00
|
|
|
if (!self.ipc.isClient()) {
|
|
|
|
return self.load_compiler_internally(done);
|
2018-06-04 17:12:51 +00:00
|
|
|
}
|
2018-06-04 22:15:27 +00:00
|
|
|
|
2018-08-23 16:54:43 +00:00
|
|
|
if (self.ipc.connected) {
|
|
|
|
self.compilerLoaded = true;
|
|
|
|
return done();
|
|
|
|
}
|
2018-06-05 20:13:17 +00:00
|
|
|
self.ipc.connect((err) => {
|
|
|
|
if (err) {
|
|
|
|
return self.load_compiler_internally(done);
|
|
|
|
}
|
|
|
|
self.compilerLoaded = true;
|
|
|
|
done();
|
|
|
|
});
|
2018-06-04 22:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
load_compiler_internally(done) {
|
|
|
|
const self = this;
|
2018-05-16 22:09:56 +00:00
|
|
|
if (this.compilerLoaded) {
|
2018-05-18 18:22:58 +00:00
|
|
|
return done();
|
2017-02-25 03:49:34 +00:00
|
|
|
}
|
2018-05-16 22:09:56 +00:00
|
|
|
this.solcProcess = new ProcessLauncher({
|
Process logs API refactor
There are three separate instances of process log APIs: embark logs, blockchain logs (when in standalone mode), and child process logs (storage, communication, blockchain, etc). Each one was repeating the implementation of creating a process log API endpoint. This commit centralises the API declaration by using the class `ProcessLogsApi`.
`ProcessLogsApi` is started for all three components mentioned above: blockchain (in standalone) in the `BlockchainListener` module, embark in the `EmbarkListener` module, and for all child processes in the `ProcessLauncher`.
These listeners have two functions:
1. Create the process logs API endpoints for `get` and `ws`, and
2. Ensure that all logs are logged through the `LogHandler`, which normalises the output of the log and ensures each log has a timestamp and id (used in the cockpit for log ordering).
Also, this commit moved the pipeline in to a module, so that the `embark` object could be passed to the `ProcessLogsApi` (to be used for registering API endpoints).
2018-10-24 05:54:09 +00:00
|
|
|
embark: self.embark,
|
2018-05-16 22:09:56 +00:00
|
|
|
modulePath: utils.joinPath(__dirname, 'solcP.js'),
|
|
|
|
logger: self.logger,
|
2018-07-20 18:28:46 +00:00
|
|
|
events: self.events,
|
|
|
|
silent: false
|
2018-05-16 22:09:56 +00:00
|
|
|
});
|
|
|
|
|
2018-06-13 13:16:54 +00:00
|
|
|
this.solcProcess.once("result", "initiated", () => {
|
|
|
|
this.events.request("version:get:solc", function(solcVersion) {
|
|
|
|
if (solcVersion === currentSolcVersion) {
|
2018-06-14 23:37:52 +00:00
|
|
|
return self.solcProcess.send({action: 'loadCompiler', requirePath: 'solc'});
|
|
|
|
}
|
|
|
|
self.events.request("version:getPackagePath", "solc", solcVersion, function(err, path) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
let requirePath = fs.dappPath(path);
|
|
|
|
self.solcProcess.send({action: 'installAndLoadCompiler', solcVersion: solcVersion, packagePath: requirePath});
|
|
|
|
});
|
2018-06-13 13:16:54 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.solcProcess.once("result", "loadedCompiler", () => {
|
2018-05-16 22:09:56 +00:00
|
|
|
self.compilerLoaded = true;
|
2017-03-30 11:12:39 +00:00
|
|
|
done();
|
|
|
|
});
|
2018-10-16 15:16:47 +00:00
|
|
|
|
2018-06-14 23:37:52 +00:00
|
|
|
this.solcProcess.send({action: "init", options: {logger: self.logger, showSpinner: !self.useDashboard}});
|
2018-06-13 13:16:54 +00:00
|
|
|
|
2018-06-04 22:15:27 +00:00
|
|
|
if (this.ipc.isServer()) {
|
|
|
|
this.ipc.on('compile', self.compile.bind(this));
|
|
|
|
}
|
2017-03-30 11:12:39 +00:00
|
|
|
}
|
2017-02-25 03:49:34 +00:00
|
|
|
|
2017-03-30 11:12:39 +00:00
|
|
|
isCompilerLoaded() {
|
2018-05-16 22:09:56 +00:00
|
|
|
return (this.compilerLoaded === true);
|
2017-03-30 11:12:39 +00:00
|
|
|
}
|
2017-02-25 20:47:35 +00:00
|
|
|
|
2018-01-27 20:07:48 +00:00
|
|
|
compile(jsonObj, done) {
|
2018-05-31 17:32:02 +00:00
|
|
|
const id = uuid();
|
2018-06-04 17:12:51 +00:00
|
|
|
|
2018-06-04 22:15:27 +00:00
|
|
|
if (this.ipc.isClient() && this.ipc.connected) {
|
2018-06-04 20:39:31 +00:00
|
|
|
return this.ipc.request('compile', jsonObj, done);
|
2018-06-04 17:12:51 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 17:32:02 +00:00
|
|
|
this.solcProcess.once('result', 'compilation-' + id, (msg) => {
|
2018-06-14 08:09:02 +00:00
|
|
|
if(msg.err) {
|
|
|
|
return done(msg.err);
|
|
|
|
}
|
|
|
|
done(null, JSON.parse(msg.output));
|
2017-03-30 11:12:39 +00:00
|
|
|
});
|
2018-05-16 22:09:56 +00:00
|
|
|
|
2018-05-31 17:32:02 +00:00
|
|
|
this.solcProcess.send({action: 'compile', jsonObj: jsonObj, id});
|
2017-03-30 11:12:39 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-25 00:27:27 +00:00
|
|
|
|
|
|
|
module.exports = SolcW;
|
|
|
|
|