Add gas estimation for constructor

pull/1/head
ninabreznik 7 years ago
parent 7acebca2da
commit 0b9f99affc
  1. 2
      src/app/editor/contextView.js
  2. 23
      src/app/editor/contextualListener.js

@ -173,7 +173,7 @@ class ContextView {
function showGasEstimation () { function showGasEstimation () {
var estimatedGas = self._api.contextualListener.gasEstimation(node) + ' gas' var estimatedGas = self._api.contextualListener.gasEstimation(node) + ' gas'
if (node.name === 'FunctionDefinition' && !node.attributes.isConstructor) var el = yo`<div class=${css.gasEstimation}> <img class=${css.gasStationIcon} title='Estimated gas price' src='https://png.icons8.com/gas-station/win8/50/000000'> ${estimatedGas}</div>` if (node.name === 'FunctionDefinition') var el = yo`<div class=${css.gasEstimation}> <img class=${css.gasStationIcon} title='Estimated gas price' src='https://png.icons8.com/gas-station/win8/50/000000'> ${estimatedGas}</div>`
return el return el
} }
} }

@ -92,24 +92,31 @@ class ContextualListener {
} }
_getGasEstimation (results) { _getGasEstimation (results) {
this.results = results
this.contractName = Object.keys(results.data.contracts[results.source.target])[0] this.contractName = Object.keys(results.data.contracts[results.source.target])[0]
this.target = results.data.contracts[results.source.target] this.target = results.data.contracts[results.source.target]
this.functions = Object.keys(this.target[this.contractName].evm.gasEstimates.external) this.functions = Object.keys(this.target[this.contractName].evm.gasEstimates.external)
this.creationCost = this.target[this.contractName].evm.gasEstimates.creation.totalCost
} }
gasEstimation (node) { gasEstimation (node) {
if (node.name === 'FunctionDefinition') { if (node.name === 'FunctionDefinition') {
var functionName = node.attributes.name var estimation
var fn if (!node.attributes.isConstructor) {
for (var x in this.functions) { var functionName = node.attributes.name
if (!!~this.functions[x].indexOf(functionName)) { var fn
fn = this.functions[x] for (var x in this.functions) {
break if (!!~this.functions[x].indexOf(functionName)) {
fn = this.functions[x]
break
}
} }
estimation = this.target[this.contractName].evm.gasEstimates.external[fn]
} else {
estimation = this.creationCost
} }
var estimation = this.target[this.contractName].evm.gasEstimates.external[fn]
return estimation
} }
return estimation
} }
_highlight (node, compilationResult) { _highlight (node, compilationResult) {

Loading…
Cancel
Save