aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2018-10-10 11:17:05 +0800
committerGitHub <noreply@github.com>2018-10-10 11:17:05 +0800
commit600f755dbf8d4cfdc152e3d521b537ee9a046a35 (patch)
tree16594c9c749b59435f1154cd5689c6417b408b58 /app/scripts
parent4cc0b1ef01573e1541d18bdcd89650e1db32ae9a (diff)
downloadtangerine-wallet-browser-600f755dbf8d4cfdc152e3d521b537ee9a046a35.tar
tangerine-wallet-browser-600f755dbf8d4cfdc152e3d521b537ee9a046a35.tar.gz
tangerine-wallet-browser-600f755dbf8d4cfdc152e3d521b537ee9a046a35.tar.bz2
tangerine-wallet-browser-600f755dbf8d4cfdc152e3d521b537ee9a046a35.tar.lz
tangerine-wallet-browser-600f755dbf8d4cfdc152e3d521b537ee9a046a35.tar.xz
tangerine-wallet-browser-600f755dbf8d4cfdc152e3d521b537ee9a046a35.tar.zst
tangerine-wallet-browser-600f755dbf8d4cfdc152e3d521b537ee9a046a35.zip
tx-gas-utils - improve format + comments
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/controllers/transactions/tx-gas-utils.js30
1 files changed, 18 insertions, 12 deletions
diff --git a/app/scripts/controllers/transactions/tx-gas-utils.js b/app/scripts/controllers/transactions/tx-gas-utils.js
index ac57dfe1d..436900715 100644
--- a/app/scripts/controllers/transactions/tx-gas-utils.js
+++ b/app/scripts/controllers/transactions/tx-gas-utils.js
@@ -62,28 +62,34 @@ class TxGasUtil {
const recipient = txParams.to
const hasRecipient = Boolean(recipient)
+ // see if we can set the gas based on the recipient
if (hasRecipient) {
const code = await this.query.getCode(recipient)
-
- // If there's data in the params, but there's no code, it's not a valid contract
- // For no code, Infura will return '0x', and ganache-core v2.2.1 will return '0x0'
- if (txParams.data && (!code || code === '0x' || code === '0x0')) {
- const err = new Error()
- err.errorKey = TRANSACTION_NO_CONTRACT_ERROR_KEY
- throw err
- } else if (!code) {
- txParams.gas = SIMPLE_GAS_COST // For a standard ETH send, gas is 21k max
- txMeta.simpleSend = true // Prevents buffer addition
+ // 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'
+
+ if (codeIsEmpty) {
+ // if there's data in the params, but there's no contract code, it's not a valid transaction
+ if (txParams.data) {
+ const err = new Error()
+ err.errorKey = TRANSACTION_NO_CONTRACT_ERROR_KEY
+ throw err
+ }
+
+ // This is a standard ether simple send, gas requirement is exactly 21k
+ txParams.gas = SIMPLE_GAS_COST
+ // prevents buffer addition
+ txMeta.simpleSend = true
return SIMPLE_GAS_COST
}
}
- // if not, fall back to block gasLimit
+ // fallback to block gasLimit
const blockGasLimitBN = hexToBn(blockGasLimitHex)
const saferGasLimitBN = BnMultiplyByFraction(blockGasLimitBN, 19, 20)
txParams.gas = bnToHex(saferGasLimitBN)
- // run tx
+ // estimate tx gas requirements
return await this.query.estimateGas(txParams)
}