Commit 1d297a10 authored by yann300's avatar yann300 Committed by Alex Beregszaszi

check the current block gas limit before sending the tx

parent 293b12fa
......@@ -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)
})
})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment