From 1b96fbf451679922825024093a210a1d75cbaf93 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 1 Aug 2018 14:10:02 -0400 Subject: [PATCH] use json in table generation --- lib/modules/profiler/index.js | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/lib/modules/profiler/index.js b/lib/modules/profiler/index.js index 400ba13f..65d837b4 100644 --- a/lib/modules/profiler/index.js +++ b/lib/modules/profiler/index.js @@ -15,23 +15,16 @@ class Profiler { profile(contractName, contract, callback) { const self = this; - let table = new asciiTable(contractName); - table.setHeading('Function', 'Payable', 'Mutability', 'Inputs', 'Outputs', 'Gas Estimates'); - self.gasEstimator.estimateGas(contractName, function(err, gastimates, name) { + + this.profileJSON(contractName, contract, (err, profileObj) => { if (err) { return callback(null, "error found in method: " + name + " error: " + JSON.stringify(err)); } - contract.abiDefinition.forEach((abiMethod) => { - switch(abiMethod.type) { - case "constructor": - table.addRow("constructor", abiMethod.payable, abiMethod.stateMutability, self.formatParams(abiMethod.inputs), self.formatParams(abiMethod.outputs), gastimates['constructor']); - break; - case "fallback": - table.addRow("fallback", abiMethod.payable, abiMethod.stateMutability, self.formatParams(abiMethod.inputs), self.formatParams(abiMethod.outputs), gastimates['fallback']); - break; - default: - table.addRow(abiMethod.name, abiMethod.payable, abiMethod.stateMutability, self.formatParams(abiMethod.inputs), self.formatParams(abiMethod.outputs), gastimates[abiMethod.name]); - } + + let table = new asciiTable(contractName); + table.setHeading('Function', 'Payable', 'Mutability', 'Inputs', 'Outputs', 'Gas Estimates'); + profileObj.methods.forEach((method) => { + table.addRow(method.name, method.payable, method.mutability, method.inputs, method.outputs, method.gasEstimates); }); callback(null, table.toString()); }); @@ -77,12 +70,11 @@ class Profiler { '/embark-api/profiler/:contractName', (req, res) => { let contractName = req.params.contractName; - //self.events.request('contracts:contract', req.params.contractName, res.send.bind(res)); self.events.request('contracts:contract', contractName, (contract) => { if (!contract || !contract.deployedAddress) { return res.send({error: "-- couldn't profile " + contractName + " - it's not deployed or could be an interface"}); } - self.profileJSON(contractName, contract, (err, table) => { + self.profile(contractName, contract, (err, table) => { if (err) { return res.send({error: err}); }