mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
tx-utils - clean and comment
This commit is contained in:
parent
de5a30c5ff
commit
17b805c76e
@ -55,26 +55,22 @@ module.exports = class txProviderUtils {
|
|||||||
// try adding an additional gas buffer to our estimation for safety
|
// try adding an additional gas buffer to our estimation for safety
|
||||||
const estimatedGasBn = new BN(ethUtil.stripHexPrefix(txData.estimatedGas), 16)
|
const estimatedGasBn = new BN(ethUtil.stripHexPrefix(txData.estimatedGas), 16)
|
||||||
const blockGasLimitBn = new BN(ethUtil.stripHexPrefix(blockGasLimitHex), 16)
|
const blockGasLimitBn = new BN(ethUtil.stripHexPrefix(blockGasLimitHex), 16)
|
||||||
const estimationWithBuffer = new BN(this.addGasBuffer(estimatedGasBn, blockGasLimitHex), 16)
|
const finalRecommendedGasBn = new BN(this.addGasBuffer(estimatedGasBn, blockGasLimitHex), 16)
|
||||||
// added gas buffer is too high
|
txParams.gas = ethUtil.intToHex(finalRecommendedGasBn)
|
||||||
if (estimationWithBuffer.gt(blockGasLimitBn)) {
|
|
||||||
txParams.gas = txData.estimatedGas
|
|
||||||
// added gas buffer is safe
|
|
||||||
} else {
|
|
||||||
const gasWithBufferHex = ethUtil.intToHex(estimationWithBuffer)
|
|
||||||
txParams.gas = gasWithBufferHex
|
|
||||||
}
|
|
||||||
cb()
|
cb()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
addGasBuffer (gas, blockGasLimitHex) {
|
addGasBuffer (initialGasLimitHex, blockGasLimitHex) {
|
||||||
const blockGasLimitBn = new BN(ethUtil.stripHexPrefix(blockGasLimitHex), 16)
|
const blockGasLimitBn = new BN(ethUtil.stripHexPrefix(blockGasLimitHex), 16)
|
||||||
const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16)
|
const initialGasLimitBn = new BN(ethUtil.stripHexPrefix(initialGasLimitHex), 16)
|
||||||
const bufferedGas = bnGas.muln(1.5)
|
const bufferedGasLimitBn = initialGasLimitBn.muln(1.5)
|
||||||
|
|
||||||
if (bnGas.gt(blockGasLimitBn)) return gas
|
// if initialGasLimit is above blockGasLimit, dont modify it
|
||||||
if (bufferedGas.lt(blockGasLimitBn)) return ethUtil.addHexPrefix(bufferedGas.toString(16))
|
if (initialGasLimitBn.gt(blockGasLimitBn)) return initialGasLimitHex
|
||||||
|
// if bufferedGasLimit is below blockGasLimit, use bufferedGasLimit
|
||||||
|
if (bufferedGasLimitBn.lt(blockGasLimitBn)) return ethUtil.addHexPrefix(bufferedGasLimitBn.toString(16))
|
||||||
|
// otherwise use blockGasLimit
|
||||||
return ethUtil.addHexPrefix(blockGasLimitBn.toString(16))
|
return ethUtil.addHexPrefix(blockGasLimitBn.toString(16))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user