tx utils - detect estimateGas err and set simulationFailed

This commit is contained in:
kumavis 2017-08-08 23:34:18 -07:00
parent 57f6fce6b2
commit b4052cd5e6
1 changed files with 11 additions and 3 deletions

View File

@ -20,7 +20,15 @@ module.exports = class txProvideUtil {
async analyzeGasUsage (txMeta) {
const block = await this.query.getBlockByNumber('latest', true)
const estimatedGasHex = await this.estimateTxGas(txMeta, block.gasLimit)
let estimatedGasHex
try {
estimatedGasHex = await this.estimateTxGas(txMeta, block.gasLimit)
} catch (err) {
if (err.message.includes('Transaction execution error.')) {
txMeta.simulationFails = true
return txMeta
}
}
this.setTxGas(txMeta, block.gasLimit, estimatedGasHex)
return txMeta
}
@ -35,8 +43,8 @@ module.exports = class txProvideUtil {
const saferGasLimitBN = BnMultiplyByFraction(blockGasLimitBN, 19, 20)
txParams.gas = bnToHex(saferGasLimitBN)
}
// run tx, see if it will OOG
return this.query.estimateGas(txParams)
// run tx
return await this.query.estimateGas(txParams)
}
setTxGas (txMeta, blockGasLimitHex, estimatedGasHex) {