From 82cbfaa826cc4d731dfbeab7482420c66c0e832b Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Thu, 1 Jun 2017 12:53:16 -0700 Subject: Convert gasLimit to not use muln in BN --- app/scripts/lib/tx-utils.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'app') 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) +} -- cgit v1.2.3