diff --git a/src/app/execution/txRunner.js b/src/app/execution/txRunner.js index efa012a883..bb0b452f57 100644 --- a/src/app/execution/txRunner.js +++ b/src/app/execution/txRunner.js @@ -126,73 +126,67 @@ TxRunner.prototype.runInVm = function (from, to, data, value, gasLimit, useCall, TxRunner.prototype.runInNode = function (from, to, data, value, gasLimit, useCall, callback) { const self = this - var tx = { - from: from, - to: to, - data: data, - value: value - } + var tx = { from: from, to: to, data: data, value: value } if (useCall) { tx.gas = gasLimit - executionContext.web3().eth.call(tx, function (error, result) { + return executionContext.web3().eth.call(tx, function (error, result) { callback(error, { result: result, transactionHash: result.transactionHash }) }) - } else { - executionContext.web3().eth.estimateGas(tx, function (err, gasEstimation) { - if (err) { - return callback(err, gasEstimation) - } - var blockGasLimit = executionContext.currentblockGasLimit() - // NOTE: estimateGas very likely will return a large limit if execution of the code failed - // we want to be able to run the code in order to debug and find the cause for the failure + } + executionContext.web3().eth.estimateGas(tx, function (err, gasEstimation) { + if (err) { + return callback(err, gasEstimation) + } + var blockGasLimit = executionContext.currentblockGasLimit() + // NOTE: estimateGas very likely will return a large limit if execution of the code failed + // we want to be able to run the code in order to debug and find the cause for the failure - var warnEstimation = " An important gas estimation might also be the sign of a problem in the contract code. Please check loops and be sure you did not sent value to a non payable function (that's also the reason of strong gas estimation)." - if (gasEstimation > gasLimit) { - return callback('Gas required exceeds limit: ' + gasLimit + '. ' + warnEstimation) - } - if (gasEstimation > blockGasLimit) { - return callback('Gas required exceeds block gas limit: ' + gasLimit + '. ' + warnEstimation) - } + var warnEstimation = " An important gas estimation might also be the sign of a problem in the contract code. Please check loops and be sure you did not sent value to a non payable function (that's also the reason of strong gas estimation)." + if (gasEstimation > gasLimit) { + return callback('Gas required exceeds limit: ' + gasLimit + '. ' + warnEstimation) + } + if (gasEstimation > blockGasLimit) { + return callback('Gas required exceeds block gas limit: ' + gasLimit + '. ' + warnEstimation) + } - tx.gas = gasEstimation + tx.gas = gasEstimation - if (!self._api.config.getUnpersistedProperty('doNotShowTransactionConfirmationAgain')) { - self._api.detectNetwork((err, network) => { - if (err) { - console.log(err) - } else { - if (network.name === 'Main') { - var content = confirmDialog(tx, gasEstimation, self) - modalDialog('Confirm transaction', content, - { label: 'Confirm', + if (!self._api.config.getUnpersistedProperty('doNotShowTransactionConfirmationAgain')) { + self._api.detectNetwork((err, network) => { + if (err) { + console.log(err) + } else { + if (network.name === 'Main') { + var content = confirmDialog(tx, gasEstimation, self) + modalDialog('Confirm transaction', content, + { label: 'Confirm', + fn: () => { + self._api.config.setUnpersistedProperty('doNotShowTransactionConfirmationAgain', content.querySelector('input#confirmsetting').checked) + if (!content.gasPriceStatus) { + callback('Given gas grice is not correct') + } else { + var gasPrice = executionContext.web3().toWei(content.querySelector('#gasprice').value, 'gwei') + executeTx(tx, gasPrice, self._api, callback) + } + }}, { + label: 'Cancel', fn: () => { - self._api.config.setUnpersistedProperty('doNotShowTransactionConfirmationAgain', content.querySelector('input#confirmsetting').checked) - if (!content.gasPriceStatus) { - callback('Given gas grice is not correct') - } else { - var gasPrice = executionContext.web3().toWei(content.querySelector('#gasprice').value, 'gwei') - executeTx(tx, gasPrice, self._api, callback) - } - }}, { - label: 'Cancel', - fn: () => { - return callback('Transaction canceled by user.') - } - }) - } else { - executeTx(tx, null, self._api, callback) - } + return callback('Transaction canceled by user.') + } + }) + } else { + executeTx(tx, null, self._api, callback) } - }) - } else { - executeTx(tx, null, self._api, callback) - } - }) - } + } + }) + } else { + executeTx(tx, null, self._api, callback) + } + }) } function tryTillResponse (txhash, done) {