embark/lib/contracts/solcW.js

36 lines
814 B
JavaScript

var solcProcess;
var compilerLoaded = false;
var SolcW = function() {
};
SolcW.prototype.load_compiler = function(done) {
if (compilerLoaded) { done(); }
solcProcess = require('child_process').fork(__dirname + '/solcP.js');
solcProcess.once('message', function(msg) {
if (msg.result !== 'loadedCompiler') {
return;
}
compilerLoaded = true;
done();
});
solcProcess.send({action: 'loadCompiler'});
};
SolcW.prototype.isCompilerLoaded = function() {
return (compilerLoaded === true);
};
SolcW.prototype.compile = function(obj, optimize, done) {
solcProcess.once('message', function(msg) {
if (msg.result !== 'compilation') {
return;
}
done(msg.output);
});
solcProcess.send({action: 'compile', obj: obj, optimize: optimize});
};
module.exports = SolcW;