aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
authorHoward Braham <howrad@gmail.com>2018-09-18 11:04:10 +0800
committerHoward Braham <howrad@gmail.com>2018-10-10 06:31:25 +0800
commit222e62d7f10ffe22dd606aea9c15e1547986c4ab (patch)
tree4b3cb0d4853d9a1408dc8b28bfdf9d9abb2f2ad5 /app/scripts
parentdb4569e920b01791edb2bab8f87dcfd9596b1837 (diff)
downloadtangerine-wallet-browser-222e62d7f10ffe22dd606aea9c15e1547986c4ab.tar
tangerine-wallet-browser-222e62d7f10ffe22dd606aea9c15e1547986c4ab.tar.gz
tangerine-wallet-browser-222e62d7f10ffe22dd606aea9c15e1547986c4ab.tar.bz2
tangerine-wallet-browser-222e62d7f10ffe22dd606aea9c15e1547986c4ab.tar.lz
tangerine-wallet-browser-222e62d7f10ffe22dd606aea9c15e1547986c4ab.tar.xz
tangerine-wallet-browser-222e62d7f10ffe22dd606aea9c15e1547986c4ab.tar.zst
tangerine-wallet-browser-222e62d7f10ffe22dd606aea9c15e1547986c4ab.zip
Bug Fix: #1789 and #4525 eth.getCode() with no contract
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/controllers/transactions/tx-gas-utils.js23
1 files changed, 16 insertions, 7 deletions
diff --git a/app/scripts/controllers/transactions/tx-gas-utils.js b/app/scripts/controllers/transactions/tx-gas-utils.js
index 3dd45507f..5ec728085 100644
--- a/app/scripts/controllers/transactions/tx-gas-utils.js
+++ b/app/scripts/controllers/transactions/tx-gas-utils.js
@@ -7,6 +7,8 @@ const {
const { addHexPrefix } = require('ethereumjs-util')
const SIMPLE_GAS_COST = '0x5208' // Hex for 21000, cost of a simple send.
+import { TRANSACTION_NO_CONTRACT_ERROR_KEY } from '../../../../ui/app/constants/error-keys'
+
/**
tx-gas-utils are gas utility methods for Transaction manager
its passed ethquery
@@ -32,6 +34,7 @@ class TxGasUtil {
} catch (err) {
txMeta.simulationFails = {
reason: err.message,
+ errorKey: err.errorKey,
}
return txMeta
}
@@ -56,16 +59,22 @@ class TxGasUtil {
return txParams.gas
}
- // if recipient has no code, gas is 21k max:
const recipient = txParams.to
const hasRecipient = Boolean(recipient)
- let code
- if (recipient) code = await this.query.getCode(recipient)
- if (hasRecipient && (!code || code === '0x')) {
- txParams.gas = SIMPLE_GAS_COST
- txMeta.simpleSend = true // Prevents buffer addition
- return SIMPLE_GAS_COST
+ if (hasRecipient) {
+ let 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 will return '0x0'
+ if (txParams.data && (!code || code === '0x' || code === '0x0')) {
+ throw {errorKey: TRANSACTION_NO_CONTRACT_ERROR_KEY}
+ }
+ else if (!code) {
+ txParams.gas = SIMPLE_GAS_COST // For a standard ETH send, gas is 21k max
+ txMeta.simpleSend = true // Prevents buffer addition
+ return SIMPLE_GAS_COST
+ }
}
// if not, fall back to block gasLimit