Skip to content

Commit

Permalink
fix(embark/compiler): fix errors and bugs with solc 0.4.18
Browse files Browse the repository at this point in the history
  • Loading branch information
jrainville authored and iurimatias committed Apr 16, 2019
1 parent eb9de68 commit bfebb3c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
33 changes: 30 additions & 3 deletions packages/embark/src/lib/modules/solidity/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,21 @@ class Solidity {

for (let contractFile in json) {
for (let contractName in json[contractFile]) {
let className = contractName;
let realContractFile = contractFile;
// This is for solc 0.4.18 which outputs weirdly
if (className.indexOf(':') > -1) {
const nameParts = className.split(':');
realContractFile += nameParts[0];
className = nameParts[nameParts.length - 1];
}
let contract = json[contractFile][contractName];

const className = contractName;
let filename = contractFile;
let filename = realContractFile;

compiled_object[className] = {};
compiled_object[className].code = contract.evm.bytecode.object;
compiled_object[className].linkReferences = contract.evm.bytecode.linkReferences;
compiled_object[className].linkReferences = self.getLinkReferences(contract.evm.bytecode.linkReferences);
compiled_object[className].runtimeBytecode = contract.evm.deployedBytecode.object;
compiled_object[className].realRuntimeBytecode = contract.evm.deployedBytecode.object.slice(0, -68);
compiled_object[className].swarmHash = contract.evm.deployedBytecode.object.slice(-68).slice(0, 64);
Expand All @@ -157,6 +164,26 @@ class Solidity {
});
}

getLinkReferences(linkReferences) {
const finalReferences = {};
for (let contractFile in linkReferences) {
for (let contractName in linkReferences[contractFile]) {
let className = contractName;
let realContractFile = contractFile;
if (className.indexOf(':') > -1) {
const nameParts = className.split(':');
realContractFile += nameParts[0];
className = nameParts[nameParts.length - 1];
}
if (!finalReferences[realContractFile]) {
finalReferences[realContractFile] = {};
}
finalReferences[realContractFile][className] = linkReferences[contractFile][contractName];
}
}
return finalReferences;
}

compile_solidity(contractFiles, options, cb) {
if (!contractFiles.length) {
return cb();
Expand Down
2 changes: 1 addition & 1 deletion packages/embark/src/lib/modules/solidity/solcP.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SolcProcess extends ProcessWrapper {
let output = func(JSON.stringify(jsonObj), this.findImports.bind(this));
cb(null, output);
} catch (err) {
cb(err.message);
cb(err.message || err);
}
}

Expand Down

0 comments on commit bfebb3c

Please sign in to comment.