refactor: remove unnecessary level of depth from runInNode

pull/1/head
Iuri Matias 7 years ago
parent 9937c9c4a9
commit 9e3c80298f
  1. 102
      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) { TxRunner.prototype.runInNode = function (from, to, data, value, gasLimit, useCall, callback) {
const self = this const self = this
var tx = { var tx = { from: from, to: to, data: data, value: value }
from: from,
to: to,
data: data,
value: value
}
if (useCall) { if (useCall) {
tx.gas = gasLimit tx.gas = gasLimit
executionContext.web3().eth.call(tx, function (error, result) { return executionContext.web3().eth.call(tx, function (error, result) {
callback(error, { callback(error, {
result: result, result: result,
transactionHash: result.transactionHash transactionHash: result.transactionHash
}) })
}) })
} else { }
executionContext.web3().eth.estimateGas(tx, function (err, gasEstimation) { executionContext.web3().eth.estimateGas(tx, function (err, gasEstimation) {
if (err) { if (err) {
return callback(err, gasEstimation) return callback(err, gasEstimation)
} }
var blockGasLimit = executionContext.currentblockGasLimit() var blockGasLimit = executionContext.currentblockGasLimit()
// NOTE: estimateGas very likely will return a large limit if execution of the code failed // 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 // 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)." 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) { if (gasEstimation > gasLimit) {
return callback('Gas required exceeds limit: ' + gasLimit + '. ' + warnEstimation) return callback('Gas required exceeds limit: ' + gasLimit + '. ' + warnEstimation)
} }
if (gasEstimation > blockGasLimit) { if (gasEstimation > blockGasLimit) {
return callback('Gas required exceeds block gas limit: ' + gasLimit + '. ' + warnEstimation) return callback('Gas required exceeds block gas limit: ' + gasLimit + '. ' + warnEstimation)
} }
tx.gas = gasEstimation tx.gas = gasEstimation
if (!self._api.config.getUnpersistedProperty('doNotShowTransactionConfirmationAgain')) { if (!self._api.config.getUnpersistedProperty('doNotShowTransactionConfirmationAgain')) {
self._api.detectNetwork((err, network) => { self._api.detectNetwork((err, network) => {
if (err) { if (err) {
console.log(err) console.log(err)
} else { } else {
if (network.name === 'Main') { if (network.name === 'Main') {
var content = confirmDialog(tx, gasEstimation, self) var content = confirmDialog(tx, gasEstimation, self)
modalDialog('Confirm transaction', content, modalDialog('Confirm transaction', content,
{ label: 'Confirm', { 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: () => { fn: () => {
self._api.config.setUnpersistedProperty('doNotShowTransactionConfirmationAgain', content.querySelector('input#confirmsetting').checked) return callback('Transaction canceled by user.')
if (!content.gasPriceStatus) { }
callback('Given gas grice is not correct') })
} else { } else {
var gasPrice = executionContext.web3().toWei(content.querySelector('#gasprice').value, 'gwei') executeTx(tx, null, self._api, callback)
executeTx(tx, gasPrice, self._api, callback)
}
}}, {
label: 'Cancel',
fn: () => {
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) { function tryTillResponse (txhash, done) {

Loading…
Cancel
Save