diff --git a/.jshintrc b/.jshintrc index 8471c8490ca..7bc37324e70 100644 --- a/.jshintrc +++ b/.jshintrc @@ -3,6 +3,7 @@ "bitwise": true, "camelcase": true, "eqeqeq": true, + "esversion": 8, "freeze": true, "funcscope": false, "maxcomplexity": 15, diff --git a/packages/web3-core-method/src/index.js b/packages/web3-core-method/src/index.js index fb9416ed8be..8b54d8ad2be 100644 --- a/packages/web3-core-method/src/index.js +++ b/packages/web3-core-method/src/index.js @@ -453,7 +453,7 @@ Method.prototype._confirmTransaction = function (defer, result, payload) { gas: parsedTx.gasLimit.toHexString(), gasPrice: parsedTx.gasPrice.toHexString(), value: parsedTx.value.toHexString() - }) + }); } // Get revert reason string with eth_call @@ -549,19 +549,19 @@ Method.prototype._confirmTransaction = function (defer, result, payload) { var startWatching = function (existingReceipt) { const startInterval = () => { intervalId = setInterval(checkConfirmation.bind(null, existingReceipt, true), 1000); - } + }; if (!this.requestManager.provider.on) { - startInterval() + startInterval(); } else { _ethereumCall.subscribe('newBlockHeaders', function (err, blockHeader, sub) { if (err || !blockHeader) { // fall back to polling - startInterval() + startInterval(); } else { checkConfirmation(existingReceipt, false, err, blockHeader, sub); } - }) + }); } }.bind(this); diff --git a/packages/web3-core-subscriptions/src/subscription.js b/packages/web3-core-subscriptions/src/subscription.js index 0ed229a43ae..9303b98401d 100644 --- a/packages/web3-core-subscriptions/src/subscription.js +++ b/packages/web3-core-subscriptions/src/subscription.js @@ -227,7 +227,7 @@ Subscription.prototype.subscribe = function() { // Re-subscription only: continue fetching from the last block we received. // a dropped connection may have resulted in gaps in the logs... if (this.lastBlock && _.isObject(this.options.params)){ - payload.params[1] = this.options.params + payload.params[1] = this.options.params; payload.params[1].fromBlock = formatters.inputBlockNumberFormatter(this.lastBlock + 1); } diff --git a/packages/web3-eth-abi/src/index.js b/packages/web3-eth-abi/src/index.js index 5bb706f114e..b9d2220a5db 100644 --- a/packages/web3-eth-abi/src/index.js +++ b/packages/web3-eth-abi/src/index.js @@ -100,16 +100,16 @@ ABICoder.prototype.encodeParameter = function (type, param) { */ ABICoder.prototype.encodeParameters = function (types, params) { var self = this; - types = self.mapTypes(types) + types = self.mapTypes(types); params = params.map(function (param, index) { - let type = types[index] + let type = types[index]; if (typeof type === 'object' && type.type) { // We may get a named type of shape {name, type} - type = type.type + type = type.type; } - param = self.formatParam(type, param) + param = self.formatParam(type, param); // Format params for tuples if (typeof type === 'string' && type.includes('tuple')) { @@ -121,21 +121,21 @@ ABICoder.prototype.encodeParameters = function (types, params) { ethersAbiCoder._getCoder(ParamType.from(coder.type.replace('[]', ''))), p ) - ) + ); } coder.coders.forEach((c, i) => { if (c.name === 'tuple') { - modifyParams(c, param[i]) + modifyParams(c, param[i]); } else { - param[i] = self.formatParam(c.name, param[i]) + param[i] = self.formatParam(c.name, param[i]); } - }) - } - modifyParams(coder, param) + }); + }; + modifyParams(coder, param); } return param; - }) + }); return ethersAbiCoder.encode(types, params); }; @@ -155,7 +155,7 @@ ABICoder.prototype.mapTypes = function (types) { // recognize former type. Solidity docs say `Function` is a bytes24 // encoding the contract address followed by the function selector hash. if (typeof type === 'object' && type.type === 'function'){ - type.type = "bytes24" + type.type = "bytes24"; } if (self.isSimplifiedStructFormat(type)) { var structName = Object.keys(type)[0]; @@ -259,7 +259,7 @@ ABICoder.prototype.formatParam = function (type, param) { } if (type.match(paramTypeBytesArray) || type.match(paramTypeNumberArray)) { - return param.map(p => this.formatParam(type.replace('[]', ''), p)) + return param.map(p => this.formatParam(type.replace('[]', ''), p)); } // Format correct width for u?int[0-9]* @@ -288,17 +288,17 @@ ABICoder.prototype.formatParam = function (type, param) { } if (param.length < maxSize) { // pad to correct length - param = utils.rightPad(param, size * 2) + param = utils.rightPad(param, size * 2); } } // format odd-length bytes to even-length if (param.length % 2 === 1) { - param = '0x0' + param.substring(2) + param = '0x0' + param.substring(2); } } - return param + return param; }; /** diff --git a/packages/web3-eth-accounts/src/index.js b/packages/web3-eth-accounts/src/index.js index 550736f8bb8..6df1f8ccf1f 100644 --- a/packages/web3-eth-accounts/src/index.js +++ b/packages/web3-eth-accounts/src/index.js @@ -149,29 +149,7 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca } function signed(tx) { - if (tx.common && (tx.chain && tx.hardfork)) { - error = new Error( - 'Please provide the ethereumjs-common object or the chain and hardfork property but not all together.' - ); - } - - if ((tx.chain && !tx.hardfork) || (tx.hardfork && !tx.chain)) { - error = new Error( - 'When specifying chain and hardfork, both values must be defined. ' + - 'Received "chain": ' + tx.chain + ', "hardfork": ' + tx.hardfork - ); - } - - if (!tx.gas && !tx.gasLimit) { - error = new Error('"gas" is missing'); - } - - if (tx.nonce < 0 || - tx.gas < 0 || - tx.gasPrice < 0 || - tx.chainId < 0) { - error = new Error('Gas, gasPrice, nonce or chainId is lower than 0'); - } + const error = _validateTransactionForSigning(tx); if (error) { callback(error); @@ -280,6 +258,35 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca }); }; +function _validateTransactionForSigning(tx) { + if (tx.common && (tx.chain && tx.hardfork)) { + return new Error( + 'Please provide the ethereumjs-common object or the chain and hardfork property but not all together.' + ); + } + + if ((tx.chain && !tx.hardfork) || (tx.hardfork && !tx.chain)) { + return new Error( + 'When specifying chain and hardfork, both values must be defined. ' + + 'Received "chain": ' + tx.chain + ', "hardfork": ' + tx.hardfork + ); + } + + if (!tx.gas && !tx.gasLimit) { + return new Error('"gas" is missing'); + } + + if (tx.nonce < 0 || + tx.gas < 0 || + tx.gasPrice < 0 || + tx.chainId < 0) { + return new Error('Gas, gasPrice, nonce or chainId is lower than 0'); + } + + return; +} + + /* jshint ignore:start */ Accounts.prototype.recoverTransaction = function recoverTransaction(rawTx) { var values = RLP.decode(rawTx); @@ -294,7 +301,7 @@ Accounts.prototype.recoverTransaction = function recoverTransaction(rawTx) { Accounts.prototype.hashMessage = function hashMessage(data) { var messageHex = utils.isHexStrict(data) ? data : utils.utf8ToHex(data); - var messageBytes = utils.hexToBytes(messageHex) + var messageBytes = utils.hexToBytes(messageHex); var messageBuffer = Buffer.from(messageBytes); var preamble = '\x19Ethereum Signed Message:\n' + messageBytes.length; var preambleBuffer = Buffer.from(preamble); @@ -630,5 +637,4 @@ function storageAvailable(type) { } } - module.exports = Accounts; diff --git a/packages/web3/src/index.js b/packages/web3/src/index.js index 2967dd202f5..f7629944df0 100644 --- a/packages/web3/src/index.js +++ b/packages/web3/src/index.js @@ -53,6 +53,7 @@ var Web3 = function Web3() { // overwrite package setProvider var setProvider = this.setProvider; this.setProvider = function (provider, net) { + /*jshint unused: false */ setProvider.apply(_this, arguments); _this.eth.setRequestManager(_this._requestManager);