check the current block gas limit before sending the tx

pull/1/head
yann300 8 years ago committed by Alex Beregszaszi
parent 293b12fac4
commit 1d297a1092
  1. 27
      src/app/txRunner.js

@ -69,21 +69,26 @@ TxRunner.prototype.execute = function () {
if (err) {
return callback(err, resp)
}
self.web3.eth.getBlock('latest', function (err, block) {
if (err) {
return callback(err)
} else {
var blockGasLimit = Math.floor(block.gasLimit - block.gasLimit / 1024)
tx.gas = blockGasLimit < resp ? blockGasLimit : resp
if (resp > gasLimit) {
return callback('Gas required exceeds limit: ' + resp)
}
tx.gas = resp
if (tx.gas > gasLimit) {
return callback('Gas required exceeds limit: ' + tx.gas)
}
var sendTransaction = self.personalMode ? self.web3.personal.sendTransaction : self.web3.eth.sendTransaction
var sendTransaction = self.personalMode ? self.web3.personal.sendTransaction : self.web3.eth.sendTransaction
sendTransaction(tx, function (err, resp) {
if (err) {
return callback(err, resp)
}
sendTransaction(tx, function (err, resp) {
if (err) {
return callback(err, resp)
tryTillResponse(self.web3, resp, callback)
})
}
tryTillResponse(self.web3, resp, callback)
})
})
}

Loading…
Cancel
Save