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,15 +69,18 @@ TxRunner.prototype.execute = function () { ...@@ -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 () { ...@@ -85,6 +88,8 @@ TxRunner.prototype.execute = function () {
tryTillResponse(self.web3, resp, callback) tryTillResponse(self.web3, resp, callback)
}) })
}
})
}) })
} }
} else { } else {
......
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