use json in table generation

This commit is contained in:
Iuri Matias 2018-08-01 14:10:02 -04:00 committed by Pascal Precht
parent efbe71f5e2
commit 1b96fbf451
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
1 changed files with 8 additions and 16 deletions

View File

@ -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});
}