add support for null inputs and fallback and constructor types

Signed-off-by: VoR0220 <catalanor0220@gmail.com>
This commit is contained in:
VoR0220 2018-06-12 10:31:26 -05:00
parent 0ff39f48b3
commit 57f098239d
2 changed files with 10 additions and 5 deletions

View File

@ -23,10 +23,15 @@ class GasEstimator {
async.each(contract.abiDefinition, async.each(contract.abiDefinition,
(abiMethod, gasCb) => { (abiMethod, gasCb) => {
let name = abiMethod.name; let name = abiMethod.name;
console.log("NAME: ", name);
console.log("ABI INPUTS: ", abiMethod.inputs);
if (abiMethod.type === "constructor") { if (abiMethod.type === "constructor") {
// already provided for us // already provided for us
gasCb(null, 'constructor', contract.gasEstimates.creation.totalCost); gasCb(null, 'constructor', contract.gasEstimates.creation.totalCost.toString());
} else if (abiMethod.inputs === []) { } else if (abiMethod.type === "fallback") {
gasCb(null, 'fallback', contract.gasEstimates.external[""].toString());
} else if (abiMethod.inputs === null || abiMethod.inputs === undefined || abiMethod.inputs.length === 0) {
console.log("Are we hitting here");
// just run it and register it // just run it and register it
contractObj.methods[name] contractObj.methods[name]
.apply(contractObj.methods[name], []) .apply(contractObj.methods[name], [])
@ -46,7 +51,7 @@ class GasEstimator {
}, (err, variance) => { }, (err, variance) => {
if (err) { if (err) {
gasCb(err) gasCb(err)
} else if (variance.reduce(_.isEqual, variance[2])) { } else if (_.isEqual(variance[0], variance[1]) && _.isEqual(variance[1], variance[2])) {
gasMap[name] = variance[0]; gasMap[name] = variance[0];
} else { } else {
gasMap[name] = 'variable'; gasMap[name] = 'variable';

View File

@ -21,10 +21,10 @@ class Profiler {
console.log("Abi Method Gastimate: ", gastimates[abiMethod.name]); console.log("Abi Method Gastimate: ", gastimates[abiMethod.name]);
switch(abiMethod.type) { switch(abiMethod.type) {
case "constructor": case "constructor":
table.addRow("constructor", abiMethod.payable, abiMethod.stateMutability, this.formatParams(abiMethod.inputs), this.formatParams(abiMethod.outputs), gastimates['constructor']); table.addRow("constructor", abiMethod.payable, abiMethod.stateMutability, self.formatParams(abiMethod.inputs), self.formatParams(abiMethod.outputs), gastimates['constructor']);
break; break;
default: default:
table.addRow(abiMethod.name, abiMethod.payable, abiMethod.stateMutability, this.formatParams(abiMethod.inputs), this.formatParams(abiMethod.outputs), gastimates[abiMethod.name]); table.addRow(abiMethod.name, abiMethod.payable, abiMethod.stateMutability, self.formatParams(abiMethod.inputs), self.formatParams(abiMethod.outputs), gastimates[abiMethod.name]);
} }
}); });
self.logger.info(table.toString()); self.logger.info(table.toString());