Can specify "outputBinary" config to gen a .bin file of contract

This commit is contained in:
Richard Ramos 2018-07-23 12:37:27 -04:00
parent dadf7dcd32
commit 34b053c8cf
2 changed files with 15 additions and 3 deletions

View File

@ -7,6 +7,6 @@ module.exports = (embark) => {
if(!contractFiles || !contractFiles.length) {
return cb();
}
Compiler.compileSolc(embark.logger, contractFiles, cb);
Compiler.compileSolc(embark, contractFiles, cb);
}
};

View File

@ -1,6 +1,6 @@
const async = require('async');
const path = require('path');
const shelljs = require('shelljs');
const fs = require('fs');
function compileSolcContract(logger, filename, callback) {
shelljs.exec(`solc --optimize --combined-json abi,bin,bin-runtime,compact-format,hashes,interface,metadata ${filename}`,
@ -22,11 +22,15 @@ function compileSolcContract(logger, filename, callback) {
});
}
function compileSolc(logger, contractFiles, cb) {
function compileSolc(embark, contractFiles, cb) {
if (!contractFiles || !contractFiles.length) {
return cb();
}
const logger = embark.logger;
const outputBinary = embark.pluginConfig.outputBinary;
const outputDir = embark.config.buildDir + embark.config.contractDirectories[0];
const solc = shelljs.which('solc');
if (!solc) {
logger.warn('solc is not installed on your machine');
@ -35,6 +39,7 @@ function compileSolc(logger, contractFiles, cb) {
}
logger.info("compiling solidity contracts with command line solc...");
let compiled_object = {};
async.each(contractFiles,
function (file, fileCb) {
@ -59,6 +64,13 @@ function compileSolc(logger, contractFiles, cb) {
compiled_object[className].functionHashes = contract.hashes;
compiled_object[className].abiDefinition = JSON.parse(contract.abi);
compiled_object[className].filename = fileName;
if(outputBinary){
fs.writeFile(outputDir + className + ".bin", contract.bin, (err) => {
if (err) logger.error(err);
});
}
}
fileCb();