mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-09 13:36:14 +00:00
f5c77b1416
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).
102 lines
2.7 KiB
JavaScript
102 lines
2.7 KiB
JavaScript
let utils = require('../../utils/utils.js');
|
|
let fs = require('../../core/fs.js');
|
|
let currentSolcVersion = require('../../../package.json').dependencies.solc;
|
|
const ProcessLauncher = require('../../core/processes/processLauncher.js');
|
|
const uuid = require('uuid/v1');
|
|
|
|
class SolcW {
|
|
|
|
constructor(embark, options) {
|
|
this.embark = embark;
|
|
this.logger = options.logger;
|
|
this.events = options.events;
|
|
this.ipc = options.ipc;
|
|
this.compilerLoaded = false;
|
|
this.solcProcess = null;
|
|
this.useDashboard = options.useDashboard;
|
|
}
|
|
|
|
load_compiler(done) {
|
|
const self = this;
|
|
if (!self.ipc.isClient()) {
|
|
return self.load_compiler_internally(done);
|
|
}
|
|
|
|
if (self.ipc.connected) {
|
|
self.compilerLoaded = true;
|
|
return done();
|
|
}
|
|
self.ipc.connect((err) => {
|
|
if (err) {
|
|
return self.load_compiler_internally(done);
|
|
}
|
|
self.compilerLoaded = true;
|
|
done();
|
|
});
|
|
}
|
|
|
|
load_compiler_internally(done) {
|
|
const self = this;
|
|
if (this.compilerLoaded) {
|
|
return done();
|
|
}
|
|
this.solcProcess = new ProcessLauncher({
|
|
embark: self.embark,
|
|
modulePath: utils.joinPath(__dirname, 'solcP.js'),
|
|
logger: self.logger,
|
|
events: self.events,
|
|
silent: false
|
|
});
|
|
|
|
this.solcProcess.once("result", "initiated", () => {
|
|
this.events.request("version:get:solc", function(solcVersion) {
|
|
if (solcVersion === currentSolcVersion) {
|
|
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});
|
|
});
|
|
});
|
|
});
|
|
|
|
this.solcProcess.once("result", "loadedCompiler", () => {
|
|
self.compilerLoaded = true;
|
|
done();
|
|
});
|
|
|
|
this.solcProcess.send({action: "init", options: {logger: self.logger, showSpinner: !self.useDashboard}});
|
|
|
|
if (this.ipc.isServer()) {
|
|
this.ipc.on('compile', self.compile.bind(this));
|
|
}
|
|
}
|
|
|
|
isCompilerLoaded() {
|
|
return (this.compilerLoaded === true);
|
|
}
|
|
|
|
compile(jsonObj, done) {
|
|
const id = uuid();
|
|
|
|
if (this.ipc.isClient() && this.ipc.connected) {
|
|
return this.ipc.request('compile', jsonObj, done);
|
|
}
|
|
|
|
this.solcProcess.once('result', 'compilation-' + id, (msg) => {
|
|
if(msg.err) {
|
|
return done(msg.err);
|
|
}
|
|
done(null, JSON.parse(msg.output));
|
|
});
|
|
|
|
this.solcProcess.send({action: 'compile', jsonObj: jsonObj, id});
|
|
}
|
|
}
|
|
|
|
module.exports = SolcW;
|
|
|