Add new blockGasLimit property to txMeta object.

feature/default_network_editable
Kevin Serrano 8 years ago
parent 1ffc6ea0b3
commit 26fd016b63
No known key found for this signature in database
GPG Key ID: BF999DEFC7371BA1
  1. 13
      app/scripts/lib/tx-utils.js

@ -21,19 +21,30 @@ module.exports = class txProviderUtils {
this.query.getBlockByNumber('latest', true, (err, block) => { this.query.getBlockByNumber('latest', true, (err, block) => {
if (err) return cb(err) if (err) return cb(err)
async.waterfall([ async.waterfall([
self.setBlockGasLimit.bind(self, txMeta, block.gasLimit),
self.estimateTxGas.bind(self, txMeta, block.gasLimit), self.estimateTxGas.bind(self, txMeta, block.gasLimit),
self.setTxGas.bind(self, txMeta, block.gasLimit), self.setTxGas.bind(self, txMeta, block.gasLimit),
], cb) ], cb)
}) })
} }
setBlockGasLimit (txMeta, blockGasLimitHex, cb) {
const blockGasLimitBN = hexToBn(blockGasLimitHex)
const saferGasLimitBN = blockGasLimitBN.muln(0.95)
txMeta.blockGasLimit = bnToHex(saferGasLimitBN)
cb()
return
}
estimateTxGas (txMeta, blockGasLimitHex, cb) { estimateTxGas (txMeta, blockGasLimitHex, cb) {
const txParams = txMeta.txParams const txParams = txMeta.txParams
// check if gasLimit is already specified // check if gasLimit is already specified
txMeta.gasLimitSpecified = Boolean(txParams.gas) txMeta.gasLimitSpecified = Boolean(txParams.gas)
// if not, fallback to block gasLimit // if not, fallback to block gasLimit
if (!txMeta.gasLimitSpecified) { if (!txMeta.gasLimitSpecified) {
txParams.gas = blockGasLimitHex const blockGasLimitBN = hexToBn(blockGasLimitHex)
const saferGasLimitBN = blockGasLimitBN.muln(0.95)
txParams.gas = bnToHex(saferGasLimitBN)
} }
// run tx, see if it will OOG // run tx, see if it will OOG
this.query.estimateGas(txParams, cb) this.query.estimateGas(txParams, cb)

Loading…
Cancel
Save