mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge pull request #1883 from MetaMask/estimateGas-fix
tx utils - detect estimateGas err and set simulationFailed
This commit is contained in:
commit
1071a35f7b
@ -20,7 +20,15 @@ module.exports = class txProvideUtil {
|
|||||||
|
|
||||||
async analyzeGasUsage (txMeta) {
|
async analyzeGasUsage (txMeta) {
|
||||||
const block = await this.query.getBlockByNumber('latest', true)
|
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)
|
this.setTxGas(txMeta, block.gasLimit, estimatedGasHex)
|
||||||
return txMeta
|
return txMeta
|
||||||
}
|
}
|
||||||
@ -35,8 +43,8 @@ module.exports = class txProvideUtil {
|
|||||||
const saferGasLimitBN = BnMultiplyByFraction(blockGasLimitBN, 19, 20)
|
const saferGasLimitBN = BnMultiplyByFraction(blockGasLimitBN, 19, 20)
|
||||||
txParams.gas = bnToHex(saferGasLimitBN)
|
txParams.gas = bnToHex(saferGasLimitBN)
|
||||||
}
|
}
|
||||||
// run tx, see if it will OOG
|
// run tx
|
||||||
return this.query.estimateGas(txParams)
|
return await this.query.estimateGas(txParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
setTxGas (txMeta, blockGasLimitHex, estimatedGasHex) {
|
setTxGas (txMeta, blockGasLimitHex, estimatedGasHex) {
|
||||||
|
Loading…
Reference in New Issue
Block a user