Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure correct tx category when sending to contracts without tx data #7252

Merged
merged 5 commits into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ui/app/pages/send/send.constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const MIN_GAS_PRICE_HEX = (parseInt(MIN_GAS_PRICE_DEC)).toString(16)
const MIN_GAS_LIMIT_DEC = '21000'
const MIN_GAS_LIMIT_HEX = (parseInt(MIN_GAS_LIMIT_DEC)).toString(16)

const ARBITRARY_HIGH_BLOCK_GAS_LIMIT = (parseInt('8000000')).toString(16)

const MIN_GAS_PRICE_GWEI = ethUtil.addHexPrefix(conversionUtil(MIN_GAS_PRICE_HEX, {
fromDenomination: 'WEI',
toDenomination: 'GWEI',
Expand Down Expand Up @@ -58,4 +60,5 @@ module.exports = {
SIMPLE_GAS_COST,
TOKEN_TRANSFER_FUNCTION_SIGNATURE,
BASE_TOKEN_GAS_COST,
ARBITRARY_HIGH_BLOCK_GAS_LIMIT,
}
10 changes: 10 additions & 0 deletions ui/app/pages/send/send.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const {
ONE_GWEI_IN_WEI_HEX,
SIMPLE_GAS_COST,
TOKEN_TRANSFER_FUNCTION_SIGNATURE,
ARBITRARY_HIGH_BLOCK_GAS_LIMIT,
} = require('./send.constants')
const abi = require('ethereumjs-abi')
const ethUtil = require('ethereumjs-util')
Expand Down Expand Up @@ -243,12 +244,21 @@ async function estimateGas ({
}

// if not, fall back to block gasLimit
if (!blockGasLimit) {
try {
blockGasLimit = await this.query.getBlockByNumber('latest', false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't getBlockByNumber return a block object, not a number string like we probably expect here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's impossible for blockGasLimit to ever be falsey, because it's given a default value of MIN_GAS_LIMIT_HEX

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this to something simpler. We don't really need a strictly accurate blockGasLimit at this point.

Meanwhile, I think blockGasLimit can be falsey if the value passed to this function is defined but falsey.

e.g.

danjm@pop-os:~/kyokan/metamask-extension$ node
> const t = ({ a = 10, b }) => console.log(`${a} | ${b}`)
undefined
> t({ a: null, b: 5})
null | 5
undefined
> t({ a: '', b: 5})
 | 5
undefined
> t({ b: 5})
10 | 5
undefined

} catch (e) {
blockGasLimit = ARBITRARY_HIGH_BLOCK_GAS_LIMIT
}
}

paramsForGasEstimate.gas = ethUtil.addHexPrefix(multiplyCurrencies(blockGasLimit, 0.95, {
multiplicandBase: 16,
multiplierBase: 10,
roundDown: '0',
toNumericBase: 'hex',
}))

// run tx
return new Promise((resolve, reject) => {
return estimateGasMethod(paramsForGasEstimate, (err, estimatedGas) => {
Expand Down