From 43b1cb9100e74ab32efe1a59b3320d0aeadedcdf Mon Sep 17 00:00:00 2001 From: Daijiro Wachi Date: Sat, 21 Oct 2017 21:06:39 +0200 Subject: Fix lint warnings Fixed warnings: ```md app/scripts/controllers/computed-balances.js + 35:27 warning Missing space before function parentheses space-before-function-paren + 41:14 warning 'address' is never reassigned. Use 'const' instead prefer-const + 61:9 warning 'updater' is never reassigned. Use 'const' instead prefer-const + 68:11 warning 'newState' is never reassigned. Use 'const' instead prefer-const app/scripts/controllers/network.js + 104:29 warning Missing space before function parentheses space-before-function-paren app/scripts/lib/createLoggerMiddleware.js + 4:32 warning Missing space before function parentheses space-before-function-paren + 15:2 warning Newline required at end of file but not found eol-last app/scripts/lib/createOriginMiddleware.js + 4:32 warning Missing space before function parentheses space-before-function-paren + 9:2 warning Newline required at end of file but not found eol-last app/scripts/lib/createProviderMiddleware.js + 5:34 warning Missing space before function parentheses space-before-function-paren + 13:2 warning Newline required at end of file but not found eol-last app/scripts/lib/events-proxy.js + 1:50 warning Missing space before function parentheses space-before-function-paren + 31:2 warning Newline required at end of file but not found eol-last app/scripts/lib/nodeify.js + 2:22 warning Missing space before function parentheses space-before-function-paren + 2:24 warning Missing space before opening brace space-before-blocks + 5:18 warning Missing space before function parentheses space-before-function-paren + 5:20 warning Missing space before opening brace space-before-blocks app/scripts/lib/pending-balance-calculator.js + 16:19 warning Missing space before function parentheses space-before-function-paren app/scripts/lib/pending-tx-tracker.js + 85:11 warning '||' should be placed at the end of the line operator-linebreak + 87:11 warning '||' should be placed at the end of the line operator-linebreak + 88:11 warning '||' should be placed at the end of the line operator-linebreak + 90:11 warning '||' should be placed at the end of the line operator-linebreak + 91:11 warning '||' should be placed at the end of the line operator-linebreak app/scripts/lib/port-stream.js + 3:22 warning Missing space before function parentheses space-before-function-paren + 3:24 warning Missing space before opening brace space-before-blocks app/scripts/lib/tx-gas-utils.js + 84:2 warning Newline required at end of file but not found eol-last app/scripts/lib/tx-state-history-helper.js + 12:37 warning Missing space before function parentheses space-before-function-paren + 23:30 warning Missing space before function parentheses space-before-function-paren + 30:23 warning Missing space before function parentheses space-before-function-paren + 35:28 warning Missing space before function parentheses space-before-function-paren + 41:2 warning Newline required at end of file but not found eol-last app/scripts/lib/tx-state-manager.js + 94:13 warning 'value' is never reassigned. Use 'const' instead prefer-const ui/app/reducers.js + 45:7 warning 'state' is never reassigned. Use 'const' instead prefer-const + 53:7 warning 'stateString' is never reassigned. Use 'const' instead prefer-const ui/lib/tx-helper.js + 27:2 warning Newline required at end of file but not found eol-last ui/app/components/account-dropdowns.js + 163:1 warning More than 2 blank lines not allowed no-multiple-empty-lines ui/app/components/menu-droppo.js + 22:7 warning 'style' is never reassigned. Use 'const' instead prefer-const ui/app/components/shapeshift-form.js + 135:11 warning '&&' should be placed at the end of the line operator-linebreak ui/app/components/typed-message-renderer.js + 35:25 warning Missing space before function parentheses space-before-function-paren + 42:2 warning Newline required at end of file but not found eol-last mascara/server/index.js + 11:42 warning Use path.join() or path.resolve() instead of + to create paths no-path-concat + 12:36 warning Use path.join() or path.resolve() instead of + to create paths no-path-concat + 13:33 warning Use path.join() or path.resolve() instead of + to create paths no-path-concat + 14:40 warning Use path.join() or path.resolve() instead of + to create paths no-path-concat + 20:29 warning Use path.join() or path.resolve() instead of + to create paths no-path-concat + 21:29 warning Use path.join() or path.resolve() instead of + to create paths no-path-concat + 26:40 warning Use path.join() or path.resolve() instead of + to create paths no-path-concat ``` --- app/scripts/lib/tx-gas-utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/scripts/lib/tx-gas-utils.js') diff --git a/app/scripts/lib/tx-gas-utils.js b/app/scripts/lib/tx-gas-utils.js index 41f67e230..7e72ea71d 100644 --- a/app/scripts/lib/tx-gas-utils.js +++ b/app/scripts/lib/tx-gas-utils.js @@ -81,4 +81,4 @@ module.exports = class txProvideUtil { throw new Error(`Invalid transaction value of ${txParams.value} not a positive number.`) } } -} \ No newline at end of file +} -- cgit From 828734b977f7c26c249c81af73fc8eef0b66e416 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Thu, 14 Dec 2017 18:15:38 -0800 Subject: transactions:gas-utils - handle new type of estimateGas error --- app/scripts/lib/tx-gas-utils.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app/scripts/lib/tx-gas-utils.js') diff --git a/app/scripts/lib/tx-gas-utils.js b/app/scripts/lib/tx-gas-utils.js index 7e72ea71d..56bee19f7 100644 --- a/app/scripts/lib/tx-gas-utils.js +++ b/app/scripts/lib/tx-gas-utils.js @@ -22,7 +22,11 @@ module.exports = class txProvideUtil { try { estimatedGasHex = await this.estimateTxGas(txMeta, block.gasLimit) } catch (err) { - if (err.message.includes('Transaction execution error.')) { + const simulationFailed = ( + err.message.includes('Transaction execution error.') || + err.message.includes('gas required exceeds allowance or always failing transaction') + ) + if ( simulationFailed ) { txMeta.simulationFails = true return txMeta } -- cgit From f47e81e4937871a7a690e357443a728b9049b8f0 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Tue, 19 Dec 2017 14:28:02 -0800 Subject: transactions - throw error if dapp provides txParams whos value has a decimal --- app/scripts/lib/tx-gas-utils.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'app/scripts/lib/tx-gas-utils.js') diff --git a/app/scripts/lib/tx-gas-utils.js b/app/scripts/lib/tx-gas-utils.js index 56bee19f7..c00323a64 100644 --- a/app/scripts/lib/tx-gas-utils.js +++ b/app/scripts/lib/tx-gas-utils.js @@ -81,8 +81,15 @@ module.exports = class txProvideUtil { } async validateTxParams (txParams) { - if (('value' in txParams) && txParams.value.indexOf('-') === 0) { - throw new Error(`Invalid transaction value of ${txParams.value} not a positive number.`) + if ('value' in txParams) { + const value = txParams.value.toString() + if (value.indexOf('-') === 0) { + throw new Error(`Invalid transaction value of ${txParams.value} not a positive number.`) + } + + if (value.indexOf('.') >= 0) { + throw new Error(`Invalid transaction value of ${txParams.value} number must be in wei`) + } } } } -- cgit From 414f89668eb554e82ab22d3b3080322057388266 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Wed, 27 Dec 2017 17:27:48 -0800 Subject: Fix some silly linting issues. --- app/scripts/lib/tx-gas-utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/scripts/lib/tx-gas-utils.js') diff --git a/app/scripts/lib/tx-gas-utils.js b/app/scripts/lib/tx-gas-utils.js index 56bee19f7..247b34e47 100644 --- a/app/scripts/lib/tx-gas-utils.js +++ b/app/scripts/lib/tx-gas-utils.js @@ -26,7 +26,7 @@ module.exports = class txProvideUtil { err.message.includes('Transaction execution error.') || err.message.includes('gas required exceeds allowance or always failing transaction') ) - if ( simulationFailed ) { + if (simulationFailed) { txMeta.simulationFails = true return txMeta } -- cgit From 3f6cef0b3f56edc8cc0b66403f23ae216de7bcfa Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 2 Jan 2018 14:22:44 -0800 Subject: tx-gas-utils - tx-param-validation - use more intuitive check --- app/scripts/lib/tx-gas-utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/scripts/lib/tx-gas-utils.js') diff --git a/app/scripts/lib/tx-gas-utils.js b/app/scripts/lib/tx-gas-utils.js index c00323a64..bc891fc07 100644 --- a/app/scripts/lib/tx-gas-utils.js +++ b/app/scripts/lib/tx-gas-utils.js @@ -83,11 +83,11 @@ module.exports = class txProvideUtil { async validateTxParams (txParams) { if ('value' in txParams) { const value = txParams.value.toString() - if (value.indexOf('-') === 0) { + if (value.includes('-')) { throw new Error(`Invalid transaction value of ${txParams.value} not a positive number.`) } - if (value.indexOf('.') >= 0) { + if (value.includes('.')) { throw new Error(`Invalid transaction value of ${txParams.value} number must be in wei`) } } -- cgit From 39b700bf87f213d2fb06dcde85f4e6173a6ce70c Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 8 Jan 2018 03:16:20 -0800 Subject: Account for 0x/empty string address and contract creation --- app/scripts/lib/tx-gas-utils.js | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'app/scripts/lib/tx-gas-utils.js') diff --git a/app/scripts/lib/tx-gas-utils.js b/app/scripts/lib/tx-gas-utils.js index ccf8bb1b1..5e49fdb22 100644 --- a/app/scripts/lib/tx-gas-utils.js +++ b/app/scripts/lib/tx-gas-utils.js @@ -81,6 +81,7 @@ module.exports = class txProvideUtil { } async validateTxParams (txParams) { + this.validateRecipient(txParams) if ('value' in txParams) { const value = txParams.value.toString() if (value.includes('-')) { @@ -92,4 +93,14 @@ module.exports = class txProvideUtil { } } } + validateRecipient (txParams) { + if (txParams.to === '0x') { + if (txParams.data) { + delete txParams.to + } else { + throw new Error('Invalid recipient address') + } + } + return txParams + } } -- cgit From cd7eaaa735aa084cec0c4a647edf89bc5e4b2ec7 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 15 Jan 2018 15:08:07 -0800 Subject: Set gas limit to 21k for recipients with no code Fixes #2907 --- app/scripts/lib/tx-gas-utils.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'app/scripts/lib/tx-gas-utils.js') 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) } -- cgit From 8fb62b97c5b0901c7e4402d49538db87396c8579 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 16 Jan 2018 11:05:11 -0800 Subject: Create new flag for simple sends to avoid overloading other flag --- app/scripts/lib/tx-gas-utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/scripts/lib/tx-gas-utils.js') diff --git a/app/scripts/lib/tx-gas-utils.js b/app/scripts/lib/tx-gas-utils.js index d57c70b10..e80e0467e 100644 --- a/app/scripts/lib/tx-gas-utils.js +++ b/app/scripts/lib/tx-gas-utils.js @@ -53,7 +53,7 @@ module.exports = class txProvideUtil { const code = await this.query.getCode(recipient) if (hasRecipient && (!code || code === '0x')) { txParams.gas = SIMPLE_GAS_COST - txMeta.gasLimitSpecified = true // Prevents buffer addition + txMeta.simpleSend = true // Prevents buffer addition return SIMPLE_GAS_COST } @@ -72,7 +72,7 @@ module.exports = class txProvideUtil { // if gasLimit was specified and doesnt OOG, // use original specified amount - if (txMeta.gasLimitSpecified) { + if (txMeta.gasLimitSpecified || txMeta.simpleSend) { txMeta.estimatedGas = txParams.gas return } -- cgit From d7c8ec22a45a704036c4969496ef293c524f4542 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 17 Jan 2018 20:09:13 -0800 Subject: test - tx controller - fix txGasUtil reference --- app/scripts/lib/tx-gas-utils.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'app/scripts/lib/tx-gas-utils.js') diff --git a/app/scripts/lib/tx-gas-utils.js b/app/scripts/lib/tx-gas-utils.js index e80e0467e..f68f3a9e2 100644 --- a/app/scripts/lib/tx-gas-utils.js +++ b/app/scripts/lib/tx-gas-utils.js @@ -12,7 +12,8 @@ its passed ethquery and used to do things like calculate gas of a tx. */ -module.exports = class txProvideUtil { +module.exports = class TxGasUtil { + constructor (provider) { this.query = new EthQuery(provider) } -- cgit From dc3f3e79ca7319b97255456a5225a266d38a4d6f Mon Sep 17 00:00:00 2001 From: frankiebee Date: Wed, 14 Feb 2018 14:37:02 -0800 Subject: fix - hex prefix estimatedGas on txMeta --- app/scripts/lib/tx-gas-utils.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'app/scripts/lib/tx-gas-utils.js') diff --git a/app/scripts/lib/tx-gas-utils.js b/app/scripts/lib/tx-gas-utils.js index f68f3a9e2..6f6ff7852 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 addHexPrefix = require('ethereumjs-util').addHexPrefix const SIMPLE_GAS_COST = '0x5208' // Hex for 21000, cost of a simple send. /* @@ -13,7 +14,7 @@ and used to do things like calculate gas of a tx. */ module.exports = class TxGasUtil { - + constructor (provider) { this.query = new EthQuery(provider) } @@ -68,7 +69,7 @@ module.exports = class TxGasUtil { } setTxGas (txMeta, blockGasLimitHex, estimatedGasHex) { - txMeta.estimatedGas = estimatedGasHex + txMeta.estimatedGas = addHexPrefix(estimatedGasHex) const txParams = txMeta.txParams // if gasLimit was specified and doesnt OOG, -- cgit From d195cfab50b42d26f3cf9436845838e075e959de Mon Sep 17 00:00:00 2001 From: frankiebee Date: Tue, 13 Mar 2018 15:13:05 -0700 Subject: transactions - insure if a to field in tx params has a truthy valu that it is a valid addres and if it is falsy that it is not null to fix issue #3509 --- app/scripts/lib/tx-gas-utils.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'app/scripts/lib/tx-gas-utils.js') diff --git a/app/scripts/lib/tx-gas-utils.js b/app/scripts/lib/tx-gas-utils.js index 6f6ff7852..e61db3332 100644 --- a/app/scripts/lib/tx-gas-utils.js +++ b/app/scripts/lib/tx-gas-utils.js @@ -4,7 +4,7 @@ const { BnMultiplyByFraction, bnToHex, } = require('./util') -const addHexPrefix = require('ethereumjs-util').addHexPrefix +const {addHexPrefix, isValidAddress} = require('ethereumjs-util') const SIMPLE_GAS_COST = '0x5208' // Hex for 21000, cost of a simple send. /* @@ -101,6 +101,12 @@ module.exports = class TxGasUtil { async validateTxParams (txParams) { this.validateRecipient(txParams) + if ('to' in txParams) { + if ( txParams.to === null ) delete txParams.to + else if ( txParams.to !== undefined && !isValidAddress(txParams.to) ) { + throw new Error(`Invalid transaction value of ${txParams.to} not a valid to address.`) + } + } if ('value' in txParams) { const value = txParams.value.toString() if (value.includes('-')) { -- cgit From c465d510b100fdf9926413751df04cbd59de68eb Mon Sep 17 00:00:00 2001 From: frankiebee Date: Tue, 13 Mar 2018 15:26:45 -0700 Subject: fix error message --- app/scripts/lib/tx-gas-utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/scripts/lib/tx-gas-utils.js') diff --git a/app/scripts/lib/tx-gas-utils.js b/app/scripts/lib/tx-gas-utils.js index e61db3332..3b0494e04 100644 --- a/app/scripts/lib/tx-gas-utils.js +++ b/app/scripts/lib/tx-gas-utils.js @@ -104,7 +104,7 @@ module.exports = class TxGasUtil { if ('to' in txParams) { if ( txParams.to === null ) delete txParams.to else if ( txParams.to !== undefined && !isValidAddress(txParams.to) ) { - throw new Error(`Invalid transaction value of ${txParams.to} not a valid to address.`) + throw new Error(`Invalid recipient address`) } } if ('value' in txParams) { -- cgit From e5a83d3f1a3ebe9115c07e162ee4bca0f157b8b1 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Tue, 13 Mar 2018 15:32:03 -0700 Subject: transactions move validation of the to field to validateRecipient --- app/scripts/lib/tx-gas-utils.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'app/scripts/lib/tx-gas-utils.js') diff --git a/app/scripts/lib/tx-gas-utils.js b/app/scripts/lib/tx-gas-utils.js index 3b0494e04..a8f473a88 100644 --- a/app/scripts/lib/tx-gas-utils.js +++ b/app/scripts/lib/tx-gas-utils.js @@ -101,12 +101,6 @@ module.exports = class TxGasUtil { async validateTxParams (txParams) { this.validateRecipient(txParams) - if ('to' in txParams) { - if ( txParams.to === null ) delete txParams.to - else if ( txParams.to !== undefined && !isValidAddress(txParams.to) ) { - throw new Error(`Invalid recipient address`) - } - } if ('value' in txParams) { const value = txParams.value.toString() if (value.includes('-')) { @@ -119,12 +113,14 @@ module.exports = class TxGasUtil { } } validateRecipient (txParams) { - if (txParams.to === '0x') { + if (txParams.to === '0x' || txParams.to === null ) { if (txParams.data) { delete txParams.to } else { throw new Error('Invalid recipient address') } + } else if ( txParams.to !== undefined && !isValidAddress(txParams.to) ) { + throw new Error('Invalid recipient address') } return txParams } -- cgit From 22cd7882038d05e51c5b76f2f4c76c15b2fd89f6 Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 13 Mar 2018 15:39:33 -0700 Subject: tx-gas-utils - fix code style --- app/scripts/lib/tx-gas-utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/scripts/lib/tx-gas-utils.js') diff --git a/app/scripts/lib/tx-gas-utils.js b/app/scripts/lib/tx-gas-utils.js index a8f473a88..0fa9dd8d4 100644 --- a/app/scripts/lib/tx-gas-utils.js +++ b/app/scripts/lib/tx-gas-utils.js @@ -4,7 +4,7 @@ const { BnMultiplyByFraction, bnToHex, } = require('./util') -const {addHexPrefix, isValidAddress} = require('ethereumjs-util') +const { addHexPrefix, isValidAddress } = require('ethereumjs-util') const SIMPLE_GAS_COST = '0x5208' // Hex for 21000, cost of a simple send. /* -- cgit