diff options
author | kumavis <kumavis@users.noreply.github.com> | 2017-06-03 02:06:32 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-03 02:06:32 +0800 |
commit | f001de86a51796575dcdd7159ca7900aadb87185 (patch) | |
tree | b744173e772da1d2ab08dde62b7ce1fb82955d7f | |
parent | bcc550d3fb0ed9480232743d3f689237fc7bbcf6 (diff) | |
parent | 82cbfaa826cc4d731dfbeab7482420c66c0e832b (diff) | |
download | tangerine-wallet-browser-f001de86a51796575dcdd7159ca7900aadb87185.tar tangerine-wallet-browser-f001de86a51796575dcdd7159ca7900aadb87185.tar.gz tangerine-wallet-browser-f001de86a51796575dcdd7159ca7900aadb87185.tar.bz2 tangerine-wallet-browser-f001de86a51796575dcdd7159ca7900aadb87185.tar.lz tangerine-wallet-browser-f001de86a51796575dcdd7159ca7900aadb87185.tar.xz tangerine-wallet-browser-f001de86a51796575dcdd7159ca7900aadb87185.tar.zst tangerine-wallet-browser-f001de86a51796575dcdd7159ca7900aadb87185.zip |
Merge pull request #1533 from MetaMask/i1528-gasLimitLow
Convert gasLimit to not use muln in BN
-rw-r--r-- | app/scripts/lib/tx-utils.js | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/app/scripts/lib/tx-utils.js b/app/scripts/lib/tx-utils.js index 8cf304d0b..658f3bedc 100644 --- a/app/scripts/lib/tx-utils.js +++ b/app/scripts/lib/tx-utils.js @@ -30,7 +30,7 @@ module.exports = class txProviderUtils { setBlockGasLimit (txMeta, blockGasLimitHex, cb) { const blockGasLimitBN = hexToBn(blockGasLimitHex) - const saferGasLimitBN = blockGasLimitBN.muln(0.95) + const saferGasLimitBN = BnMultiplyByFraction(blockGasLimitBN, 19, 20) txMeta.blockGasLimit = bnToHex(saferGasLimitBN) cb() return @@ -43,7 +43,7 @@ module.exports = class txProviderUtils { // if not, fallback to block gasLimit if (!txMeta.gasLimitSpecified) { const blockGasLimitBN = hexToBn(blockGasLimitHex) - const saferGasLimitBN = blockGasLimitBN.muln(0.95) + const saferGasLimitBN = BnMultiplyByFraction(blockGasLimitBN, 19, 20) txParams.gas = bnToHex(saferGasLimitBN) } // run tx, see if it will OOG @@ -143,3 +143,9 @@ function bnToHex (inputBn) { function hexToBn (inputHex) { return new BN(ethUtil.stripHexPrefix(inputHex), 16) } + +function BnMultiplyByFraction (targetBN, numerator, denominator) { + const numBN = new BN(numerator) + const denomBN = new BN(denominator) + return targetBN.mul(numBN).div(denomBN) +} |