1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 12:29:06 +01:00

tx-gas-util - set error message when invalidating tx based on tx data but no contract code

This commit is contained in:
kumavis 2018-10-21 01:01:21 -04:00
parent 17a856cfd3
commit 31e5cad1e3

View File

@ -62,20 +62,21 @@ class TxGasUtil {
const recipient = txParams.to
const hasRecipient = Boolean(recipient)
// see if we can set the gas based on the recipient
// 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'
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()
const err = new Error('TxGasUtil - Trying to call a function on a non-contract address')
// set error key so ui can display localized error message
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