1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

ganache-core merged my PR, so I changed some comments to clarify that ganache-core v2.2.1 and below will return the non-standard '0x0'

This commit is contained in:
Howard Braham 2018-09-28 11:01:34 -07:00
parent 222e62d7f1
commit 4cc0b1ef01
4 changed files with 9 additions and 8 deletions

View File

@ -63,14 +63,15 @@ class TxGasUtil {
const hasRecipient = Boolean(recipient) const hasRecipient = Boolean(recipient)
if (hasRecipient) { if (hasRecipient) {
let code = await this.query.getCode(recipient) 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 // 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' // For no code, Infura will return '0x', and ganache-core v2.2.1 will return '0x0'
if (txParams.data && (!code || code === '0x' || code === '0x0')) { if (txParams.data && (!code || code === '0x' || code === '0x0')) {
throw {errorKey: TRANSACTION_NO_CONTRACT_ERROR_KEY} const err = new Error()
} err.errorKey = TRANSACTION_NO_CONTRACT_ERROR_KEY
else if (!code) { throw err
} else if (!code) {
txParams.gas = SIMPLE_GAS_COST // For a standard ETH send, gas is 21k max txParams.gas = SIMPLE_GAS_COST // For a standard ETH send, gas is 21k max
txMeta.simpleSend = true // Prevents buffer addition txMeta.simpleSend = true // Prevents buffer addition
return SIMPLE_GAS_COST return SIMPLE_GAS_COST

View File

@ -489,7 +489,7 @@ PendingTx.prototype.verifyGasParams = function () {
} }
PendingTx.prototype._notZeroOrEmptyString = function (obj) { PendingTx.prototype._notZeroOrEmptyString = function (obj) {
return obj !== '' && obj !== '0x0' && obj !== '0x' // The '0x' case might not ever happen, but it seems safest to protect against it return obj !== '' && obj !== '0x0' && obj !== '0x' // '0x' means null
} }
PendingTx.prototype.bnMultiplyByFraction = function (targetBN, numerator, denominator) { PendingTx.prototype.bnMultiplyByFraction = function (targetBN, numerator, denominator) {

View File

@ -215,7 +215,7 @@ async function estimateGas ({
// if recipient has no code, gas is 21k max: // if recipient has no code, gas is 21k max:
if (!selectedToken && !data) { if (!selectedToken && !data) {
const code = Boolean(to) && await global.eth.getCode(to) const code = Boolean(to) && await global.eth.getCode(to)
if (!code || code === '0x' || code === '0x0') { // Infura will return '0x', and Ganache will return '0x0' if (!code || code === '0x' || code === '0x0') { // Infura will return '0x', and ganache-core v2.2.1 will return '0x0'
return SIMPLE_GAS_COST return SIMPLE_GAS_COST
} }
} else if (selectedToken && !to) { } else if (selectedToken && !to) {

View File

@ -114,7 +114,7 @@ export function getLatestSubmittedTxWithNonce (transactions = [], nonce = '0x0')
export async function isSmartContractAddress (address) { export async function isSmartContractAddress (address) {
const code = await global.eth.getCode(address) const code = await global.eth.getCode(address)
return code && code !== '0x' && code !== '0x0'; // Infura will return '0x', and Ganache will return '0x0' return code && code !== '0x' && code !== '0x0' // Infura will return '0x', and ganache-core v2.2.1 will return '0x0'
} }
export function sumHexes (...args) { export function sumHexes (...args) {