aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/controllers/transactions/tx-gas-utils.js
diff options
context:
space:
mode:
authorDan J Miller <danjm.com@gmail.com>2019-05-09 03:18:33 +0800
committerGitHub <noreply@github.com>2019-05-09 03:18:33 +0800
commitef8a07c2ce2b1c5fc4ef18f48592b2e7da178c44 (patch)
treef313f041fd6f51322375239525aeb1a54a71e5f1 /app/scripts/controllers/transactions/tx-gas-utils.js
parent56ed189aeb4ebc8e5dff7a6886e07791ce6569bb (diff)
downloadtangerine-wallet-browser-ef8a07c2ce2b1c5fc4ef18f48592b2e7da178c44.tar.gz
tangerine-wallet-browser-ef8a07c2ce2b1c5fc4ef18f48592b2e7da178c44.tar.zst
tangerine-wallet-browser-ef8a07c2ce2b1c5fc4ef18f48592b2e7da178c44.zip
Adds a transactionCategory to txMeta for use in UI (#6567)
* Adds a transactionCategory to txMeta for use in UI * Update transaction controller and tx-gas-util documentation on new code param in multiple functions.
Diffstat (limited to 'app/scripts/controllers/transactions/tx-gas-utils.js')
-rw-r--r--app/scripts/controllers/transactions/tx-gas-utils.js11
1 files changed, 7 insertions, 4 deletions
diff --git a/app/scripts/controllers/transactions/tx-gas-utils.js b/app/scripts/controllers/transactions/tx-gas-utils.js
index 765551167..2dc461f48 100644
--- a/app/scripts/controllers/transactions/tx-gas-utils.js
+++ b/app/scripts/controllers/transactions/tx-gas-utils.js
@@ -4,6 +4,7 @@ const {
BnMultiplyByFraction,
bnToHex,
} = require('../../lib/util')
+const log = require('loglevel')
const { addHexPrefix } = require('ethereumjs-util')
const SIMPLE_GAS_COST = '0x5208' // Hex for 21000, cost of a simple send.
@@ -24,14 +25,16 @@ class TxGasUtil {
/**
@param txMeta {Object} - the txMeta object
+ @param code {string} - the code at the txs address, as returned by this.query.getCode(to)
@returns {object} the txMeta object with the gas written to the txParams
*/
- async analyzeGasUsage (txMeta) {
+ async analyzeGasUsage (txMeta, code) {
const block = await this.query.getBlockByNumber('latest', false)
let estimatedGasHex
try {
- estimatedGasHex = await this.estimateTxGas(txMeta, block.gasLimit)
+ estimatedGasHex = await this.estimateTxGas(txMeta, block.gasLimit, code)
} catch (err) {
+ log.warn(err)
txMeta.simulationFails = {
reason: err.message,
errorKey: err.errorKey,
@@ -52,9 +55,10 @@ class TxGasUtil {
Estimates the tx's gas usage
@param txMeta {Object} - the txMeta object
@param blockGasLimitHex {string} - hex string of the block's gas limit
+ @param code {string} - the code at the txs address, as returned by this.query.getCode(to)
@returns {string} the estimated gas limit as a hex string
*/
- async estimateTxGas (txMeta, blockGasLimitHex) {
+ async estimateTxGas (txMeta, blockGasLimitHex, code) {
const txParams = txMeta.txParams
// check if gasLimit is already specified
@@ -70,7 +74,6 @@ class TxGasUtil {
// see if we can set the gas based on the recipient
if (hasRecipient) {
- const code = await this.query.getCode(recipient)
// For an address with no code, geth will return '0x', and ganache-core v2.2.1 will return '0x0'
const codeIsEmpty = !code || code === '0x' || code === '0x0'