diff options
author | kumavis <kumavis@users.noreply.github.com> | 2017-03-08 14:18:14 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-08 14:18:14 +0800 |
commit | 17b805c76ea3ea160bcb2560d2043581b54c4834 (patch) | |
tree | e85b82b180d1ee62598fad1f56cc2395c520a609 | |
parent | de5a30c5ff3acbcda7a46a3caba70a622308dbb2 (diff) | |
download | tangerine-wallet-browser-17b805c76ea3ea160bcb2560d2043581b54c4834.tar tangerine-wallet-browser-17b805c76ea3ea160bcb2560d2043581b54c4834.tar.gz tangerine-wallet-browser-17b805c76ea3ea160bcb2560d2043581b54c4834.tar.bz2 tangerine-wallet-browser-17b805c76ea3ea160bcb2560d2043581b54c4834.tar.lz tangerine-wallet-browser-17b805c76ea3ea160bcb2560d2043581b54c4834.tar.xz tangerine-wallet-browser-17b805c76ea3ea160bcb2560d2043581b54c4834.tar.zst tangerine-wallet-browser-17b805c76ea3ea160bcb2560d2043581b54c4834.zip |
tx-utils - clean and comment
-rw-r--r-- | app/scripts/lib/tx-utils.js | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/app/scripts/lib/tx-utils.js b/app/scripts/lib/tx-utils.js index f5051eb8f..32a8a012a 100644 --- a/app/scripts/lib/tx-utils.js +++ b/app/scripts/lib/tx-utils.js @@ -55,26 +55,22 @@ module.exports = class txProviderUtils { // try adding an additional gas buffer to our estimation for safety const estimatedGasBn = new BN(ethUtil.stripHexPrefix(txData.estimatedGas), 16) const blockGasLimitBn = new BN(ethUtil.stripHexPrefix(blockGasLimitHex), 16) - const estimationWithBuffer = new BN(this.addGasBuffer(estimatedGasBn, blockGasLimitHex), 16) - // added gas buffer is too high - if (estimationWithBuffer.gt(blockGasLimitBn)) { - txParams.gas = txData.estimatedGas - // added gas buffer is safe - } else { - const gasWithBufferHex = ethUtil.intToHex(estimationWithBuffer) - txParams.gas = gasWithBufferHex - } + const finalRecommendedGasBn = new BN(this.addGasBuffer(estimatedGasBn, blockGasLimitHex), 16) + txParams.gas = ethUtil.intToHex(finalRecommendedGasBn) cb() return } - addGasBuffer (gas, blockGasLimitHex) { + addGasBuffer (initialGasLimitHex, blockGasLimitHex) { const blockGasLimitBn = new BN(ethUtil.stripHexPrefix(blockGasLimitHex), 16) - const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16) - const bufferedGas = bnGas.muln(1.5) - - if (bnGas.gt(blockGasLimitBn)) return gas - if (bufferedGas.lt(blockGasLimitBn)) return ethUtil.addHexPrefix(bufferedGas.toString(16)) + const initialGasLimitBn = new BN(ethUtil.stripHexPrefix(initialGasLimitHex), 16) + const bufferedGasLimitBn = initialGasLimitBn.muln(1.5) + + // if initialGasLimit is above blockGasLimit, dont modify it + 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)) } |