aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/tx-utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/scripts/lib/tx-utils.js')
-rw-r--r--app/scripts/lib/tx-utils.js43
1 files changed, 10 insertions, 33 deletions
diff --git a/app/scripts/lib/tx-utils.js b/app/scripts/lib/tx-utils.js
index 3687a9652..b64ea6712 100644
--- a/app/scripts/lib/tx-utils.js
+++ b/app/scripts/lib/tx-utils.js
@@ -1,7 +1,11 @@
-const ethUtil = require('ethereumjs-util')
+const EthQuery = require('ethjs-query')
const Transaction = require('ethereumjs-tx')
const normalize = require('eth-sig-util').normalize
-const BN = ethUtil.BN
+const {
+ hexToBn,
+ BnMultiplyByFraction,
+ bnToHex,
+} = require('./util')
/*
tx-utils are utility methods for Transaction manager
@@ -9,9 +13,9 @@ its passed ethquery
and used to do things like calculate gas of a tx.
*/
-module.exports = class txProvideUtils {
- constructor (ethQuery) {
- this.query = ethQuery
+module.exports = class txProvideUtil {
+ constructor (provider) {
+ this.query = new EthQuery(provider)
}
async analyzeGasUsage (txMeta) {
@@ -91,31 +95,4 @@ module.exports = class txProvideUtils {
throw new Error(`Invalid transaction value of ${txParams.value} not a positive number.`)
}
}
-
- sufficientBalance (txParams, hexBalance) {
- const balance = hexToBn(hexBalance)
- const value = hexToBn(txParams.value)
- const gasLimit = hexToBn(txParams.gas)
- const gasPrice = hexToBn(txParams.gasPrice)
-
- const maxCost = value.add(gasLimit.mul(gasPrice))
- return balance.gte(maxCost)
- }
-
-}
-
-// util
-
-function bnToHex (inputBn) {
- return ethUtil.addHexPrefix(inputBn.toString(16))
-}
-
-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)
-}
+} \ No newline at end of file