aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Serrano <kevin.serrano@consensys.net>2017-06-02 03:53:16 +0800
committerKevin Serrano <kevin.serrano@consensys.net>2017-06-02 03:53:16 +0800
commit82cbfaa826cc4d731dfbeab7482420c66c0e832b (patch)
tree4c1f412e52e9fb2ab3db61220ff7b7e1ad062c1a
parent93e57e52870c870751b9c0461fdd89da2b4e2629 (diff)
downloadtangerine-wallet-browser-82cbfaa826cc4d731dfbeab7482420c66c0e832b.tar
tangerine-wallet-browser-82cbfaa826cc4d731dfbeab7482420c66c0e832b.tar.gz
tangerine-wallet-browser-82cbfaa826cc4d731dfbeab7482420c66c0e832b.tar.bz2
tangerine-wallet-browser-82cbfaa826cc4d731dfbeab7482420c66c0e832b.tar.lz
tangerine-wallet-browser-82cbfaa826cc4d731dfbeab7482420c66c0e832b.tar.xz
tangerine-wallet-browser-82cbfaa826cc4d731dfbeab7482420c66c0e832b.tar.zst
tangerine-wallet-browser-82cbfaa826cc4d731dfbeab7482420c66c0e832b.zip
Convert gasLimit to not use muln in BN
-rw-r--r--app/scripts/lib/tx-utils.js10
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)
+}