mirror of https://github.com/embarklabs/embark.git
update solidity module to use compileStandard and the standard json
This commit is contained in:
parent
5c5ef44f2f
commit
7a7330e695
|
@ -26,7 +26,7 @@ class Solidity {
|
|||
}
|
||||
|
||||
file.content(function(fileContent) {
|
||||
input[filename] = fileContent;
|
||||
input[filename] = {content: fileContent};
|
||||
fileCb();
|
||||
});
|
||||
},
|
||||
|
@ -49,13 +49,30 @@ class Solidity {
|
|||
},
|
||||
function compileContracts(callback) {
|
||||
self.logger.info("compiling contracts...");
|
||||
solcW.compile({sources: input}, 1, function (output) {
|
||||
let jsonObj = {
|
||||
language: 'Solidity',
|
||||
sources: input,
|
||||
settings: {
|
||||
optimizer: {
|
||||
enabled: true,
|
||||
runs: 200
|
||||
},
|
||||
outputSelection: {
|
||||
'*': {
|
||||
'*': ['abi', 'metadata', 'userdoc', 'devdoc', 'evm.legacyAssembly', 'evm.bytecode', 'evm.deployedBytecode', 'evm.methodIdentifiers', 'evm.gasEstimates']
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
solcW.compile(jsonObj, function (output) {
|
||||
if (output.errors) {
|
||||
for (let i=0; i<output.errors.length; i++) {
|
||||
if (output.errors[i].indexOf('Warning:') >= 0) {
|
||||
if (output.errors[i].type === 'Warning') {
|
||||
self.logger.warn(output.errors[i].formattedMessage);
|
||||
//return callback(new Error("Solidity errors: " + output.errors).message);
|
||||
}
|
||||
if (output.errors[i].indexOf('Error:') >= 0) {
|
||||
if (output.errors[i].type === 'Error') {
|
||||
return callback(new Error("Solidity errors: " + output.errors).message);
|
||||
}
|
||||
}
|
||||
|
@ -77,26 +94,23 @@ class Solidity {
|
|||
|
||||
let compiled_object = {};
|
||||
|
||||
for (let contractName in json) {
|
||||
let contract = json[contractName];
|
||||
for (let contractFile in json) {
|
||||
for (let contractName in json[contractFile]) {
|
||||
let contract = json[contractFile][contractName];
|
||||
|
||||
// Pull out filename:classname
|
||||
// [0] filename:classname
|
||||
// [1] filename
|
||||
// [2] classname
|
||||
const regex = /(.*):(.*)/;
|
||||
const className = contractName.match(regex)[2];
|
||||
const filename = contractName.match(regex)[1];
|
||||
const className = contractName;
|
||||
const filename = contractFile;
|
||||
|
||||
compiled_object[className] = {};
|
||||
compiled_object[className].code = contract.bytecode;
|
||||
compiled_object[className].runtimeBytecode = contract.runtimeBytecode;
|
||||
compiled_object[className].realRuntimeBytecode = contract.runtimeBytecode.slice(0, -68);
|
||||
compiled_object[className].swarmHash = contract.runtimeBytecode.slice(-68).slice(0, 64);
|
||||
compiled_object[className].gasEstimates = contract.gasEstimates;
|
||||
compiled_object[className].functionHashes = contract.functionHashes;
|
||||
compiled_object[className].abiDefinition = JSON.parse(contract.interface);
|
||||
compiled_object[className].filename = filename;
|
||||
compiled_object[className] = {};
|
||||
compiled_object[className].code = contract.evm.bytecode.object;
|
||||
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);
|
||||
compiled_object[className].gasEstimates = contract.evm.gasEstimates;
|
||||
compiled_object[className].functionHashes = contract.evm.methodIdentifiers;
|
||||
compiled_object[className].abiDefinition = contract.abi;
|
||||
compiled_object[className].filename = filename;
|
||||
}
|
||||
}
|
||||
|
||||
callback(null, compiled_object);
|
||||
|
|
|
@ -7,7 +7,8 @@ process.on('message', function (msg) {
|
|||
}
|
||||
|
||||
if (msg.action === 'compile') {
|
||||
let output = solc.compile(msg.obj, msg.optimize);
|
||||
// TODO: only available in 0.4.11; need to make versions warn about this
|
||||
let output = solc.compileStandardWrapper(JSON.stringify(msg.jsonObj));
|
||||
process.send({result: "compilation", output: output});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -44,14 +44,14 @@ class SolcW {
|
|||
return (compilerLoaded === true);
|
||||
}
|
||||
|
||||
compile(obj, optimize, done) {
|
||||
compile(jsonObj, done) {
|
||||
solcProcess.once('message', function (msg) {
|
||||
if (msg.result !== 'compilation') {
|
||||
return;
|
||||
}
|
||||
done(msg.output);
|
||||
done(JSON.parse(msg.output));
|
||||
});
|
||||
solcProcess.send({action: 'compile', obj: obj, optimize: optimize});
|
||||
solcProcess.send({action: 'compile', jsonObj: jsonObj});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue