diff --git a/lib/config.es6 b/lib/config.es6 index 88c8931552c..86ea10db32f 100644 --- a/lib/config.es6 +++ b/lib/config.es6 @@ -54,6 +54,7 @@ var Config = { } }, contracts: { + filenames: {}, classes: {}, directory: `${working_dir}/contracts`, build_directory: null @@ -215,9 +216,18 @@ var Config = { for (file of filesSync(config.contracts.directory)) { var name = file.substring(file.lastIndexOf("/") + 1, file.lastIndexOf(".")); var relative_path = file.replace(config.working_dir, "./"); - config.contracts.classes[name] = { + config.contracts.filenames[name] = { source: relative_path } + var code = fs.readFileSync(file, {encoding: "utf8"}); + var myRegex = /contract\s([a-zA-Z0-9_\-]+)/g; + var match = myRegex.exec(code); + while (match != null){ + config.contracts.classes[match[1]] = { + source: "./" + match[1] + ".sol" + } + match = myRegex.exec(code); + } } } diff --git a/lib/contracts.es6 b/lib/contracts.es6 index 15abb11f0d1..1bfc1ce6094 100644 --- a/lib/contracts.es6 +++ b/lib/contracts.es6 @@ -115,10 +115,10 @@ var Contracts = { compile_all(config, callback) { var sources = {}; - var contracts = Object.keys(config.contracts.classes); + var contracts = Object.keys(config.contracts.filenames); for (var i = 0; i < contracts.length; i++) { var key = contracts[i]; - var contract = config.contracts.classes[key]; + var contract = config.contracts.filenames[key]; var source = contract.source.replace("./contracts/", ""); var full_path = path.resolve(config.working_dir, contract.source) sources[source] = fs.readFileSync(full_path, {encoding: "utf8"}); @@ -131,14 +131,14 @@ var Contracts = { return; } - var compiled_contract = result.contracts[key]; - - for (var i = 0; i < contracts.length; i++) { - var key = contracts[i]; - var contract = config.contracts.classes[key]; - var compiled_contract = result.contracts[key]; - contract["binary"] = compiled_contract.bytecode; - contract["abi"] = JSON.parse(compiled_contract.interface); + for (var contractKey in result.contracts){ + if(result.contracts.hasOwnProperty(contractKey)){ + config.contracts.classes[contractKey] = { + source: "./" + contractKey + ".sol", + binary: result.contracts[contractKey].bytecode, + abi: JSON.parse(result.contracts[contractKey].interface) + } + } } callback();