embark/lib/contracts/solcW.js

37 lines
870 B
JavaScript
Raw Normal View History

2017-03-01 21:15:02 -05:00
var utils = require('../core/utils.js');
var solcProcess;
var compilerLoaded = false;
2017-02-24 19:27:27 -05:00
var SolcW = function() {
};
SolcW.prototype.load_compiler = function(done) {
if (compilerLoaded) { done(); }
2017-03-01 21:15:02 -05:00
solcProcess = require('child_process').fork(utils.joinPath(__dirname, '/solcP.js'));
solcProcess.once('message', function(msg) {
2017-02-24 22:49:34 -05:00
if (msg.result !== 'loadedCompiler') {
return;
}
compilerLoaded = true;
2017-02-24 22:49:34 -05:00
done();
});
solcProcess.send({action: 'loadCompiler'});
};
SolcW.prototype.isCompilerLoaded = function() {
return (compilerLoaded === true);
};
2017-02-24 22:49:34 -05:00
SolcW.prototype.compile = function(obj, optimize, done) {
solcProcess.once('message', function(msg) {
2017-02-24 22:49:34 -05:00
if (msg.result !== 'compilation') {
return;
}
done(msg.output);
});
2017-02-25 23:20:57 -05:00
solcProcess.send({action: 'compile', obj: obj, optimize: optimize});
2017-02-24 19:27:27 -05:00
};
module.exports = SolcW;