use json in table generation

This commit is contained in:
Iuri Matias 2018-08-01 14:10:02 -04:00
parent 2d57547778
commit 2c6f26ef04

View File

@ -15,23 +15,16 @@ class Profiler {
profile(contractName, contract, callback) { profile(contractName, contract, callback) {
const self = this; const self = this;
let table = new asciiTable(contractName);
table.setHeading('Function', 'Payable', 'Mutability', 'Inputs', 'Outputs', 'Gas Estimates'); this.profileJSON(contractName, contract, (err, profileObj) => {
self.gasEstimator.estimateGas(contractName, function(err, gastimates, name) {
if (err) { if (err) {
return callback(null, "error found in method: " + name + " error: " + JSON.stringify(err)); return callback(null, "error found in method: " + name + " error: " + JSON.stringify(err));
} }
contract.abiDefinition.forEach((abiMethod) => {
switch(abiMethod.type) { let table = new asciiTable(contractName);
case "constructor": table.setHeading('Function', 'Payable', 'Mutability', 'Inputs', 'Outputs', 'Gas Estimates');
table.addRow("constructor", abiMethod.payable, abiMethod.stateMutability, self.formatParams(abiMethod.inputs), self.formatParams(abiMethod.outputs), gastimates['constructor']); profileObj.methods.forEach((method) => {
break; table.addRow(method.name, method.payable, method.mutability, method.inputs, method.outputs, method.gasEstimates);
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]);
}
}); });
callback(null, table.toString()); callback(null, table.toString());
}); });
@ -77,12 +70,11 @@ class Profiler {
'/embark-api/profiler/:contractName', '/embark-api/profiler/:contractName',
(req, res) => { (req, res) => {
let contractName = req.params.contractName; let contractName = req.params.contractName;
//self.events.request('contracts:contract', req.params.contractName, res.send.bind(res));
self.events.request('contracts:contract', contractName, (contract) => { self.events.request('contracts:contract', contractName, (contract) => {
if (!contract || !contract.deployedAddress) { if (!contract || !contract.deployedAddress) {
return res.send({error: "-- couldn't profile " + contractName + " - it's not deployed or could be an interface"}); 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) { if (err) {
return res.send({error: err}); return res.send({error: err});
} }