diff options
author | Dan Finlay <dan@danfinlay.com> | 2018-01-16 07:08:07 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2018-01-16 07:08:07 +0800 |
commit | cd7eaaa735aa084cec0c4a647edf89bc5e4b2ec7 (patch) | |
tree | 0e9e3abdc141fb766dac4d03c7fb3284b6607086 /app | |
parent | 1b3ab710637cab2959c2da25de895a3c28f348d8 (diff) | |
download | tangerine-wallet-browser-cd7eaaa735aa084cec0c4a647edf89bc5e4b2ec7.tar tangerine-wallet-browser-cd7eaaa735aa084cec0c4a647edf89bc5e4b2ec7.tar.gz tangerine-wallet-browser-cd7eaaa735aa084cec0c4a647edf89bc5e4b2ec7.tar.bz2 tangerine-wallet-browser-cd7eaaa735aa084cec0c4a647edf89bc5e4b2ec7.tar.lz tangerine-wallet-browser-cd7eaaa735aa084cec0c4a647edf89bc5e4b2ec7.tar.xz tangerine-wallet-browser-cd7eaaa735aa084cec0c4a647edf89bc5e4b2ec7.tar.zst tangerine-wallet-browser-cd7eaaa735aa084cec0c4a647edf89bc5e4b2ec7.zip |
Set gas limit to 21k for recipients with no code
Fixes #2907
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/lib/tx-gas-utils.js | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/app/scripts/lib/tx-gas-utils.js b/app/scripts/lib/tx-gas-utils.js index 5e49fdb22..d57c70b10 100644 --- a/app/scripts/lib/tx-gas-utils.js +++ b/app/scripts/lib/tx-gas-utils.js @@ -4,6 +4,7 @@ const { BnMultiplyByFraction, bnToHex, } = require('./util') +const SIMPLE_GAS_COST = '0x5208' // Hex for 21000, cost of a simple send. /* tx-utils are utility methods for Transaction manager @@ -37,14 +38,30 @@ module.exports = class txProvideUtil { async estimateTxGas (txMeta, blockGasLimitHex) { const txParams = txMeta.txParams + // check if gasLimit is already specified txMeta.gasLimitSpecified = Boolean(txParams.gas) - // if not, fallback to block gasLimit - if (!txMeta.gasLimitSpecified) { - const blockGasLimitBN = hexToBn(blockGasLimitHex) - const saferGasLimitBN = BnMultiplyByFraction(blockGasLimitBN, 19, 20) - txParams.gas = bnToHex(saferGasLimitBN) + + // if it is, use that value + if (txMeta.gasLimitSpecified) { + return txParams.gas } + + // if recipient has no code, gas is 21k max: + const recipient = txParams.to + const hasRecipient = Boolean(recipient) + const code = await this.query.getCode(recipient) + if (hasRecipient && (!code || code === '0x')) { + txParams.gas = SIMPLE_GAS_COST + txMeta.gasLimitSpecified = true // Prevents buffer addition + return SIMPLE_GAS_COST + } + + // if not, fall back to block gasLimit + const blockGasLimitBN = hexToBn(blockGasLimitHex) + const saferGasLimitBN = BnMultiplyByFraction(blockGasLimitBN, 19, 20) + txParams.gas = bnToHex(saferGasLimitBN) + // run tx return await this.query.estimateGas(txParams) } |