diff options
author | Dan Finlay <dan@danfinlay.com> | 2016-11-24 08:54:27 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2016-11-24 08:54:27 +0800 |
commit | b8991195829474691f17db3a7a6c9c081f9a95c9 (patch) | |
tree | a68a7c2529a82f4634913755bfc3f781f9476c3c /app | |
parent | b9b3ef8fedc848cbebc60eab70b90aa4f75060f2 (diff) | |
parent | 323f3cb1a05947f320f77fc3e87c9d6c70ea1900 (diff) | |
download | tangerine-wallet-browser-b8991195829474691f17db3a7a6c9c081f9a95c9.tar tangerine-wallet-browser-b8991195829474691f17db3a7a6c9c081f9a95c9.tar.gz tangerine-wallet-browser-b8991195829474691f17db3a7a6c9c081f9a95c9.tar.bz2 tangerine-wallet-browser-b8991195829474691f17db3a7a6c9c081f9a95c9.tar.lz tangerine-wallet-browser-b8991195829474691f17db3a7a6c9c081f9a95c9.tar.xz tangerine-wallet-browser-b8991195829474691f17db3a7a6c9c081f9a95c9.tar.zst tangerine-wallet-browser-b8991195829474691f17db3a7a6c9c081f9a95c9.zip |
Merge branch 'master' into dev
Diffstat (limited to 'app')
-rw-r--r-- | app/manifest.json | 2 | ||||
-rw-r--r-- | app/scripts/lib/idStore.js | 70 | ||||
-rw-r--r-- | app/scripts/lib/inpage-provider.js | 7 |
3 files changed, 56 insertions, 23 deletions
diff --git a/app/manifest.json b/app/manifest.json index 99149f91e..b9d3735ad 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -1,7 +1,7 @@ { "name": "MetaMask", "short_name": "Metamask", - "version": "2.13.8", + "version": "2.13.10", "manifest_version": 2, "author": "https://metamask.io", "description": "Ethereum Browser Extension", diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js index e5861c0ca..d36504f13 100644 --- a/app/scripts/lib/idStore.js +++ b/app/scripts/lib/idStore.js @@ -258,24 +258,51 @@ IdentityStore.prototype.addUnconfirmedTransaction = function (txParams, onTxDone function estimateGas (cb) { var estimationParams = extend(txParams) - // 1 billion gas for estimation - var gasLimit = '0x3b9aca00' - estimationParams.gas = gasLimit - query.estimateGas(estimationParams, function (err, result) { - if (err) return cb(err.message || err) - if (result === estimationParams.gas) { - txData.simulationFails = true - query.getBlockByNumber('latest', true, function (err, block) { - if (err) return cb(err) - txData.estimatedGas = block.gasLimit - txData.txParams.gas = block.gasLimit + query.getBlockByNumber('latest', true, function(err, block){ + if (err) return cb(err) + // check if gasLimit is already specified + const gasLimitSpecified = Boolean(txParams.gas) + // if not, fallback to block gasLimit + if (!gasLimitSpecified) { + estimationParams.gas = block.gasLimit + } + // run tx, see if it will OOG + query.estimateGas(estimationParams, function(err, estimatedGasHex){ + if (err) return cb(err.message || err) + // all gas used - must be an error + if (estimatedGasHex === estimationParams.gas) { + txData.simulationFails = true + txData.estimatedGas = estimatedGasHex + txData.txParams.gas = estimatedGasHex + cb() + return + } + // otherwise, did not use all gas, must be ok + + // if specified gasLimit and no error, we're done + if (gasLimitSpecified) { + txData.estimatedGas = txParams.gas cb() - }) + return + } + + // try adding an additional gas buffer to our estimation for safety + const estimatedGasBn = new BN(ethUtil.stripHexPrefix(estimatedGasHex), 16) + const blockGasLimitBn = new BN(ethUtil.stripHexPrefix(block.gasLimit), 16) + const estimationWithBuffer = self.addGasBuffer(estimatedGasBn) + // added gas buffer is too high + if (estimationWithBuffer.gt(blockGasLimitBn)) { + txData.estimatedGas = estimatedGasHex + txData.txParams.gas = estimatedGasHex + // added gas buffer is safe + } else { + const gasWithBufferHex = ethUtil.intToHex(estimationWithBuffer) + txData.estimatedGas = gasWithBufferHex + txData.txParams.gas = gasWithBufferHex + } + cb() return - } - txData.estimatedGas = self.addGasBuffer(result) - txData.txParams.gas = txData.estimatedGas - cb() + }) }) } @@ -300,12 +327,11 @@ IdentityStore.prototype.checkForDelegateCall = function (codeHex) { } } -IdentityStore.prototype.addGasBuffer = function (gas) { - const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16) - const five = new BN('5', 10) - const gasBuffer = bnGas.div(five) - const correct = bnGas.add(gasBuffer) - return ethUtil.addHexPrefix(correct.toString(16)) +IdentityStore.prototype.addGasBuffer = function (gasBn) { + // add 20% to specified gas + const gasBuffer = gasBn.div(new BN('5', 10)) + const gasWithBuffer = gasBn.add(gasBuffer) + return gasWithBuffer } // comes from metamask ui diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js index 7179ae978..30fcbcb66 100644 --- a/app/scripts/lib/inpage-provider.js +++ b/app/scripts/lib/inpage-provider.js @@ -82,6 +82,11 @@ MetamaskInpageProvider.prototype.send = function (payload) { result = selectedAccount || '0x0000000000000000000000000000000000000000' break + case 'eth_uninstallFilter': + self.sendAsync(payload, noop) + result = true + break + // throw not-supported Error default: var link = 'https://github.com/MetaMask/faq/blob/master/DEVELOPERS.md#dizzy-all-async---think-of-metamask-as-a-light-client' @@ -127,3 +132,5 @@ function eachJsonMessage (payload, transformFn) { return transformFn(payload) } } + +function noop () {} |