From 21d65e8f8c8d74f79e98bc985b625761506bb30d Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Tue, 24 Jul 2018 11:56:35 -0400 Subject: [PATCH 1/3] Add directory list to list of allowed paths --- lib/Compiler.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/Compiler.js b/lib/Compiler.js index 054e254..3f7aed4 100644 --- a/lib/Compiler.js +++ b/lib/Compiler.js @@ -3,8 +3,10 @@ const shelljs = require('shelljs'); const fs = require('fs'); const path = require('path'); -function compileSolcContract(logger, filename, callback) { - shelljs.exec(`solc --optimize --combined-json abi,bin,bin-runtime,compact-format,hashes,interface,metadata ${filename}`, +function compileSolcContract(logger, filename, allowedDirectories, callback) { + const command = `solc --optimize --combined-json abi,bin,bin-runtime,compact-format,hashes,interface,metadata --allow-paths ${allowedDirectories.join(',')} ${filename}`; + console.log(command); + shelljs.exec(command, {silent: true}, (code, stdout, stderr) => { if (stderr) { @@ -40,11 +42,13 @@ function compileSolc(embark, contractFiles, cb) { } logger.info("compiling solidity contracts with command line solc..."); - + + const allowedDirectories = contractFiles.map((contractFile) => path.dirname(path.join(process.cwd(), contractFile.path))); + let compiled_object = {}; async.each(contractFiles, function (file, fileCb) { - compileSolcContract(logger, file.filename, (err, compileString) => { + compileSolcContract(logger, file.filename, allowedDirectories, (err, compileString) => { if (err) { return fileCb(err); } From 98890beb46ab5f97b431cc5b7f079a59ac7150f3 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Tue, 24 Jul 2018 12:05:42 -0400 Subject: [PATCH 2/3] Filtering duplicated contracts dirs --- lib/Compiler.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Compiler.js b/lib/Compiler.js index 3f7aed4..ae146d1 100644 --- a/lib/Compiler.js +++ b/lib/Compiler.js @@ -5,7 +5,6 @@ const path = require('path'); function compileSolcContract(logger, filename, allowedDirectories, callback) { const command = `solc --optimize --combined-json abi,bin,bin-runtime,compact-format,hashes,interface,metadata --allow-paths ${allowedDirectories.join(',')} ${filename}`; - console.log(command); shelljs.exec(command, {silent: true}, (code, stdout, stderr) => { @@ -43,7 +42,8 @@ function compileSolc(embark, contractFiles, cb) { logger.info("compiling solidity contracts with command line solc..."); - const allowedDirectories = contractFiles.map((contractFile) => path.dirname(path.join(process.cwd(), contractFile.path))); + const allowedDirectories = contractFiles.map((contractFile) => path.dirname(path.join(process.cwd(), contractFile.path))) + .filter((x, i, a) => a.indexOf(x) == i); let compiled_object = {}; async.each(contractFiles, From f852bf3da067017247fa3dd1ba40ad64c08daa85 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Tue, 24 Jul 2018 13:37:59 -0400 Subject: [PATCH 3/3] Added duplicated contract warning --- lib/Compiler.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/Compiler.js b/lib/Compiler.js index ae146d1..a3f2b95 100644 --- a/lib/Compiler.js +++ b/lib/Compiler.js @@ -59,16 +59,20 @@ function compileSolc(embark, contractFiles, cb) { for (let contractFile in json.contracts) { let className = contractFile.substr( contractFile.indexOf(":") + 1); - let fileName = contractFile.substr(0, contractFile.indexOf(":")); + let filename = contractFile.substr(0, contractFile.indexOf(":")); let contract = json.contracts[contractFile]; - + if(compiled_object[className] && compiled_object[className].filename != filename){ + logger.warn(`Duplicated contract '${className}' found. Using '${compiled_object[className].filename}' instead of '${file.filename}'`); + continue; + } + compiled_object[className] = {}; compiled_object[className].code = contract.bin compiled_object[className].runtimeBytecode = contract["bin-runtime"]; compiled_object[className].functionHashes = contract.hashes; compiled_object[className].abiDefinition = JSON.parse(contract.abi); - compiled_object[className].filename = fileName; + compiled_object[className].filename = filename; } fileCb();