aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/tx-utils.js
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2017-03-08 14:47:35 +0800
committerkumavis <aaron@kumavis.me>2017-03-08 14:47:35 +0800
commitc063fab9932c6b90414fd7db7849012d6594afb7 (patch)
tree9507b086979ffaef2df0aeb568d63416ad32d995 /app/scripts/lib/tx-utils.js
parent68b99dfb086c282fa3f2e76fbaf93673e92f097d (diff)
downloadtangerine-wallet-browser-c063fab9932c6b90414fd7db7849012d6594afb7.tar
tangerine-wallet-browser-c063fab9932c6b90414fd7db7849012d6594afb7.tar.gz
tangerine-wallet-browser-c063fab9932c6b90414fd7db7849012d6594afb7.tar.bz2
tangerine-wallet-browser-c063fab9932c6b90414fd7db7849012d6594afb7.tar.lz
tangerine-wallet-browser-c063fab9932c6b90414fd7db7849012d6594afb7.tar.xz
tangerine-wallet-browser-c063fab9932c6b90414fd7db7849012d6594afb7.tar.zst
tangerine-wallet-browser-c063fab9932c6b90414fd7db7849012d6594afb7.zip
tx-utils - stricter naming type-based convention
Diffstat (limited to 'app/scripts/lib/tx-utils.js')
-rw-r--r--app/scripts/lib/tx-utils.js24
1 files changed, 15 insertions, 9 deletions
diff --git a/app/scripts/lib/tx-utils.js b/app/scripts/lib/tx-utils.js
index 32a8a012a..f1171851c 100644
--- a/app/scripts/lib/tx-utils.js
+++ b/app/scripts/lib/tx-utils.js
@@ -53,25 +53,23 @@ module.exports = class txProviderUtils {
}
// if gasLimit not originally specified,
// 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 finalRecommendedGasBn = new BN(this.addGasBuffer(estimatedGasBn, blockGasLimitHex), 16)
- txParams.gas = ethUtil.intToHex(finalRecommendedGasBn)
+ const recommendedGasHex = this.addGasBuffer(txData.estimatedGas, blockGasLimitHex)
+ txParams.gas = recommendedGasHex
cb()
return
}
addGasBuffer (initialGasLimitHex, blockGasLimitHex) {
- const blockGasLimitBn = new BN(ethUtil.stripHexPrefix(blockGasLimitHex), 16)
- const initialGasLimitBn = new BN(ethUtil.stripHexPrefix(initialGasLimitHex), 16)
+ const initialGasLimitBn = hexToBn(initialGasLimitHex)
+ const blockGasLimitBn = hexToBn(blockGasLimitHex)
const bufferedGasLimitBn = initialGasLimitBn.muln(1.5)
// if initialGasLimit is above blockGasLimit, dont modify it
- if (initialGasLimitBn.gt(blockGasLimitBn)) return initialGasLimitHex
+ if (initialGasLimitBn.gt(blockGasLimitBn)) return bnToHex(initialGasLimitBn)
// if bufferedGasLimit is below blockGasLimit, use bufferedGasLimit
- if (bufferedGasLimitBn.lt(blockGasLimitBn)) return ethUtil.addHexPrefix(bufferedGasLimitBn.toString(16))
+ if (bufferedGasLimitBn.lt(blockGasLimitBn)) return bnToHex(bufferedGasLimitBn)
// otherwise use blockGasLimit
- return ethUtil.addHexPrefix(blockGasLimitBn.toString(16))
+ return bnToHex(blockGasLimitBn)
}
fillInTxParams (txParams, cb) {
@@ -129,3 +127,11 @@ module.exports = class txProviderUtils {
function isUndef(value) {
return value === undefined
}
+
+function bnToHex(inputBn) {
+ return ethUtil.addHexPrefix(inputBn.toString(16))
+}
+
+function hexToBn(inputHex) {
+ return new BN(ethUtil.stripHexPrefix(inputHex), 16)
+} \ No newline at end of file