Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Adding support for multiple contracts in the same file to be handled correctly #86

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/config.es6
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ var Config = {
}
},
contracts: {
filenames: {},
classes: {},
directory: `${working_dir}/contracts`,
build_directory: null
Expand Down Expand Up @@ -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);
}
}
}

Expand Down
20 changes: 10 additions & 10 deletions lib/contracts.es6
Original file line number Diff line number Diff line change
Expand Up @@ -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"});
Expand All @@ -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();
Expand Down