From 57f098239d57c4e6bd4104fa2a7576100e97d6c7 Mon Sep 17 00:00:00 2001 From: VoR0220 Date: Tue, 12 Jun 2018 10:31:26 -0500 Subject: [PATCH] add support for null inputs and fallback and constructor types Signed-off-by: VoR0220 --- lib/modules/gasEstimator/index.js | 11 ++++++++--- lib/modules/profiler/index.js | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/modules/gasEstimator/index.js b/lib/modules/gasEstimator/index.js index 4eb27853..101083a4 100644 --- a/lib/modules/gasEstimator/index.js +++ b/lib/modules/gasEstimator/index.js @@ -23,10 +23,15 @@ class GasEstimator { async.each(contract.abiDefinition, (abiMethod, gasCb) => { let name = abiMethod.name; + console.log("NAME: ", name); + console.log("ABI INPUTS: ", abiMethod.inputs); if (abiMethod.type === "constructor") { // already provided for us - gasCb(null, 'constructor', contract.gasEstimates.creation.totalCost); - } else if (abiMethod.inputs === []) { + gasCb(null, 'constructor', contract.gasEstimates.creation.totalCost.toString()); + } 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 contractObj.methods[name] .apply(contractObj.methods[name], []) @@ -46,7 +51,7 @@ class GasEstimator { }, (err, variance) => { if (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]; } else { gasMap[name] = 'variable'; diff --git a/lib/modules/profiler/index.js b/lib/modules/profiler/index.js index 14b7859a..56a46fe1 100644 --- a/lib/modules/profiler/index.js +++ b/lib/modules/profiler/index.js @@ -21,10 +21,10 @@ class Profiler { console.log("Abi Method Gastimate: ", gastimates[abiMethod.name]); switch(abiMethod.type) { 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; 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());