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. 15
      src/app/txRunner.js

@ -69,15 +69,18 @@ TxRunner.prototype.execute = function () {
if (err) { if (err) {
return callback(err, resp) 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) { if (tx.gas > gasLimit) {
return callback('Gas required exceeds limit: ' + resp) return callback('Gas required exceeds limit: ' + tx.gas)
} }
tx.gas = resp
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) { sendTransaction(tx, function (err, resp) {
if (err) { if (err) {
return callback(err, resp) return callback(err, resp)
@ -85,6 +88,8 @@ TxRunner.prototype.execute = function () {
tryTillResponse(self.web3, resp, callback) tryTillResponse(self.web3, resp, callback)
}) })
}
})
}) })
} }
} else { } else {

Loading…
Cancel
Save