mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
parent
1b3ab71063
commit
cd7eaaa735
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
## Current Master
|
## Current Master
|
||||||
|
|
||||||
|
- Estimating gas limit for simple ether sends now faster & cheaper, by avoiding VM usage on recipients with no code.
|
||||||
|
|
||||||
## 3.13.4 2018-1-9
|
## 3.13.4 2018-1-9
|
||||||
|
|
||||||
- Remove recipient field if application initializes a tx with an empty string, or 0x, and tx data. Throw an error with the same condition, but without tx data.
|
- Remove recipient field if application initializes a tx with an empty string, or 0x, and tx data. Throw an error with the same condition, but without tx data.
|
||||||
|
@ -4,6 +4,7 @@ const {
|
|||||||
BnMultiplyByFraction,
|
BnMultiplyByFraction,
|
||||||
bnToHex,
|
bnToHex,
|
||||||
} = require('./util')
|
} = require('./util')
|
||||||
|
const SIMPLE_GAS_COST = '0x5208' // Hex for 21000, cost of a simple send.
|
||||||
|
|
||||||
/*
|
/*
|
||||||
tx-utils are utility methods for Transaction manager
|
tx-utils are utility methods for Transaction manager
|
||||||
@ -37,14 +38,30 @@ module.exports = class txProvideUtil {
|
|||||||
|
|
||||||
async estimateTxGas (txMeta, blockGasLimitHex) {
|
async estimateTxGas (txMeta, blockGasLimitHex) {
|
||||||
const txParams = txMeta.txParams
|
const txParams = txMeta.txParams
|
||||||
|
|
||||||
// check if gasLimit is already specified
|
// check if gasLimit is already specified
|
||||||
txMeta.gasLimitSpecified = Boolean(txParams.gas)
|
txMeta.gasLimitSpecified = Boolean(txParams.gas)
|
||||||
// if not, fallback to block gasLimit
|
|
||||||
if (!txMeta.gasLimitSpecified) {
|
// if it is, use that value
|
||||||
const blockGasLimitBN = hexToBn(blockGasLimitHex)
|
if (txMeta.gasLimitSpecified) {
|
||||||
const saferGasLimitBN = BnMultiplyByFraction(blockGasLimitBN, 19, 20)
|
return txParams.gas
|
||||||
txParams.gas = bnToHex(saferGasLimitBN)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
// run tx
|
||||||
return await this.query.estimateGas(txParams)
|
return await this.query.estimateGas(txParams)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user