From 7a7330e6952aa52ab4b537c4d39a90b7f167cc70 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sat, 27 Jan 2018 15:07:48 -0500 Subject: [PATCH] update solidity module to use compileStandard and the standard json --- lib/modules/solidity/index.js | 58 ++++++++++++++++++++++------------- lib/modules/solidity/solcP.js | 3 +- lib/modules/solidity/solcW.js | 6 ++-- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/lib/modules/solidity/index.js b/lib/modules/solidity/index.js index 178fb3215..3777b1815 100644 --- a/lib/modules/solidity/index.js +++ b/lib/modules/solidity/index.js @@ -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= 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); diff --git a/lib/modules/solidity/solcP.js b/lib/modules/solidity/solcP.js index 9444f3a89..5550c9b1f 100644 --- a/lib/modules/solidity/solcP.js +++ b/lib/modules/solidity/solcP.js @@ -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}); } }); diff --git a/lib/modules/solidity/solcW.js b/lib/modules/solidity/solcW.js index 80a0d631a..a773d05ee 100644 --- a/lib/modules/solidity/solcW.js +++ b/lib/modules/solidity/solcW.js @@ -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}); } }