2017-12-16 20:39:30 +00:00
|
|
|
let utils = require('../../utils/utils.js');
|
2017-03-29 17:50:05 +00:00
|
|
|
let solcProcess;
|
|
|
|
let compilerLoaded = false;
|
2017-12-16 20:39:30 +00:00
|
|
|
let currentSolcVersion = require('../../../package.json').dependencies.solc;
|
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
|
|
|
|
2017-07-05 22:26:44 +00:00
|
|
|
constructor(options) {
|
|
|
|
this.logger = options.logger;
|
2017-12-30 21:48:53 +00:00
|
|
|
this.events = options.events;
|
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;
|
2017-03-30 11:12:39 +00:00
|
|
|
if (compilerLoaded) {
|
|
|
|
done();
|
2017-02-25 03:49:34 +00:00
|
|
|
}
|
2017-03-30 11:12:39 +00:00
|
|
|
solcProcess = require('child_process').fork(utils.joinPath(__dirname, '/solcP.js'));
|
|
|
|
solcProcess.once('message', function (msg) {
|
|
|
|
if (msg.result !== 'loadedCompiler') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
compilerLoaded = true;
|
|
|
|
done();
|
|
|
|
});
|
2017-07-05 13:12:11 +00:00
|
|
|
|
2017-12-30 21:48:53 +00:00
|
|
|
this.events.request("version:get:solc", function(solcVersion) {
|
2017-12-30 23:12:16 +00:00
|
|
|
if (solcVersion === currentSolcVersion) {
|
2017-12-30 21:48:53 +00:00
|
|
|
solcProcess.send({action: 'loadCompiler', solcLocation: 'solc'});
|
|
|
|
} else {
|
2017-12-31 00:34:15 +00:00
|
|
|
self.events.request("version:getPackageLocation", "solc", solcVersion, function(err, location) {
|
2017-12-30 21:48:53 +00:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2018-03-26 18:54:47 +00:00
|
|
|
let requirePath = utils.joinPath(utils.pwd(), location);
|
2017-12-30 21:48:53 +00:00
|
|
|
solcProcess.send({action: 'loadCompiler', solcLocation: requirePath});
|
|
|
|
});
|
2017-12-30 23:12:16 +00:00
|
|
|
|
2017-12-30 21:48:53 +00:00
|
|
|
}
|
|
|
|
});
|
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() {
|
|
|
|
return (compilerLoaded === true);
|
|
|
|
}
|
2017-02-25 20:47:35 +00:00
|
|
|
|
2018-01-27 20:07:48 +00:00
|
|
|
compile(jsonObj, done) {
|
2017-03-30 11:12:39 +00:00
|
|
|
solcProcess.once('message', function (msg) {
|
|
|
|
if (msg.result !== 'compilation') {
|
|
|
|
return;
|
|
|
|
}
|
2018-01-27 20:07:48 +00:00
|
|
|
done(JSON.parse(msg.output));
|
2017-03-30 11:12:39 +00:00
|
|
|
});
|
2018-01-27 20:07:48 +00:00
|
|
|
solcProcess.send({action: 'compile', jsonObj: jsonObj});
|
2017-03-30 11:12:39 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-25 00:27:27 +00:00
|
|
|
|
|
|
|
module.exports = SolcW;
|
|
|
|
|