mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Convert gasLimit to not use muln in BN
This commit is contained in:
parent
93e57e5287
commit
82cbfaa826
@ -30,7 +30,7 @@ module.exports = class txProviderUtils {
|
|||||||
|
|
||||||
setBlockGasLimit (txMeta, blockGasLimitHex, cb) {
|
setBlockGasLimit (txMeta, blockGasLimitHex, cb) {
|
||||||
const blockGasLimitBN = hexToBn(blockGasLimitHex)
|
const blockGasLimitBN = hexToBn(blockGasLimitHex)
|
||||||
const saferGasLimitBN = blockGasLimitBN.muln(0.95)
|
const saferGasLimitBN = BnMultiplyByFraction(blockGasLimitBN, 19, 20)
|
||||||
txMeta.blockGasLimit = bnToHex(saferGasLimitBN)
|
txMeta.blockGasLimit = bnToHex(saferGasLimitBN)
|
||||||
cb()
|
cb()
|
||||||
return
|
return
|
||||||
@ -43,7 +43,7 @@ module.exports = class txProviderUtils {
|
|||||||
// if not, fallback to block gasLimit
|
// if not, fallback to block gasLimit
|
||||||
if (!txMeta.gasLimitSpecified) {
|
if (!txMeta.gasLimitSpecified) {
|
||||||
const blockGasLimitBN = hexToBn(blockGasLimitHex)
|
const blockGasLimitBN = hexToBn(blockGasLimitHex)
|
||||||
const saferGasLimitBN = blockGasLimitBN.muln(0.95)
|
const saferGasLimitBN = BnMultiplyByFraction(blockGasLimitBN, 19, 20)
|
||||||
txParams.gas = bnToHex(saferGasLimitBN)
|
txParams.gas = bnToHex(saferGasLimitBN)
|
||||||
}
|
}
|
||||||
// run tx, see if it will OOG
|
// run tx, see if it will OOG
|
||||||
@ -143,3 +143,9 @@ function bnToHex (inputBn) {
|
|||||||
function hexToBn (inputHex) {
|
function hexToBn (inputHex) {
|
||||||
return new BN(ethUtil.stripHexPrefix(inputHex), 16)
|
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)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user