From a69b9f6a634114651322f4bec372aae168597841 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 17 May 2021 14:24:01 -0400 Subject: [PATCH 01/19] removed some of the underscore methods in web3-core-method --- packages/web3-core-method/src/index.js | 30 ++++++++++++++------------ 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/web3-core-method/src/index.js b/packages/web3-core-method/src/index.js index 63ce5acbc00..f7d224137a9 100644 --- a/packages/web3-core-method/src/index.js +++ b/packages/web3-core-method/src/index.js @@ -102,7 +102,7 @@ Method.prototype.attachToObject = function (obj) { * @return {String} name of jsonrpc method */ Method.prototype.getCall = function (args) { - return _.isFunction(this.call) ? this.call(args) : this.call; + return typeof this.call === 'function' ? this.call(args) : this.call; }; /** @@ -113,7 +113,7 @@ Method.prototype.getCall = function (args) { * @return {Function|Null} callback, if exists */ Method.prototype.extractCallback = function (args) { - if (_.isFunction(args[args.length - 1])) { + if (typeof (args[args.length - 1]) === 'function') { return args.pop(); // modify the args array! } }; @@ -161,7 +161,7 @@ Method.prototype.formatInput = function (args) { Method.prototype.formatOutput = function (result) { var _this = this; - if (_.isArray(result)) { + if (Array.isArray(result)) { return result.map(function (res) { return _this.outputFormatter && res ? _this.outputFormatter(res) : res; }); @@ -180,6 +180,8 @@ Method.prototype.formatOutput = function (result) { Method.prototype.toPayload = function (args) { var call = this.getCall(args); var callback = this.extractCallback(args); + //check if last args is a function, if so pop it out. + var params = this.formatInput(args); this.validateArgs(params); @@ -206,8 +208,8 @@ Method.prototype._confirmTransaction = function (defer, result, payload) { intervalId = null, lastBlock = null, receiptJSON = '', - gasProvided = (_.isObject(payload.params[0]) && payload.params[0].gas) ? payload.params[0].gas : null, - isContractDeployment = _.isObject(payload.params[0]) && + gasProvided = ((typeof payload.params[0] === 'object' && payload.params[0] != null) && payload.params[0].gas) ? payload.params[0].gas : null, + isContractDeployment = (typeof payload.params[0] === 'object' && payload.params[0] != null) && payload.params[0].data && payload.params[0].from && !payload.params[0].to, @@ -258,7 +260,7 @@ Method.prototype._confirmTransaction = function (defer, result, payload) { ]; // attach methods to this._ethereumCall var _ethereumCall = {}; - _.each(_ethereumCalls, function (mthd) { + _ethereumCalls.forEach(mthd => { mthd.attachToObject(_ethereumCall); mthd.requestManager = method.requestManager; // assign rather than call setRequestManager() }); @@ -591,11 +593,11 @@ var getWallet = function (from, accounts) { var wallet = null; // is index given - if (_.isNumber(from)) { + if (typeof from === 'number') { wallet = accounts.wallet[from]; // is account given - } else if (_.isObject(from) && from.address && from.privateKey) { + } else if (typeof from === 'object' && from.address && from.privateKey) { wallet = from; // search in wallet for address @@ -689,10 +691,10 @@ Method.prototype.buildCall = function () { // SENDS the SIGNED SIGNATURE var sendSignedTx = function (sign) { - var signedPayload = _.extend({}, payload, { + var signedPayload = { ... payload, method: 'eth_sendRawTransaction', params: [sign.rawTransaction] - }); + }; method.requestManager.send(signedPayload, sendTxCallback); }; @@ -706,7 +708,7 @@ Method.prototype.buildCall = function () { // ETH_SENDTRANSACTION if (payload.method === 'eth_sendTransaction') { var tx = payload.params[0]; - wallet = getWallet((_.isObject(tx)) ? tx.from : null, method.accounts); + wallet = getWallet((typeof tx === 'object') ? tx.from : null, method.accounts); // If wallet was found, sign tx, and send using sendRawTransaction @@ -728,7 +730,7 @@ Method.prototype.buildCall = function () { method.accounts.signTransaction(txOptions, wallet.privateKey) .then(sendSignedTx) .catch(function (err) { - if (_.isFunction(defer.eventEmitter.listeners) && defer.eventEmitter.listeners('error').length) { + if (typeof defer.eventEmitter.listeners === 'function' && defer.eventEmitter.listeners('error').length) { try { defer.eventEmitter.emit('error', err); } catch (err) { @@ -769,7 +771,7 @@ Method.prototype.buildCall = function () { }; // Send the actual transaction - if (isSendTx && _.isObject(payload.params[0]) && typeof payload.params[0].gasPrice === 'undefined') { + if (isSendTx && typeof payload.params[0] === 'object' && typeof payload.params[0].gasPrice === 'undefined') { var getGasPrice = (new Method({ name: 'getGasPrice', @@ -866,7 +868,7 @@ Method.prototype.getRevertReason = function (txOptions, blockNumber) { * @returns {Boolean} */ Method.prototype.isRevertReasonString = function (data) { - return _.isString(data) && ((data.length - 2) / 2) % 32 === 4 && data.substring(0, 10) === '0x08c379a0'; + return typeof data === 'string' && ((data.length - 2) / 2) % 32 === 4 && data.substring(0, 10) === '0x08c379a0'; }; /** From cea0439cf55bf01987b45e963707ab90f6b52ae6 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 18 May 2021 09:22:08 -0400 Subject: [PATCH 02/19] removed underscore from bzz --- packages/web3-bzz/src/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/web3-bzz/src/index.js b/packages/web3-bzz/src/index.js index 7f87381f838..8b4379b8cca 100644 --- a/packages/web3-bzz/src/index.js +++ b/packages/web3-bzz/src/index.js @@ -22,7 +22,7 @@ "use strict"; -var _ = require('underscore'); + var swarm = require("swarm-js"); @@ -52,7 +52,7 @@ if (typeof ethereum !== 'undefined' && ethereum.bzz) { Bzz.prototype.setProvider = function(provider) { // is ethereum provider - if(_.isObject(provider) && _.isString(provider.bzz)) { + if(typeof provider === 'object' && provider != null && typeof provider.bzz === 'string') { provider = provider.bzz; // is no string, set default } @@ -61,7 +61,7 @@ Bzz.prototype.setProvider = function(provider) { // } - if(_.isString(provider)) { + if(typeof provider === 'string') { this.currentProvider = provider; } else { this.currentProvider = null; From 624bf3117ab0a31b44332bd802d6ace1e2f97b3e Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 18 May 2021 09:55:33 -0400 Subject: [PATCH 03/19] adding subscriptions --- .../src/subscription.js | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/web3-core-subscriptions/src/subscription.js b/packages/web3-core-subscriptions/src/subscription.js index 9303b98401d..b4453042fdb 100644 --- a/packages/web3-core-subscriptions/src/subscription.js +++ b/packages/web3-core-subscriptions/src/subscription.js @@ -27,11 +27,15 @@ var errors = require('web3-core-helpers').errors; var EventEmitter = require('eventemitter3'); var formatters = require('web3-core-helpers').formatters; +function identity(value) { + return value; +} + function Subscription(options) { EventEmitter.call(this); this.id = null; - this.callback = _.identity; + this.callback = identity; this.arguments = null; this.lastBlock = null; // "from" block tracker for backfilling events on reconnection @@ -56,7 +60,7 @@ Subscription.prototype.constructor = Subscription; */ Subscription.prototype._extractCallback = function (args) { - if (_.isFunction(args[args.length - 1])) { + if (typeof args[args.length - 1] === 'function') { return args.pop(); // modify the args array! } }; @@ -136,7 +140,7 @@ Subscription.prototype._formatOutput = function (result) { */ Subscription.prototype._toPayload = function (args) { var params = []; - this.callback = this._extractCallback(args) || _.identity; + this.callback = this._extractCallback(args) || identity; if (!this.subscriptionMethod) { this.subscriptionMethod = args.shift(); @@ -226,7 +230,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)){ + if (this.lastBlock && typeof this.options.params === 'object' && !!null ){ payload.params[1] = this.options.params; payload.params[1].fromBlock = formatters.inputBlockNumberFormatter(this.lastBlock + 1); } @@ -240,7 +244,7 @@ Subscription.prototype.subscribe = function() { this.options.params = payload.params[1]; // get past logs, if fromBlock is available - if(payload.params[0] === 'logs' && _.isObject(payload.params[1]) && payload.params[1].hasOwnProperty('fromBlock') && isFinite(payload.params[1].fromBlock)) { + if(payload.params[0] === 'logs' && typeof payload.params[1] === 'object' && !!payload.params[1] && payload.params[1].hasOwnProperty('fromBlock') && isFinite(payload.params[1].fromBlock)) { // send the subscription request // copy the params to avoid race-condition with deletion below this block @@ -283,7 +287,7 @@ Subscription.prototype.subscribe = function() { // call callback on notifications _this.options.requestManager.addSubscription(_this, function(error, result) { if (!error) { - if (!_.isArray(result)) { + if (!Array.isArray(result)) { result = [result]; } @@ -291,9 +295,9 @@ Subscription.prototype.subscribe = function() { var output = _this._formatOutput(resultItem); // Track current block (for gaps introduced by dropped connections) - _this.lastBlock = _.isObject(output) ? output.blockNumber : null; + _this.lastBlock = typeof output === 'object' ? output.blockNumber : null; - if (_.isFunction(_this.options.subscription.subscriptionHandler)) { + if (typeof _this.options.subscription.subscriptionHandler === 'function' ) { return _this.options.subscription.subscriptionHandler.call(_this, output); } else { _this.emit('data', output); From 55b315ab6f7871c83d819e828f3809f53e6abdd1 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 18 May 2021 15:48:27 -0400 Subject: [PATCH 04/19] fixing up test cases --- packages/web3-core-method/src/index.js | 14 +++++++------- .../web3-core-subscriptions/src/subscription.js | 5 ++--- packages/web3-eth/src/getNetworkType.js | 6 ++---- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/packages/web3-core-method/src/index.js b/packages/web3-core-method/src/index.js index f7d224137a9..70ddd63bc60 100644 --- a/packages/web3-core-method/src/index.js +++ b/packages/web3-core-method/src/index.js @@ -23,7 +23,6 @@ 'use strict'; -var _ = require('underscore'); var errors = require('web3-core-helpers').errors; var formatters = require('web3-core-helpers').formatters; var utils = require('web3-utils'); @@ -208,8 +207,8 @@ Method.prototype._confirmTransaction = function (defer, result, payload) { intervalId = null, lastBlock = null, receiptJSON = '', - gasProvided = ((typeof payload.params[0] === 'object' && payload.params[0] != null) && payload.params[0].gas) ? payload.params[0].gas : null, - isContractDeployment = (typeof payload.params[0] === 'object' && payload.params[0] != null) && + gasProvided = ((typeof payload.params[0] === 'object' && !!payload.params[0]) && payload.params[0].gas) ? payload.params[0].gas : null, + isContractDeployment = (typeof payload.params[0] === 'object' && !!payload.params[0]) && payload.params[0].data && payload.params[0].from && !payload.params[0].to, @@ -597,7 +596,7 @@ var getWallet = function (from, accounts) { wallet = accounts.wallet[from]; // is account given - } else if (typeof from === 'object' && from.address && from.privateKey) { + } else if (typeof from === 'object' && !!from && from.address && from.privateKey) { wallet = from; // search in wallet for address @@ -708,12 +707,13 @@ Method.prototype.buildCall = function () { // ETH_SENDTRANSACTION if (payload.method === 'eth_sendTransaction') { var tx = payload.params[0]; - wallet = getWallet((typeof tx === 'object') ? tx.from : null, method.accounts); + wallet = getWallet((typeof tx === 'object' && !!tx) ? tx.from : null, method.accounts); // If wallet was found, sign tx, and send using sendRawTransaction if (wallet && wallet.privateKey) { - var txOptions = _.omit(tx, 'from'); + var txOptions = JSON.parse(JSON.stringify(tx)); + delete txOptions['from']; if (method.defaultChain && !txOptions.chain) { txOptions.chain = method.defaultChain; @@ -771,7 +771,7 @@ Method.prototype.buildCall = function () { }; // Send the actual transaction - if (isSendTx && typeof payload.params[0] === 'object' && typeof payload.params[0].gasPrice === 'undefined') { + if (isSendTx && typeof payload.params[0] === 'object' && !!paypload.params[0] && typeof payload.params[0].gasPrice === 'undefined') { var getGasPrice = (new Method({ name: 'getGasPrice', diff --git a/packages/web3-core-subscriptions/src/subscription.js b/packages/web3-core-subscriptions/src/subscription.js index b4453042fdb..aa83059d003 100644 --- a/packages/web3-core-subscriptions/src/subscription.js +++ b/packages/web3-core-subscriptions/src/subscription.js @@ -22,7 +22,6 @@ "use strict"; -var _ = require('underscore'); var errors = require('web3-core-helpers').errors; var EventEmitter = require('eventemitter3'); var formatters = require('web3-core-helpers').formatters; @@ -230,7 +229,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 && typeof this.options.params === 'object' && !!null ){ + if (this.lastBlock && typeof this.options.params === 'object' && !!this.options.params ){ payload.params[1] = this.options.params; payload.params[1].fromBlock = formatters.inputBlockNumberFormatter(this.lastBlock + 1); } @@ -295,7 +294,7 @@ Subscription.prototype.subscribe = function() { var output = _this._formatOutput(resultItem); // Track current block (for gaps introduced by dropped connections) - _this.lastBlock = typeof output === 'object' ? output.blockNumber : null; + _this.lastBlock = typeof output === 'object' && !!output ? output.blockNumber : null; if (typeof _this.options.subscription.subscriptionHandler === 'function' ) { return _this.options.subscription.subscriptionHandler.call(_this, output); diff --git a/packages/web3-eth/src/getNetworkType.js b/packages/web3-eth/src/getNetworkType.js index 3be3a2027e6..5f9b9b31e57 100644 --- a/packages/web3-eth/src/getNetworkType.js +++ b/packages/web3-eth/src/getNetworkType.js @@ -22,8 +22,6 @@ "use strict"; -var _ = require('underscore'); - var getNetworkType = function (callback) { var _this = this, id; @@ -64,14 +62,14 @@ var getNetworkType = function (callback) { returnValue = 'kovan'; } - if (_.isFunction(callback)) { + if (typeof callback === 'function') { callback(null, returnValue); } return returnValue; }) .catch(function (err) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { callback(err); } else { throw err; From addcf933279dba7ff82e8a93d3906eef9f2a1e15 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 18 May 2021 16:00:29 -0400 Subject: [PATCH 05/19] changing variable names --- packages/web3-bzz/src/index.js | 2 +- packages/web3-core-method/src/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/web3-bzz/src/index.js b/packages/web3-bzz/src/index.js index 8b4379b8cca..1c32b9c8820 100644 --- a/packages/web3-bzz/src/index.js +++ b/packages/web3-bzz/src/index.js @@ -52,7 +52,7 @@ if (typeof ethereum !== 'undefined' && ethereum.bzz) { Bzz.prototype.setProvider = function(provider) { // is ethereum provider - if(typeof provider === 'object' && provider != null && typeof provider.bzz === 'string') { + if(typeof provider === 'object' && !!provider && typeof provider.bzz === 'string') { provider = provider.bzz; // is no string, set default } diff --git a/packages/web3-core-method/src/index.js b/packages/web3-core-method/src/index.js index 70ddd63bc60..bf0ccbeaade 100644 --- a/packages/web3-core-method/src/index.js +++ b/packages/web3-core-method/src/index.js @@ -771,7 +771,7 @@ Method.prototype.buildCall = function () { }; // Send the actual transaction - if (isSendTx && typeof payload.params[0] === 'object' && !!paypload.params[0] && typeof payload.params[0].gasPrice === 'undefined') { + if (isSendTx && typeof payload.params[0] === 'object' && !!payload.params[0] && typeof payload.params[0].gasPrice === 'undefined') { var getGasPrice = (new Method({ name: 'getGasPrice', From 0c8bcbc3e0ba0f841a3a103a7f5cbf983495cd5d Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 18 May 2021 16:29:28 -0400 Subject: [PATCH 06/19] removed underscore from formatters.js --- packages/web3-core-helpers/src/formatters.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/web3-core-helpers/src/formatters.js b/packages/web3-core-helpers/src/formatters.js index 6f9af04de0d..86a0191f007 100644 --- a/packages/web3-core-helpers/src/formatters.js +++ b/packages/web3-core-helpers/src/formatters.js @@ -23,7 +23,6 @@ "use strict"; -var _ = require('underscore'); var utils = require('web3-utils'); var Iban = require('web3-eth-iban'); @@ -121,7 +120,7 @@ var inputBlockNumberFormatter = function (blockNumber) { return '0x0'; } - return (utils.isHexStrict(blockNumber)) ? ((_.isString(blockNumber)) ? blockNumber.toLowerCase() : blockNumber) : utils.numberToHex(blockNumber); + return (utils.isHexStrict(blockNumber)) ? ((typeof blockNumber === 'string') ? blockNumber.toLowerCase() : blockNumber) : utils.numberToHex(blockNumber); }; /** @@ -201,10 +200,10 @@ var inputTransactionFormatter = function (options) { options = _txInputFormatter(options); // check from, only if not number, or object - if (!_.isNumber(options.from) && !_.isObject(options.from)) { + if (!(typeof options.from === 'number') && !(typeof options.from === 'object' && !!options.from)) { options.from = options.from || (this ? this.defaultAccount : null); - if (!options.from && !_.isNumber(options.from)) { + if (!options.from && !(typeof options.from === 'number')) { throw new Error('The send transactions "from" field must be defined!'); } @@ -274,7 +273,7 @@ var outputTransactionReceiptFormatter = function (receipt) { receipt.cumulativeGasUsed = utils.hexToNumber(receipt.cumulativeGasUsed); receipt.gasUsed = utils.hexToNumber(receipt.gasUsed); - if (_.isArray(receipt.logs)) { + if (Array.isArray(receipt.logs)) { receipt.logs = receipt.logs.map(outputLogFormatter); } @@ -311,9 +310,9 @@ var outputBlockFormatter = function (block) { if (block.totalDifficulty) block.totalDifficulty = outputBigNumberFormatter(block.totalDifficulty); - if (_.isArray(block.transactions)) { + if (Array.isArray(block.transactions)) { block.transactions.forEach(function (item) { - if (!_.isString(item)) + if (!(typeof item === 'string')) return outputTransactionFormatter(item); }); } @@ -358,13 +357,13 @@ var inputLogFormatter = function (options) { // make sure topics, get converted to hex options.topics = options.topics || []; options.topics = options.topics.map(function (topic) { - return (_.isArray(topic)) ? topic.map(toTopic) : toTopic(topic); + return (Array.isArray(topic)) ? topic.map(toTopic) : toTopic(topic); }); toTopic = null; if (options.address) { - options.address = (_.isArray(options.address)) ? options.address.map(function (addr) { + options.address = (Array.isArray(options.address)) ? options.address.map(function (addr) { return inputAddressFormatter(addr); }) : inputAddressFormatter(options.address); } @@ -424,7 +423,7 @@ var inputPostFormatter = function (post) { post.priority = utils.numberToHex(post.priority); // fallback - if (!_.isArray(post.topics)) { + if (!Array.isArray(post.topics)) { post.topics = post.topics ? [post.topics] : []; } From 65b7da68371910976cb8c4cee9e3efc366272c3b Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 18 May 2021 16:44:39 -0400 Subject: [PATCH 07/19] removed underscore from request manager and abi --- packages/web3-core-requestmanager/src/index.js | 3 +-- packages/web3-eth-abi/src/index.js | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/web3-core-requestmanager/src/index.js b/packages/web3-core-requestmanager/src/index.js index 4e472fc8f41..31062ec61d6 100644 --- a/packages/web3-core-requestmanager/src/index.js +++ b/packages/web3-core-requestmanager/src/index.js @@ -21,7 +21,6 @@ const { callbackify } = require('util'); -var _ = require('underscore'); var errors = require('web3-core-helpers').errors; var Jsonrpc = require('./jsonrpc.js'); var BatchManager = require('./batch.js'); @@ -207,7 +206,7 @@ RequestManager.prototype.sendBatch = function (data, callback) { return callback(err); } - if (!_.isArray(results)) { + if (!Array.isArray(results)) { return callback(errors.InvalidResponse(results)); } diff --git a/packages/web3-eth-abi/src/index.js b/packages/web3-eth-abi/src/index.js index 34801939265..ea880ac83fb 100644 --- a/packages/web3-eth-abi/src/index.js +++ b/packages/web3-eth-abi/src/index.js @@ -22,13 +22,12 @@ */ var Buffer = require('buffer').Buffer; -var _ = require('underscore'); var utils = require('web3-utils'); var EthersAbiCoder = require('@ethersproject/abi').AbiCoder; var ParamType = require('@ethersproject/abi').ParamType; var ethersAbiCoder = new EthersAbiCoder(function (type, value) { - if (type.match(/^u?int/) && !_.isArray(value) && (!_.isObject(value) || value.constructor.name !== 'BN')) { + if (type.match(/^u?int/) && !Array.isArray(value) && (!(typeof value === 'object' && !!value) || value.constructor.name !== 'BN')) { return value.toString(); } return value; @@ -52,7 +51,7 @@ var ABICoder = function () { * @return {String} encoded function name */ ABICoder.prototype.encodeFunctionSignature = function (functionName) { - if (_.isObject(functionName)) { + if (typeof functionName === 'function' || typeof functionName === 'object' && functionName) { functionName = utils._jsonInterfaceMethodToString(functionName); } @@ -67,7 +66,7 @@ ABICoder.prototype.encodeFunctionSignature = function (functionName) { * @return {String} encoded function name */ ABICoder.prototype.encodeEventSignature = function (functionName) { - if (_.isObject(functionName)) { + if (typeof functionName === 'function' || typeof functionName === 'object' && functionName) { functionName = utils._jsonInterfaceMethodToString(functionName); } @@ -367,7 +366,7 @@ ABICoder.prototype.decodeParametersWith = function (outputs, bytes, loose) { returnValue[i] = decodedValue; - if (_.isObject(output) && output.name) { + if ((typeof output === 'function' || typeof output === 'object' && !!output) && output.name) { returnValue[output.name] = decodedValue; } @@ -388,7 +387,7 @@ ABICoder.prototype.decodeParametersWith = function (outputs, bytes, loose) { */ ABICoder.prototype.decodeLog = function (inputs, data, topics) { var _this = this; - topics = _.isArray(topics) ? topics : [topics]; + topics = Array.isArray(topics) ? topics : [topics]; data = data || ''; From db3ab3d3248af3a10a72d2d35a5b427365ba128d Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 18 May 2021 17:00:06 -0400 Subject: [PATCH 08/19] removing underscore in the rest of the web3 packages --- packages/web3-eth-accounts/src/index.js | 21 +++++++------ packages/web3-eth-contract/src/index.js | 38 +++++++++++------------- packages/web3-eth-ens/src/ENS.js | 5 ++-- packages/web3-eth/src/index.js | 21 +++++++------ packages/web3-providers-ipc/src/index.js | 5 ++-- packages/web3-utils/src/index.js | 26 ++++++++-------- packages/web3-utils/src/soliditySha3.js | 15 +++++----- packages/web3-utils/src/utils.js | 17 +++++------ 8 files changed, 69 insertions(+), 79 deletions(-) diff --git a/packages/web3-eth-accounts/src/index.js b/packages/web3-eth-accounts/src/index.js index 6df1f8ccf1f..1e963428bf4 100644 --- a/packages/web3-eth-accounts/src/index.js +++ b/packages/web3-eth-accounts/src/index.js @@ -22,7 +22,6 @@ 'use strict'; -var _ = require('underscore'); var core = require('web3-core'); var Method = require('web3-core-method'); var Account = require('eth-lib/lib/account'); @@ -39,7 +38,7 @@ var Common = require('ethereumjs-common').default; var isNot = function(value) { - return (_.isUndefined(value) || _.isNull(value)); + return (typeof value === 'undefined') || value == null; }; var Accounts = function Accounts() { @@ -87,7 +86,7 @@ var Accounts = function Accounts() { ]; // attach methods to this._ethereumCall this._ethereumCall = {}; - _.each(_ethereumCall, function(method) { + _ethereumCall.forEach( (method) => { method.attachToObject(_this._ethereumCall); method.setRequestManager(_this._requestManager); }); @@ -157,7 +156,7 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca } try { - var transaction = helpers.formatters.inputCallFormatter(_.clone(tx)); + var transaction = helpers.formatters.inputCallFormatter(Object.assign({},tx)); transaction.to = transaction.to || '0x'; transaction.data = transaction.data || '0x'; transaction.value = transaction.value || '0x'; @@ -254,7 +253,7 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca if (isNot(args[0]) || isNot(args[1]) || isNot(args[2]) || isNot(args[3])) { throw new Error('One of the values "chainId", "networkId", "gasPrice", or "nonce" couldn\'t be fetched: ' + JSON.stringify(args)); } - return signed(_.extend(tx, {chainId: args[0], gasPrice: args[1], nonce: args[2], networkId: args[3]})); + return signed({ ...tx, chainId: args[0], gasPrice: args[1], nonce: args[2], networkId: args[3]}); }); }; @@ -336,7 +335,7 @@ Accounts.prototype.recover = function recover(message, signature, preFixed) { var args = [].slice.apply(arguments); - if (_.isObject(message)) { + if (typeof message === 'object' && !!message) { return this.recover(message.messageHash, Account.encodeSignature([message.v, message.r, message.s]), true); } @@ -346,7 +345,7 @@ Accounts.prototype.recover = function recover(message, signature, preFixed) { if (args.length >= 4) { preFixed = args.slice(-1)[0]; - preFixed = _.isBoolean(preFixed) ? !!preFixed : false; + preFixed = typeof preFixed === 'boolean' ? !!preFixed : false; return this.recover(message, Account.encodeSignature(args.slice(1, 4)), preFixed); // v, r, s } @@ -357,11 +356,11 @@ Accounts.prototype.recover = function recover(message, signature, preFixed) { Accounts.prototype.decrypt = function(v3Keystore, password, nonStrict) { /* jshint maxcomplexity: 10 */ - if (!_.isString(password)) { + if (!typeof password === 'string') { throw new Error('No password given.'); } - var json = (_.isObject(v3Keystore)) ? v3Keystore : JSON.parse(nonStrict ? v3Keystore.toLowerCase() : v3Keystore); + var json = (typeof v3Keystore === 'object' && !!v3Keystore) ? v3Keystore : JSON.parse(nonStrict ? v3Keystore.toLowerCase() : v3Keystore); if (json.version !== 3) { throw new Error('Not a valid V3 wallet'); @@ -470,7 +469,7 @@ function Wallet(accounts) { Wallet.prototype._findSafeIndex = function(pointer) { pointer = pointer || 0; - if (_.has(this, pointer)) { + if (this.hasOwnProperty(pointer)) { return this._findSafeIndex(pointer + 1); } else { return pointer; @@ -499,7 +498,7 @@ Wallet.prototype.create = function(numberOfAccounts, entropy) { Wallet.prototype.add = function(account) { - if (_.isString(account)) { + if (typeof account == 'string') { account = this._accounts.privateKeyToAccount(account); } if (!this[account.address]) { diff --git a/packages/web3-eth-contract/src/index.js b/packages/web3-eth-contract/src/index.js index fd46f9be6c5..5df766b2f87 100644 --- a/packages/web3-eth-contract/src/index.js +++ b/packages/web3-eth-contract/src/index.js @@ -30,8 +30,6 @@ "use strict"; - -var _ = require('underscore'); var core = require('web3-core'); var Method = require('web3-core-method'); var utils = require('web3-utils'); @@ -78,11 +76,11 @@ var Contract = function Contract(jsonInterface, address, options) { this.options = {}; var lastArg = args[args.length - 1]; - if(_.isObject(lastArg) && !_.isArray(lastArg)) { + if(typeof lastArg == 'object' && !!lastArg && !Array.isArray(lastArg)) { options = lastArg; - this.options = _.extend(this.options, this._getOrSetDefaultOptions(options)); - if(_.isObject(address)) { + this.options = { ...this.options, ...this._getOrSetDefaultOptions(options)}; + if(typeof address == 'object' && !!address) { address = null; } } @@ -327,7 +325,7 @@ Contract.setProvider = function(provider, accounts) { * @return {Function} the callback */ Contract.prototype._getCallback = function getCallback(args) { - if (args && _.isFunction(args[args.length - 1])) { + if (args && typeof args[args.length - 1] === 'function' && !!args[args.length- 1 ]) { return args.pop(); // modify the args array! } }; @@ -391,7 +389,7 @@ Contract.prototype._encodeEventABI = function (event, options) { }); // use given topics - if(_.isArray(options.topics)) { + if(Array.isArray(options.topics)) { result.topics = options.topics; // create topics based on filter @@ -417,7 +415,7 @@ Contract.prototype._encodeEventABI = function (event, options) { // TODO: https://github.com/ethereum/web3.js/issues/344 // TODO: deal properly with components - if (_.isArray(value)) { + if (Array.isArray(value)) { return value.map(function (v) { return abi.encodeParameter(i.type, v); }); @@ -517,7 +515,7 @@ Contract.prototype._encodeMethodABI = function _encodeMethodABI() { return ((methodSignature === 'constructor' && json.type === methodSignature) || ((json.signature === methodSignature || json.signature === methodSignature.replace('0x','') || json.name === methodSignature) && json.type === 'function')); }).map(function (json) { - var inputLength = (_.isArray(json.inputs)) ? json.inputs.length : 0; + var inputLength = (Array.isArray(json.inputs)) ? json.inputs.length : 0; if (inputLength !== args.length) { throw new Error('The number of arguments is not matching the methods required number. You need to pass '+ inputLength +' arguments.'); @@ -526,7 +524,7 @@ Contract.prototype._encodeMethodABI = function _encodeMethodABI() { if (json.type === 'function') { signature = json.signature; } - return _.isArray(json.inputs) ? json.inputs : []; + return Array.isArray(json.inputs) ? json.inputs : []; }).map(function (inputs) { return abi.encodeParameters(inputs, args).replace('0x',''); })[0] || ''; @@ -606,7 +604,7 @@ Contract.prototype.deploy = function(options, callback){ throw errors.ContractMissingDeployDataError(); } - var constructor = _.find(this.options.jsonInterface, function (method) { + var constructor = this.options.jsonInterface.find((method) => { return (method.type === 'constructor'); }) || {}; constructor.signature = 'constructor'; @@ -636,9 +634,9 @@ Contract.prototype._generateEventOptions = function() { var callback = this._getCallback(args); // get the options - var options = (_.isObject(args[args.length - 1])) ? args.pop() : {}; + var options = (typeof args[args.length - 1]) === 'object' && !!args[args.length - 1] ? args.pop() : {}; - var eventName = (_.isString(args[0])) ? args[0] : 'allevents'; + var eventName = (typeof args[0] === 'string') ? args[0] : 'allevents'; var event = (eventName.toLowerCase() === 'allevents') ? { name: 'ALLEVENTS', jsonInterface: this.options.jsonInterface @@ -698,7 +696,7 @@ Contract.prototype.once = function(event, options, callback) { // don't return as once shouldn't provide "on" this._on(event, options, function (err, res, sub) { sub.unsubscribe(); - if(_.isFunction(callback)){ + if(typeof callback === 'function'){ callback(err, res, sub); } }); @@ -745,7 +743,7 @@ Contract.prototype._on = function(){ this.emit('data', output); } - if (_.isFunction(this.callback)) { + if (typeof this.callback === 'function') { this.callback(null, output, this); } } @@ -845,11 +843,11 @@ Contract.prototype._processExecuteArguments = function _processExecuteArguments( processedArgs.callback = this._parent._getCallback(args); // get block number to use for call - if(processedArgs.type === 'call' && args[args.length - 1] !== true && (_.isString(args[args.length - 1]) || isFinite(args[args.length - 1]))) + if(processedArgs.type === 'call' && args[args.length - 1] !== true && (typeof args[args.length - 1] === 'string' || isFinite(args[args.length - 1]))) processedArgs.defaultBlock = args.pop(); // get the options - processedArgs.options = (_.isObject(args[args.length - 1])) ? args.pop() : {}; + processedArgs.options = (typeof args[args.length - 1]) === 'object' && !!args[args.length - 1] ? args.pop() : {}; // get the generateRequest argument for batch requests processedArgs.generateRequest = (args[args.length - 1] === true)? args.pop() : false; @@ -951,7 +949,7 @@ Contract.prototype._executeMethod = function _executeMethod(){ return utils._fireError(errors.ContractNoFromAddressDefinedError(), defer.eventEmitter, defer.reject, args.callback); } - if (_.isBoolean(this._method.payable) && !this._method.payable && args.options.value && args.options.value > 0) { + if (typeof this._method.payable === 'boolean' && !this._method.payable && args.options.value && args.options.value > 0) { return utils._fireError(new Error('Can not send value to non-payable contract method or constructor'), defer.eventEmitter, defer.reject, args.callback); } @@ -959,10 +957,10 @@ Contract.prototype._executeMethod = function _executeMethod(){ // make sure receipt logs are decoded var extraFormatters = { receiptFormatter: function (receipt) { - if (_.isArray(receipt.logs)) { + if (Array.isArray(receipt.logs)) { // decode logs - var events = _.map(receipt.logs, function(log) { + var events = receipt.logs.map((log) => { return _this._parent._decodeEventABI.call({ name: 'ALLEVENTS', jsonInterface: _this._parent.options.jsonInterface diff --git a/packages/web3-eth-ens/src/ENS.js b/packages/web3-eth-ens/src/ENS.js index 604df14329d..7223445f92d 100644 --- a/packages/web3-eth-ens/src/ENS.js +++ b/packages/web3-eth-ens/src/ENS.js @@ -20,7 +20,6 @@ "use strict"; -var _ = require('underscore'); var config = require('./config'); var formatters = require('web3-core-helpers').formatters; var utils = require('web3-utils'); @@ -92,7 +91,7 @@ ENS.prototype.supportsInterface = function (name, interfaceId, callback) { return resolver.methods.supportsInterface(interfaceId).call(callback); }).catch(function(error) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { callback(error, null); return; @@ -452,7 +451,7 @@ ENS.prototype.setContenthash = function (name, hash, txConfig, callback) { } catch(err){ var error = new Error('Could not encode ' + hash + '. See docs for supported hash protocols.'); - if (_.isFunction(callback)) { + if (typeof callback === 'function') { callback(error, null); return; diff --git a/packages/web3-eth/src/index.js b/packages/web3-eth/src/index.js index 0bd9f42fe81..33c9a93e20a 100644 --- a/packages/web3-eth/src/index.js +++ b/packages/web3-eth/src/index.js @@ -22,7 +22,6 @@ "use strict"; -var _ = require('underscore'); var core = require('web3-core'); var helpers = require('web3-core-helpers'); var Subscriptions = require('web3-core-subscriptions').subscriptions; @@ -42,23 +41,23 @@ var formatter = helpers.formatters; var blockCall = function (args) { - return (_.isString(args[0]) && args[0].indexOf('0x') === 0) ? "eth_getBlockByHash" : "eth_getBlockByNumber"; + return (typeof args[0] === 'string' && args[0].indexOf('0x') === 0) ? "eth_getBlockByHash" : "eth_getBlockByNumber"; }; var transactionFromBlockCall = function (args) { - return (_.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionByBlockHashAndIndex' : 'eth_getTransactionByBlockNumberAndIndex'; + return (typeof args[0] === 'string' && args[0].indexOf('0x') === 0) ? 'eth_getTransactionByBlockHashAndIndex' : 'eth_getTransactionByBlockNumberAndIndex'; }; var uncleCall = function (args) { - return (_.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleByBlockHashAndIndex' : 'eth_getUncleByBlockNumberAndIndex'; + return (typeof args[0] === 'string' && args[0].indexOf('0x') === 0) ? 'eth_getUncleByBlockHashAndIndex' : 'eth_getUncleByBlockNumberAndIndex'; }; var getBlockTransactionCountCall = function (args) { - return (_.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getBlockTransactionCountByHash' : 'eth_getBlockTransactionCountByNumber'; + return (typeof args[0] === 'string' && args[0].indexOf('0x') === 0) ? 'eth_getBlockTransactionCountByHash' : 'eth_getBlockTransactionCountByNumber'; }; var uncleCountCall = function (args) { - return (_.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleCountByBlockHash' : 'eth_getUncleCountByBlockNumber'; + return (typeof args[0] === 'string' && args[0].indexOf('0x') === 0) ? 'eth_getUncleCountByBlockHash' : 'eth_getUncleCountByBlockNumber'; }; @@ -588,7 +587,7 @@ var Eth = function Eth() { this.emit('data', output); } - if (_.isFunction(this.callback)) { + if (typeof this.callback === 'function') { this.callback(null, output, this); } } @@ -604,14 +603,14 @@ var Eth = function Eth() { this._isSyncing = true; this.emit('changed', _this._isSyncing); - if (_.isFunction(this.callback)) { + if (typeof this.callback === 'function') { this.callback(null, _this._isSyncing, this); } setTimeout(function () { _this.emit('data', output); - if (_.isFunction(_this.callback)) { + if (typeof _this.callback === 'function') { _this.callback(null, output, _this); } }, 0); @@ -619,7 +618,7 @@ var Eth = function Eth() { // fire sync status } else { this.emit('data', output); - if (_.isFunction(_this.callback)) { + if ( typeof _this.callback === 'function') { this.callback(null, output, this); } @@ -630,7 +629,7 @@ var Eth = function Eth() { _this._isSyncing = false; _this.emit('changed', _this._isSyncing); - if (_.isFunction(_this.callback)) { + if ( typeof _this.callback === 'function') { _this.callback(null, _this._isSyncing, _this); } } diff --git a/packages/web3-providers-ipc/src/index.js b/packages/web3-providers-ipc/src/index.js index e0fcdeefb70..8e3b9c76393 100644 --- a/packages/web3-providers-ipc/src/index.js +++ b/packages/web3-providers-ipc/src/index.js @@ -22,7 +22,6 @@ "use strict"; -var _ = require('underscore'); var errors = require('web3-core-helpers').errors; var oboe = require('oboe'); @@ -45,7 +44,7 @@ var IpcProvider = function IpcProvider(path, net) { var id = null; // get the id which matches the returned id - if(_.isArray(result)) { + if(Array.isArray(result)) { result.forEach(function(load){ if(_this.responseCallbacks[load.id]) id = load.id; @@ -57,7 +56,7 @@ var IpcProvider = function IpcProvider(path, net) { // notification if(!id && result.method.indexOf('_subscription') !== -1) { _this.notificationCallbacks.forEach(function(callback){ - if(_.isFunction(callback)) + if(typeof callback === 'function') callback(result); }); diff --git a/packages/web3-utils/src/index.js b/packages/web3-utils/src/index.js index fb26c6e1187..75ffb2f5999 100644 --- a/packages/web3-utils/src/index.js +++ b/packages/web3-utils/src/index.js @@ -21,8 +21,6 @@ * @date 2017 */ - -var _ = require('underscore'); var ethjsUnit = require('ethjs-unit'); var utils = require('./utils.js'); var soliditySha3 = require('./soliditySha3.js'); @@ -45,28 +43,28 @@ var _fireError = function (error, emitter, reject, callback, optionalData) { /*jshint maxcomplexity: 10 */ // add data if given - if(_.isObject(error) && !(error instanceof Error) && error.data) { - if(_.isObject(error.data) || _.isArray(error.data)) { + if(typeof error === 'object' && !!error && !(error instanceof Error) && error.data) { + if(typeof error.data === 'object' && !!error.data || Array.isArray(error.data)) { error.data = JSON.stringify(error.data, null, 2); } error = error.message +"\n"+ error.data; } - if(_.isString(error)) { + if(typeof error === 'string') { error = new Error(error); } - if (_.isFunction(callback)) { + if (typeof callback === 'function') { callback(error, optionalData); } - if (_.isFunction(reject)) { + if (typeof reject === 'function') { // suppress uncatched error if an error listener is present // OR suppress uncatched error if an callback listener is present if ( emitter && - (_.isFunction(emitter.listeners) && - emitter.listeners('error').length) || _.isFunction(callback) + (typeof emitter.listeners === 'function' && + emitter.listeners('error').length) || typeof callback === 'function' ) { emitter.catch(function(){}); } @@ -76,7 +74,7 @@ var _fireError = function (error, emitter, reject, callback, optionalData) { }, 1); } - if(emitter && _.isFunction(emitter.emit)) { + if(emitter && typeof emitter.emit === 'function') { // emit later, to be able to return emitter setTimeout(function () { emitter.emit('error', error, optionalData); @@ -95,7 +93,7 @@ var _fireError = function (error, emitter, reject, callback, optionalData) { * @return {String} full function/event name */ var _jsonInterfaceMethodToString = function (json) { - if (_.isObject(json) && json.name && json.name.indexOf('(') !== -1) { + if (typeof json === 'object' && !!json && json.name && json.name.indexOf('(') !== -1) { return json.name; } @@ -126,7 +124,7 @@ var _flattenTypes = function(includeTuple, puts) if (arrayBracket >= 0) { suffix = param.type.substring(arrayBracket); } var result = _flattenTypes(includeTuple, param.components); // console.log("result should have things: " + result) - if(_.isArray(result) && includeTuple) { + if(Array.isArray(result) && includeTuple) { // console.log("include tuple word, and its an array. joining...: " + result.types) types.push('tuple(' + result.join(',') + ')' + suffix); } @@ -244,7 +242,7 @@ var getUnitValue = function (unit) { var fromWei = function(number, unit) { unit = getUnitValue(unit); - if(!utils.isBN(number) && !_.isString(number)) { + if(!utils.isBN(number) && !(typeof number === 'string')) { throw new Error('Please pass numbers as strings or BN objects to avoid precision errors.'); } @@ -276,7 +274,7 @@ var fromWei = function(number, unit) { var toWei = function(number, unit) { unit = getUnitValue(unit); - if(!utils.isBN(number) && !_.isString(number)) { + if(!utils.isBN(number) && !(typeof number === 'string')) { throw new Error('Please pass numbers as strings or BN objects to avoid precision errors.'); } diff --git a/packages/web3-utils/src/soliditySha3.js b/packages/web3-utils/src/soliditySha3.js index 055f3e30f9e..657b20ff441 100644 --- a/packages/web3-utils/src/soliditySha3.js +++ b/packages/web3-utils/src/soliditySha3.js @@ -20,7 +20,6 @@ * @date 2017 */ -var _ = require('underscore'); var BN = require('bn.js'); var utils = require('./utils.js'); @@ -172,7 +171,7 @@ var _solidityPack = function (type, value, arraySize) { var _processSolidityEncodePackedArgs = function (arg) { /*jshint maxcomplexity:false */ - if(_.isArray(arg)) { + if(Array.isArray(arg)) { throw new Error('Autodetection of array types is not supported.'); } @@ -180,7 +179,7 @@ var _processSolidityEncodePackedArgs = function (arg) { var hexArg, arraySize; // if type is given - if (_.isObject(arg) && (arg.hasOwnProperty('v') || arg.hasOwnProperty('t') || arg.hasOwnProperty('value') || arg.hasOwnProperty('type'))) { + if (typeof arg === 'object' && !!arg && (arg.hasOwnProperty('v') || arg.hasOwnProperty('t') || arg.hasOwnProperty('value') || arg.hasOwnProperty('type'))) { type = arg.hasOwnProperty('t') ? arg.t : arg.type; value = arg.hasOwnProperty('v') ? arg.v : arg.value; @@ -200,7 +199,7 @@ var _processSolidityEncodePackedArgs = function (arg) { } // get the array size - if(_.isArray(value)) { + if(Array.isArray(value)) { arraySize = _parseTypeNArray(type); if(arraySize && value.length !== arraySize) { throw new Error(type +' is not matching the given array '+ JSON.stringify(value)); @@ -210,7 +209,7 @@ var _processSolidityEncodePackedArgs = function (arg) { } - if (_.isArray(value)) { + if (Array.isArray(value)) { hexArg = value.map(function (val) { return _solidityPack(type, val, arraySize).toString('hex').replace('0x',''); }); @@ -233,7 +232,7 @@ var soliditySha3 = function () { var args = Array.prototype.slice.call(arguments); - var hexArgs = _.map(args, _processSolidityEncodePackedArgs); + var hexArgs = args.map(_processSolidityEncodePackedArgs); // console.log(args, hexArgs); // console.log('0x'+ hexArgs.join('')); @@ -248,7 +247,7 @@ var soliditySha3 = function () { * @return {Object} the sha3 */ var soliditySha3Raw = function () { - return utils.sha3Raw('0x'+ _.map(Array.prototype.slice.call(arguments), _processSolidityEncodePackedArgs).join('')); + return utils.sha3Raw('0x'+ Array.prototype.slice.call(arguments).map(_processSolidityEncodePackedArgs).join('')); }; /** @@ -262,7 +261,7 @@ var encodePacked = function () { var args = Array.prototype.slice.call(arguments); - var hexArgs = _.map(args, _processSolidityEncodePackedArgs); + var hexArgs = args.map(_processSolidityEncodePackedArgs); return '0x'+ hexArgs.join('').toLowerCase(); }; diff --git a/packages/web3-utils/src/utils.js b/packages/web3-utils/src/utils.js index 63afa1c7dee..3056afd1f40 100644 --- a/packages/web3-utils/src/utils.js +++ b/packages/web3-utils/src/utils.js @@ -20,7 +20,6 @@ * @date 2017 */ -var _ = require('underscore'); var BN = require('bn.js'); var numberToBN = require('number-to-bn'); var utf8 = require('utf8'); @@ -232,7 +231,7 @@ var hexToNumber = function (value) { return value; } - if (_.isString(value) && !isHexStrict(value)) { + if (typeof value == 'string' && !isHexStrict(value)) { throw new Error('Given value "'+value+'" is not a valid hex string.'); } @@ -249,7 +248,7 @@ var hexToNumber = function (value) { var hexToNumberString = function (value) { if (!value) return value; - if (_.isString(value) && !isHexStrict(value)) { + if (typeof value == 'string' && !isHexStrict(value)) { throw new Error('Given value "'+value+'" is not a valid hex string.'); } @@ -265,7 +264,7 @@ var hexToNumberString = function (value) { * @return {String} */ var numberToHex = function (value) { - if (_.isNull(value) || _.isUndefined(value)) { + if ((value === null || value === undefined)) { return value; } @@ -339,7 +338,7 @@ var toHex = function (value, returnType) { return returnType ? 'address' : '0x'+ value.toLowerCase().replace(/^0x/i,''); } - if (_.isBoolean(value)) { + if (typeof value === 'boolean' ) { return returnType ? 'bool' : value ? '0x01' : '0x00'; } @@ -347,12 +346,12 @@ var toHex = function (value, returnType) { return '0x' + value.toString('hex'); } - if (_.isObject(value) && !isBigNumber(value) && !isBN(value)) { + if (typeof value === 'object' && !!value && !isBigNumber(value) && !isBN(value)) { return returnType ? 'string' : utf8ToHex(JSON.stringify(value)); } // if its a negative number, pass it through numberToHex - if (_.isString(value)) { + if (typeof value === 'string') { if (value.indexOf('-0x') === 0 || value.indexOf('-0X') === 0) { return returnType ? 'int256' : numberToHex(value); } else if(value.indexOf('0x') === 0 || value.indexOf('0X') === 0) { @@ -374,7 +373,7 @@ var toHex = function (value, returnType) { * @returns {Boolean} */ var isHexStrict = function (hex) { - return ((_.isString(hex) || _.isNumber(hex)) && /^(-)?0x[0-9a-f]*$/i.test(hex)); + return ((typeof hex === 'string' || typeof hex === 'number') && /^(-)?0x[0-9a-f]*$/i.test(hex)); }; /** @@ -385,7 +384,7 @@ var isHexStrict = function (hex) { * @returns {Boolean} */ var isHex = function (hex) { - return ((_.isString(hex) || _.isNumber(hex)) && /^(-0x|0x)?[0-9a-f]*$/i.test(hex)); + return ((typeof hex === 'string' || typeof hex === 'number') && /^(-0x|0x)?[0-9a-f]*$/i.test(hex)); }; /** From 8140c95abd221ad07e7691cdbf6141bbb69d59b2 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 18 May 2021 17:12:59 -0400 Subject: [PATCH 09/19] fixing exports --- packages/web3-utils/src/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/web3-utils/src/index.js b/packages/web3-utils/src/index.js index 75ffb2f5999..c227d764745 100644 --- a/packages/web3-utils/src/index.js +++ b/packages/web3-utils/src/index.js @@ -377,7 +377,6 @@ module.exports = { // extractDisplayName: extractDisplayName, // extractTypeName: extractTypeName, randomHex: randomHex, - _: _, BN: utils.BN, isBN: utils.isBN, isBigNumber: utils.isBigNumber, From 877a3a8a64c9f040478c7deb7750e4c6e1036cbd Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 18 May 2021 17:34:00 -0400 Subject: [PATCH 10/19] fixing failing testcases --- packages/web3-eth-accounts/src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/web3-eth-accounts/src/index.js b/packages/web3-eth-accounts/src/index.js index 1e963428bf4..6fc2737d766 100644 --- a/packages/web3-eth-accounts/src/index.js +++ b/packages/web3-eth-accounts/src/index.js @@ -356,7 +356,7 @@ Accounts.prototype.recover = function recover(message, signature, preFixed) { Accounts.prototype.decrypt = function(v3Keystore, password, nonStrict) { /* jshint maxcomplexity: 10 */ - if (!typeof password === 'string') { + if (!(typeof password === 'string')) { throw new Error('No password given.'); } @@ -469,7 +469,7 @@ function Wallet(accounts) { Wallet.prototype._findSafeIndex = function(pointer) { pointer = pointer || 0; - if (this.hasOwnProperty(pointer)) { + if (this != null && this.hasOwnProperty(pointer)) { return this._findSafeIndex(pointer + 1); } else { return pointer; From 05ee2a3521d43cd6b5430b6971f44c3d3c33cdc6 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 19 May 2021 10:37:29 -0400 Subject: [PATCH 11/19] removing underscore from tests --- test/abi.decodeParameter.js | 10 +++++----- test/eth.accounts.signTransaction.js | 3 +-- test/helpers/test.method.js | 11 +++++------ test/utils.encodePacked.js | 3 +-- test/utils.soliditySha3.js | 3 +-- 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/test/abi.decodeParameter.js b/test/abi.decodeParameter.js index e79fab2c927..19eaff76a85 100644 --- a/test/abi.decodeParameter.js +++ b/test/abi.decodeParameter.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var chai = require('chai'); var assert = chai.assert; var coder = require('../packages/web3-eth-abi'); @@ -349,10 +348,11 @@ describe('lib/solidity/coder', function () { var result = coder.decodeParameters(t.types, t.values); var resultArray = []; - _.each(result, function (res, key) { - if(_.isFinite(key)) - resultArray.push(res); - }); + for (var key in result) { + if(isFinite(key)) + resultArray.push(result[key]); + } + diff --git a/test/eth.accounts.signTransaction.js b/test/eth.accounts.signTransaction.js index f139d79385e..653fc244e4f 100644 --- a/test/eth.accounts.signTransaction.js +++ b/test/eth.accounts.signTransaction.js @@ -2,7 +2,6 @@ var FakeHttpProvider = require('./helpers/FakeIpcProvider'); var Web3 = require('../packages/web3'); var Accounts = require("./../packages/web3-eth-accounts"); var chai = require('chai'); -var _ = require('underscore'); var assert = chai.assert; var common = { @@ -15,7 +14,7 @@ var common = { harfork: 'petersburg', }; -var clone = function (object) { return object ? _.clone(object) : []; }; +var clone = function (object) { return object ? Object.assign({},object) : []; }; var tests = [ { diff --git a/test/helpers/test.method.js b/test/helpers/test.method.js index 3afa2958e5c..25817c679f5 100644 --- a/test/helpers/test.method.js +++ b/test/helpers/test.method.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var chai = require('chai'); var assert = chai.assert; var FakeIpcProvider = require('./FakeIpcProvider'); @@ -30,7 +29,7 @@ var useLocalWallet = function (test, provider, web3) { var runTests = function (obj, method, tests) { var objName; - if(_.isArray(obj)) { + if(Array.isArray(obj)) { objName = obj.join('.'); } else { objName = obj; @@ -98,7 +97,7 @@ var runTests = function (obj, method, tests) { if(test.error) { if (obj) { - if(_.isArray(obj)) { + if(Array.isArray(obj)) { w3 = web3[obj[0]][obj[1]]; } else { w3 = web3[obj]; @@ -126,7 +125,7 @@ var runTests = function (obj, method, tests) { } else { if (obj) { - if(_.isArray(obj)) { + if(Array.isArray(obj)) { w3 = web3[obj[0]][obj[1]]; } else { w3 = web3[obj]; @@ -204,7 +203,7 @@ var runTests = function (obj, method, tests) { if(test.error) { if (obj) { - if(_.isArray(obj)) { + if(Array.isArray(obj)) { w3 = web3[obj[0]][obj[1]]; } else { w3 = web3[obj]; @@ -233,7 +232,7 @@ var runTests = function (obj, method, tests) { // when if (obj) { - if(_.isArray(obj)) { + if(Array.isArray(obj)) { w3 = web3[obj[0]][obj[1]]; } else { w3 = web3[obj]; diff --git a/test/utils.encodePacked.js b/test/utils.encodePacked.js index a56f13d9609..d7bd208c45b 100644 --- a/test/utils.encodePacked.js +++ b/test/utils.encodePacked.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var BN = require('bn.js'); var BigNumber = require('bignumber.js'); var chai = require('chai'); @@ -183,7 +182,7 @@ describe('web3.encodePacked', function () { test.values.forEach(function (value) { it('should hash "'+ JSON.stringify(value) +'" into "'+ test.expected +'"', function() { - if(value.error || _.isArray(value)) { + if(value.error || Array.isArray(value)) { assert.throws(utils.encodePacked.bind(null, value)); } else { assert.deepEqual(utils.encodePacked(value), test.expected); diff --git a/test/utils.soliditySha3.js b/test/utils.soliditySha3.js index c40b1eb1fa0..9150eceeae8 100644 --- a/test/utils.soliditySha3.js +++ b/test/utils.soliditySha3.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var BN = require('bn.js'); var BigNumber = require('bignumber.js'); var chai = require('chai'); @@ -183,7 +182,7 @@ describe('web3.soliditySha3', function () { test.values.forEach(function (value) { it('should hash "'+ JSON.stringify(value) +'" into "'+ test.expected +'"', function() { - if(value.error || _.isArray(value)) { + if(value.error || Array.isArray(value)) { assert.throws(utils.soliditySha3.bind(null, value)); } else { assert.deepEqual(utils.soliditySha3(value), test.expected); From de39e428767c779319e8c31151e91305df10014f Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 20 May 2021 12:41:31 -0400 Subject: [PATCH 12/19] addressing feedback --- package.json | 2 -- packages/web3-bzz/package.json | 3 +-- packages/web3-bzz/src/index.js | 1 - packages/web3-core-helpers/package.json | 1 - packages/web3-core-method/package.json | 1 - packages/web3-core-method/src/index.js | 1 - packages/web3-core-requestmanager/package.json | 1 - packages/web3-core-subscriptions/package.json | 1 - packages/web3-core-subscriptions/src/subscription.js | 2 +- packages/web3-eth-abi/package.json | 1 - packages/web3-eth-accounts/package.json | 1 - packages/web3-eth-contract/package.json | 1 - packages/web3-eth-ens/package.json | 1 - packages/web3-eth/package.json | 1 - packages/web3-providers-ipc/package.json | 1 - packages/web3-providers-ws/package.json | 1 - packages/web3-utils/package.json | 1 - test/abi.decodeParameter.js | 7 +++---- 18 files changed, 5 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index d24eb84b277..aa2c4cf6362 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,6 @@ "@types/bignumber.js": "^4.0.2", "@types/bn.js": "^4.11.6", "@types/node": "^12.12.68", - "@types/underscore": "^1.10.24", "babel-loader": "^8.1.0", "bignumber.js": "^9.0.1", "bn.js": "^4.11.9", @@ -132,7 +131,6 @@ "sandboxed-module": "^2.0.4", "ts-node": "^9.0.0", "typescript": "^3.9.7", - "underscore": "1.12.1", "wait-port": "^0.2.9", "webpack": "^4.44.2", "webpack-cli": "^3.3.12" diff --git a/packages/web3-bzz/package.json b/packages/web3-bzz/package.json index 7c9b6e35018..a607a75bbbc 100644 --- a/packages/web3-bzz/package.json +++ b/packages/web3-bzz/package.json @@ -17,8 +17,7 @@ "dependencies": { "@types/node": "^12.12.6", "got": "9.6.0", - "swarm-js": "^0.1.40", - "underscore": "1.12.1" + "swarm-js": "^0.1.40" }, "devDependencies": { "dtslint": "^3.4.1", diff --git a/packages/web3-bzz/src/index.js b/packages/web3-bzz/src/index.js index 1c32b9c8820..34f006518a4 100644 --- a/packages/web3-bzz/src/index.js +++ b/packages/web3-bzz/src/index.js @@ -22,7 +22,6 @@ "use strict"; - var swarm = require("swarm-js"); diff --git a/packages/web3-core-helpers/package.json b/packages/web3-core-helpers/package.json index 19ab67c96ca..1309ef088d2 100644 --- a/packages/web3-core-helpers/package.json +++ b/packages/web3-core-helpers/package.json @@ -14,7 +14,6 @@ }, "main": "lib/index.js", "dependencies": { - "underscore": "1.12.1", "web3-eth-iban": "1.3.6", "web3-utils": "1.3.6" }, diff --git a/packages/web3-core-method/package.json b/packages/web3-core-method/package.json index 69c07f1183d..c416c09f1db 100644 --- a/packages/web3-core-method/package.json +++ b/packages/web3-core-method/package.json @@ -15,7 +15,6 @@ "main": "lib/index.js", "dependencies": { "@ethersproject/transactions": "^5.0.0-beta.135", - "underscore": "1.12.1", "web3-core-helpers": "1.3.6", "web3-core-promievent": "1.3.6", "web3-core-subscriptions": "1.3.6", diff --git a/packages/web3-core-method/src/index.js b/packages/web3-core-method/src/index.js index bf0ccbeaade..d7ccd701ec6 100644 --- a/packages/web3-core-method/src/index.js +++ b/packages/web3-core-method/src/index.js @@ -179,7 +179,6 @@ Method.prototype.formatOutput = function (result) { Method.prototype.toPayload = function (args) { var call = this.getCall(args); var callback = this.extractCallback(args); - //check if last args is a function, if so pop it out. var params = this.formatInput(args); this.validateArgs(params); diff --git a/packages/web3-core-requestmanager/package.json b/packages/web3-core-requestmanager/package.json index 279af5ba871..ff101fa2a29 100644 --- a/packages/web3-core-requestmanager/package.json +++ b/packages/web3-core-requestmanager/package.json @@ -12,7 +12,6 @@ "compile": "tsc -b tsconfig.json" }, "dependencies": { - "underscore": "1.12.1", "util": "^0.12.0", "web3-core-helpers": "1.3.6", "web3-providers-http": "1.3.6", diff --git a/packages/web3-core-subscriptions/package.json b/packages/web3-core-subscriptions/package.json index 5387646c69a..2864ee2803a 100644 --- a/packages/web3-core-subscriptions/package.json +++ b/packages/web3-core-subscriptions/package.json @@ -15,7 +15,6 @@ "main": "lib/index.js", "dependencies": { "eventemitter3": "4.0.4", - "underscore": "1.12.1", "web3-core-helpers": "1.3.6" }, "devDependencies": { diff --git a/packages/web3-core-subscriptions/src/subscription.js b/packages/web3-core-subscriptions/src/subscription.js index aa83059d003..4ba0d913bb5 100644 --- a/packages/web3-core-subscriptions/src/subscription.js +++ b/packages/web3-core-subscriptions/src/subscription.js @@ -26,7 +26,7 @@ var errors = require('web3-core-helpers').errors; var EventEmitter = require('eventemitter3'); var formatters = require('web3-core-helpers').formatters; -function identity(value) { +function identity(value) { //used to return the exact same replica of the value given to it as the argument return value; } diff --git a/packages/web3-eth-abi/package.json b/packages/web3-eth-abi/package.json index 498c44590eb..2cfa3a3f214 100644 --- a/packages/web3-eth-abi/package.json +++ b/packages/web3-eth-abi/package.json @@ -15,7 +15,6 @@ "main": "lib/index.js", "dependencies": { "@ethersproject/abi": "5.0.7", - "underscore": "1.12.1", "web3-utils": "1.3.6" }, "devDependencies": { diff --git a/packages/web3-eth-accounts/package.json b/packages/web3-eth-accounts/package.json index f0ad1d2d545..43c2e3b2c52 100644 --- a/packages/web3-eth-accounts/package.json +++ b/packages/web3-eth-accounts/package.json @@ -19,7 +19,6 @@ "ethereumjs-common": "^1.3.2", "ethereumjs-tx": "^2.1.1", "scrypt-js": "^3.0.1", - "underscore": "1.12.1", "uuid": "3.3.2", "web3-core": "1.3.6", "web3-core-helpers": "1.3.6", diff --git a/packages/web3-eth-contract/package.json b/packages/web3-eth-contract/package.json index 3f45b26dd97..09e08ab0542 100644 --- a/packages/web3-eth-contract/package.json +++ b/packages/web3-eth-contract/package.json @@ -15,7 +15,6 @@ "main": "lib/index.js", "dependencies": { "@types/bn.js": "^4.11.5", - "underscore": "1.12.1", "web3-core": "1.3.6", "web3-core-helpers": "1.3.6", "web3-core-method": "1.3.6", diff --git a/packages/web3-eth-ens/package.json b/packages/web3-eth-ens/package.json index 78620900398..eda285f7a74 100644 --- a/packages/web3-eth-ens/package.json +++ b/packages/web3-eth-ens/package.json @@ -16,7 +16,6 @@ "dependencies": { "content-hash": "^2.5.2", "eth-ens-namehash": "2.0.8", - "underscore": "1.12.1", "web3-core": "1.3.6", "web3-core-helpers": "1.3.6", "web3-core-promievent": "1.3.6", diff --git a/packages/web3-eth/package.json b/packages/web3-eth/package.json index 960c702980c..61957ae9600 100644 --- a/packages/web3-eth/package.json +++ b/packages/web3-eth/package.json @@ -14,7 +14,6 @@ }, "main": "lib/index.js", "dependencies": { - "underscore": "1.12.1", "web3-core": "1.3.6", "web3-core-helpers": "1.3.6", "web3-core-method": "1.3.6", diff --git a/packages/web3-providers-ipc/package.json b/packages/web3-providers-ipc/package.json index c03b2a8c7a4..2d1f146dd00 100644 --- a/packages/web3-providers-ipc/package.json +++ b/packages/web3-providers-ipc/package.json @@ -15,7 +15,6 @@ "main": "lib/index.js", "dependencies": { "oboe": "2.1.5", - "underscore": "1.12.1", "web3-core-helpers": "1.3.6" }, "devDependencies": { diff --git a/packages/web3-providers-ws/package.json b/packages/web3-providers-ws/package.json index 9d8934716da..6d79e3f84b3 100644 --- a/packages/web3-providers-ws/package.json +++ b/packages/web3-providers-ws/package.json @@ -15,7 +15,6 @@ "main": "lib/index.js", "dependencies": { "eventemitter3": "4.0.4", - "underscore": "1.12.1", "web3-core-helpers": "1.3.6", "websocket": "^1.0.32" }, diff --git a/packages/web3-utils/package.json b/packages/web3-utils/package.json index 709612f9c3f..509f37dc1b8 100644 --- a/packages/web3-utils/package.json +++ b/packages/web3-utils/package.json @@ -20,7 +20,6 @@ "ethjs-unit": "0.1.6", "number-to-bn": "1.7.0", "randombytes": "^2.1.0", - "underscore": "1.12.1", "utf8": "3.0.0" }, "devDependencies": { diff --git a/test/abi.decodeParameter.js b/test/abi.decodeParameter.js index 19eaff76a85..6c09e2f2ed8 100644 --- a/test/abi.decodeParameter.js +++ b/test/abi.decodeParameter.js @@ -348,10 +348,9 @@ describe('lib/solidity/coder', function () { var result = coder.decodeParameters(t.types, t.values); var resultArray = []; - for (var key in result) { - if(isFinite(key)) - resultArray.push(result[key]); - } + Object.keys(result).map(key => { + if(isFinite(key)) resultArray.push(result[key]) + }); From 24268f402403c4295060522fd6ae38ac2c5de2be Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 3 Jul 2021 22:07:20 -0400 Subject: [PATCH 13/19] removing unwanted code from transaction --- packages/web3-eth-accounts/src/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/web3-eth-accounts/src/index.js b/packages/web3-eth-accounts/src/index.js index 351ef107e86..6a0ab8b58d8 100644 --- a/packages/web3-eth-accounts/src/index.js +++ b/packages/web3-eth-accounts/src/index.js @@ -154,7 +154,6 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca try { var transaction = helpers.formatters.inputCallFormatter(Object.assign({},tx)); - transaction.to = transaction.data || '0x'; transaction.data = transaction.data || '0x'; transaction.value = transaction.value || '0x'; transaction.gasLimit = transaction.gasLimit || transaction.gas; From 3d1ad54d5e6ac2fb41d1956e50b48e765f129da5 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 7 Jul 2021 12:35:09 -0400 Subject: [PATCH 14/19] removing underscore from remaining packages --- .../web3-eth-ens/src/contracts/Registry.js | 49 +++++++++---------- .../src/lib/ResolverMethodHandler.js | 13 +++-- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/packages/web3-eth-ens/src/contracts/Registry.js b/packages/web3-eth-ens/src/contracts/Registry.js index d0119e09d75..eee8ac4e468 100644 --- a/packages/web3-eth-ens/src/contracts/Registry.js +++ b/packages/web3-eth-ens/src/contracts/Registry.js @@ -20,7 +20,6 @@ "use strict"; -var _ = require('underscore'); var Contract = require('web3-eth-contract'); var namehash = require('eth-ens-namehash'); var PromiEvent = require('web3-core-promievent'); @@ -84,7 +83,7 @@ Registry.prototype.getOwner = function (name, callback) { this.contract.then(function (contract) { return contract.methods.owner(namehash.hash(name)).call(); }).then(function (receipt) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { // It's required to pass the receipt to the first argument to be backward compatible and to have the required consistency callback(receipt, receipt); @@ -93,7 +92,7 @@ Registry.prototype.getOwner = function (name, callback) { promiEvent.resolve(receipt); }).catch(function (error) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { callback(error, null); return; @@ -124,7 +123,7 @@ Registry.prototype.setOwner = function (name, address, txConfig, callback) { this.contract.then(function (contract) { return contract.methods.setOwner(namehash.hash(name), formatters.inputAddressFormatter(address)).send(txConfig); }).then(function (receipt) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { // It's required to pass the receipt to the first argument to be backward compatible and to have the required consistency callback(receipt, receipt); @@ -133,7 +132,7 @@ Registry.prototype.setOwner = function (name, address, txConfig, callback) { promiEvent.resolve(receipt); }).catch(function (error) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { callback(error, null); return; @@ -162,7 +161,7 @@ Registry.prototype.getTTL = function (name, callback) { this.contract.then(function (contract) { return contract.methods.ttl(namehash.hash(name)).call(); }).then(function (receipt) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { // It's required to pass the receipt to the first argument to be backward compatible and to have the required consistency callback(receipt, receipt); @@ -171,7 +170,7 @@ Registry.prototype.getTTL = function (name, callback) { promiEvent.resolve(receipt); }).catch(function (error) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { callback(error, null); return; @@ -202,7 +201,7 @@ Registry.prototype.setTTL = function (name, ttl, txConfig, callback) { this.contract.then(function (contract) { return contract.methods.setTTL(namehash.hash(name), ttl).send(txConfig); }).then(function (receipt) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { // It's required to pass the receipt to the first argument to be backward compatible and to have the required consistency callback(receipt, receipt); @@ -211,7 +210,7 @@ Registry.prototype.setTTL = function (name, ttl, txConfig, callback) { promiEvent.resolve(receipt); }).catch(function (error) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { callback(error, null); return; @@ -251,7 +250,7 @@ Registry.prototype.setSubnodeOwner = function (name, label, address, txConfig, c formatters.inputAddressFormatter(address) ).send(txConfig); }).then(function (receipt) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { // It's required to pass the receipt to the first argument to be backward compatible and to have the required consistency callback(receipt, receipt); @@ -260,7 +259,7 @@ Registry.prototype.setSubnodeOwner = function (name, label, address, txConfig, c promiEvent.resolve(receipt); }).catch(function (error) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { callback(error, null); return; @@ -298,7 +297,7 @@ Registry.prototype.setRecord = function (name, owner, resolver, ttl, txConfig, c ttl ).send(txConfig); }).then(function (receipt) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { // It's required to pass the receipt to the first argument to be backward compatible and to have the required consistency callback(receipt, receipt); @@ -307,7 +306,7 @@ Registry.prototype.setRecord = function (name, owner, resolver, ttl, txConfig, c promiEvent.resolve(receipt); }).catch(function (error) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { callback(error, null); return; @@ -351,7 +350,7 @@ Registry.prototype.setSubnodeRecord = function (name, label, owner, resolver, tt ttl ).send(txConfig); }).then(function (receipt) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { // It's required to pass the receipt to the first argument to be backward compatible and to have the required consistency callback(receipt, receipt); @@ -360,7 +359,7 @@ Registry.prototype.setSubnodeRecord = function (name, label, owner, resolver, tt promiEvent.resolve(receipt); }).catch(function (error) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { callback(error, null); return; @@ -391,7 +390,7 @@ Registry.prototype.setApprovalForAll = function (operator, approved, txConfig, c this.contract.then(function (contract) { return contract.methods.setApprovalForAll(formatters.inputAddressFormatter(operator), approved).send(txConfig); }).then(function (receipt) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { // It's required to pass the receipt to the first argument to be backward compatible and to have the required consistency callback(receipt, receipt); @@ -400,7 +399,7 @@ Registry.prototype.setApprovalForAll = function (operator, approved, txConfig, c promiEvent.resolve(receipt); }).catch(function (error) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { callback(error, null); return; @@ -433,7 +432,7 @@ Registry.prototype.isApprovedForAll = function (owner, operator, callback) { formatters.inputAddressFormatter(operator) ).call(); }).then(function (receipt) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { // It's required to pass the receipt to the first argument to be backward compatible and to have the required consistency callback(receipt, receipt); @@ -442,7 +441,7 @@ Registry.prototype.isApprovedForAll = function (owner, operator, callback) { promiEvent.resolve(receipt); }).catch(function (error) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { callback(error, null); return; @@ -471,7 +470,7 @@ Registry.prototype.recordExists = function (name, callback) { this.contract.then(function (contract) { return contract.methods.recordExists(namehash.hash(name)).call(); }).then(function (receipt) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { // It's required to pass the receipt to the first argument to be backward compatible and to have the required consistency callback(receipt, receipt); @@ -480,7 +479,7 @@ Registry.prototype.recordExists = function (name, callback) { promiEvent.resolve(receipt); }).catch(function (error) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { callback(error, null); return; @@ -531,7 +530,7 @@ Registry.prototype.getResolver = function (name, callback) { var contract = new Contract(RESOLVER_ABI, address); contract.setProvider(self.ens.eth.currentProvider); - if (_.isFunction(callback)) { + if (typeof callback === 'function') { // It's required to pass the contract to the first argument to be backward compatible and to have the required consistency callback(contract, contract); @@ -540,7 +539,7 @@ Registry.prototype.getResolver = function (name, callback) { return contract; }).catch(function (error) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { callback(error, null); return; @@ -569,7 +568,7 @@ Registry.prototype.setResolver = function (name, address, txConfig, callback) { this.contract.then(function (contract) { return contract.methods.setResolver(namehash.hash(name), formatters.inputAddressFormatter(address)).send(txConfig); }).then(function (receipt) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { // It's required to pass the receipt to the first argument to be backward compatible and to have the required consistency callback(receipt, receipt); @@ -578,7 +577,7 @@ Registry.prototype.setResolver = function (name, address, txConfig, callback) { promiEvent.resolve(receipt); }).catch(function (error) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { callback(error, null); return; diff --git a/packages/web3-eth-ens/src/lib/ResolverMethodHandler.js b/packages/web3-eth-ens/src/lib/ResolverMethodHandler.js index a07d8e89fe4..04e6b703a50 100644 --- a/packages/web3-eth-ens/src/lib/ResolverMethodHandler.js +++ b/packages/web3-eth-ens/src/lib/ResolverMethodHandler.js @@ -23,7 +23,6 @@ var PromiEvent = require('web3-core-promievent'); var namehash = require('eth-ens-namehash'); var errors = require('web3-core-helpers').errors; -var _ = require('underscore'); var interfaceIds = require('../config').interfaceIds; /** @@ -78,7 +77,7 @@ ResolverMethodHandler.prototype.call = function (callback) { await self.parent.checkInterfaceSupport(resolver, self.methodName); self.parent.handleCall(promiEvent, resolver.methods[self.methodName], preparedArguments, outputFormatter, callback); }).catch(function(error) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { callback(error, null); return; @@ -107,7 +106,7 @@ ResolverMethodHandler.prototype.send = function (sendOptions, callback) { await self.parent.checkInterfaceSupport(resolver, self.methodName); self.parent.handleSend(promiEvent, resolver.methods[self.methodName], preparedArguments, sendOptions, callback); }).catch(function(error) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { callback(error, null); return; @@ -135,7 +134,7 @@ ResolverMethodHandler.prototype.handleCall = function (promiEvent, method, prepa result = outputFormatter(result); } - if (_.isFunction(callback)) { + if (typeof callback === 'function') { // It's required to pass the receipt to the second argument to be backwards compatible and to have the required consistency callback(result, result); @@ -144,7 +143,7 @@ ResolverMethodHandler.prototype.handleCall = function (promiEvent, method, prepa promiEvent.resolve(result); }).catch(function (error) { - if (_.isFunction(callback)) { + if (typeof callback === 'function') { callback(error, null); return; @@ -184,7 +183,7 @@ ResolverMethodHandler.prototype.handleSend = function (promiEvent, method, prepa promiEvent.eventEmitter.emit('receipt', receipt); promiEvent.resolve(receipt); - if (_.isFunction(callback)) { + if (typeof callback === 'function') { // It's required to pass the receipt to the second argument to be backwards compatible and to have the required consistency callback(receipt, receipt); } @@ -192,7 +191,7 @@ ResolverMethodHandler.prototype.handleSend = function (promiEvent, method, prepa .on('error', function (error) { promiEvent.eventEmitter.emit('error', error); - if (_.isFunction(callback)) { + if (typeof callback === 'function') { callback(error, null); return; From 75ec5688bcf369ba8055c0e34fa60380eb84aa73 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 7 Jul 2021 12:58:54 -0400 Subject: [PATCH 15/19] updating change log --- CHANGELOG.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ea1d4c9f95..af5e311c338 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -394,6 +394,10 @@ Released with 1.0.0-beta.37 code base. - Changed Geth Docker verision from `stable` to `1.10.3` in `e2e.geth.instamine.sh` and `scripts/e2e.geth.automine.sh` (#4154) -## [Unreleased] - ## [1.4.1] + +### Removes + +- Removing the underscore package + +## [Unreleased] \ No newline at end of file From 91735d6035d1dd92a935d0ee5da665d92aa431e3 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 7 Jul 2021 16:23:02 -0400 Subject: [PATCH 16/19] addressing feedback --- packages/web3-core-method/src/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/web3-core-method/src/index.js b/packages/web3-core-method/src/index.js index d7ccd701ec6..3a33232904a 100644 --- a/packages/web3-core-method/src/index.js +++ b/packages/web3-core-method/src/index.js @@ -711,8 +711,7 @@ Method.prototype.buildCall = function () { // If wallet was found, sign tx, and send using sendRawTransaction if (wallet && wallet.privateKey) { - var txOptions = JSON.parse(JSON.stringify(tx)); - delete txOptions['from']; + delete txOptions.from; if (method.defaultChain && !txOptions.chain) { txOptions.chain = method.defaultChain; From 7bbe5b0ecae9e5c0f160e4867ce860e1197c3be4 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 8 Jul 2021 10:43:54 -0400 Subject: [PATCH 17/19] adding strict equality --- packages/web3-core-method/src/index.js | 16 ++++++++-------- packages/web3-eth-accounts/src/index.js | 6 +++--- packages/web3-eth-contract/src/index.js | 4 ++-- packages/web3-utils/src/utils.js | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/web3-core-method/src/index.js b/packages/web3-core-method/src/index.js index 3a33232904a..e0d3446ea51 100644 --- a/packages/web3-core-method/src/index.js +++ b/packages/web3-core-method/src/index.js @@ -711,21 +711,21 @@ Method.prototype.buildCall = function () { // If wallet was found, sign tx, and send using sendRawTransaction if (wallet && wallet.privateKey) { - delete txOptions.from; + delete tx.from; - if (method.defaultChain && !txOptions.chain) { - txOptions.chain = method.defaultChain; + if (method.defaultChain && !tx.chain) { + tx.chain = method.defaultChain; } - if (method.defaultHardfork && !txOptions.hardfork) { - txOptions.hardfork = method.defaultHardfork; + if (method.defaultHardfork && !tx.hardfork) { + tx.hardfork = method.defaultHardfork; } - if (method.defaultCommon && !txOptions.common) { - txOptions.common = method.defaultCommon; + if (method.defaultCommon && !tx.common) { + tx.common = method.defaultCommon; } - method.accounts.signTransaction(txOptions, wallet.privateKey) + method.accounts.signTransaction(tx, wallet.privateKey) .then(sendSignedTx) .catch(function (err) { if (typeof defer.eventEmitter.listeners === 'function' && defer.eventEmitter.listeners('error').length) { diff --git a/packages/web3-eth-accounts/src/index.js b/packages/web3-eth-accounts/src/index.js index 6a0ab8b58d8..5fc36c5c8a7 100644 --- a/packages/web3-eth-accounts/src/index.js +++ b/packages/web3-eth-accounts/src/index.js @@ -36,7 +36,7 @@ var Common = require('@ethereumjs/common').default; var isNot = function(value) { - return (typeof value === 'undefined') || value == null; + return (typeof value === 'undefined') || value === null; }; var Accounts = function Accounts() { @@ -467,7 +467,7 @@ function Wallet(accounts) { Wallet.prototype._findSafeIndex = function(pointer) { pointer = pointer || 0; - if (this != null && this.hasOwnProperty(pointer)) { + if (this.hasOwnProperty(pointer)) { return this._findSafeIndex(pointer + 1); } else { return pointer; @@ -496,7 +496,7 @@ Wallet.prototype.create = function(numberOfAccounts, entropy) { Wallet.prototype.add = function(account) { - if (typeof account == 'string') { + if (typeof account === 'string') { account = this._accounts.privateKeyToAccount(account); } if (!this[account.address]) { diff --git a/packages/web3-eth-contract/src/index.js b/packages/web3-eth-contract/src/index.js index 5df766b2f87..9d35999492b 100644 --- a/packages/web3-eth-contract/src/index.js +++ b/packages/web3-eth-contract/src/index.js @@ -76,11 +76,11 @@ var Contract = function Contract(jsonInterface, address, options) { this.options = {}; var lastArg = args[args.length - 1]; - if(typeof lastArg == 'object' && !!lastArg && !Array.isArray(lastArg)) { + if(typeof lastArg === 'object' && !!lastArg && !Array.isArray(lastArg)) { options = lastArg; this.options = { ...this.options, ...this._getOrSetDefaultOptions(options)}; - if(typeof address == 'object' && !!address) { + if(typeof address === 'object' && !!address) { address = null; } } diff --git a/packages/web3-utils/src/utils.js b/packages/web3-utils/src/utils.js index 3056afd1f40..4e71b160f52 100644 --- a/packages/web3-utils/src/utils.js +++ b/packages/web3-utils/src/utils.js @@ -231,7 +231,7 @@ var hexToNumber = function (value) { return value; } - if (typeof value == 'string' && !isHexStrict(value)) { + if (typeof value === 'string' && !isHexStrict(value)) { throw new Error('Given value "'+value+'" is not a valid hex string.'); } @@ -248,7 +248,7 @@ var hexToNumber = function (value) { var hexToNumberString = function (value) { if (!value) return value; - if (typeof value == 'string' && !isHexStrict(value)) { + if (typeof value === 'string' && !isHexStrict(value)) { throw new Error('Given value "'+value+'" is not a valid hex string.'); } From f3ca98249e1c8335fefdef4d80ecb8410290e426 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 8 Jul 2021 14:03:01 -0400 Subject: [PATCH 18/19] efficient short circuiting --- packages/web3-bzz/src/index.js | 2 +- packages/web3-core-helpers/src/formatters.js | 2 +- packages/web3-core-method/src/index.js | 10 +++++----- packages/web3-core-subscriptions/src/subscription.js | 6 +++--- packages/web3-eth-abi/src/index.js | 4 ++-- packages/web3-eth-accounts/src/index.js | 4 ++-- packages/web3-eth-contract/src/index.js | 10 +++++----- packages/web3-utils/src/index.js | 6 +++--- packages/web3-utils/src/soliditySha3.js | 2 +- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/web3-bzz/src/index.js b/packages/web3-bzz/src/index.js index 34f006518a4..b81e7f67433 100644 --- a/packages/web3-bzz/src/index.js +++ b/packages/web3-bzz/src/index.js @@ -51,7 +51,7 @@ if (typeof ethereum !== 'undefined' && ethereum.bzz) { Bzz.prototype.setProvider = function(provider) { // is ethereum provider - if(typeof provider === 'object' && !!provider && typeof provider.bzz === 'string') { + if(!!provider && typeof provider === 'object' && typeof provider.bzz === 'string') { provider = provider.bzz; // is no string, set default } diff --git a/packages/web3-core-helpers/src/formatters.js b/packages/web3-core-helpers/src/formatters.js index 86a0191f007..2de56c11105 100644 --- a/packages/web3-core-helpers/src/formatters.js +++ b/packages/web3-core-helpers/src/formatters.js @@ -200,7 +200,7 @@ var inputTransactionFormatter = function (options) { options = _txInputFormatter(options); // check from, only if not number, or object - if (!(typeof options.from === 'number') && !(typeof options.from === 'object' && !!options.from)) { + if (!(typeof options.from === 'number') && !(!!options.from && typeof options.from === 'object')) { options.from = options.from || (this ? this.defaultAccount : null); if (!options.from && !(typeof options.from === 'number')) { diff --git a/packages/web3-core-method/src/index.js b/packages/web3-core-method/src/index.js index e0d3446ea51..dd2d3bd991d 100644 --- a/packages/web3-core-method/src/index.js +++ b/packages/web3-core-method/src/index.js @@ -206,8 +206,8 @@ Method.prototype._confirmTransaction = function (defer, result, payload) { intervalId = null, lastBlock = null, receiptJSON = '', - gasProvided = ((typeof payload.params[0] === 'object' && !!payload.params[0]) && payload.params[0].gas) ? payload.params[0].gas : null, - isContractDeployment = (typeof payload.params[0] === 'object' && !!payload.params[0]) && + gasProvided = ((!!payload.params[0] && typeof payload.params[0] === 'object') && payload.params[0].gas) ? payload.params[0].gas : null, + isContractDeployment = (!!payload.params[0] && typeof payload.params[0] === 'object') && payload.params[0].data && payload.params[0].from && !payload.params[0].to, @@ -595,7 +595,7 @@ var getWallet = function (from, accounts) { wallet = accounts.wallet[from]; // is account given - } else if (typeof from === 'object' && !!from && from.address && from.privateKey) { + } else if (!!from && typeof from === 'object' && from.address && from.privateKey) { wallet = from; // search in wallet for address @@ -706,7 +706,7 @@ Method.prototype.buildCall = function () { // ETH_SENDTRANSACTION if (payload.method === 'eth_sendTransaction') { var tx = payload.params[0]; - wallet = getWallet((typeof tx === 'object' && !!tx) ? tx.from : null, method.accounts); + wallet = getWallet((!!tx && typeof tx === 'object') ? tx.from : null, method.accounts); // If wallet was found, sign tx, and send using sendRawTransaction @@ -769,7 +769,7 @@ Method.prototype.buildCall = function () { }; // Send the actual transaction - if (isSendTx && typeof payload.params[0] === 'object' && !!payload.params[0] && typeof payload.params[0].gasPrice === 'undefined') { + if (isSendTx && !!payload.params[0] && typeof payload.params[0] === 'object' && typeof payload.params[0].gasPrice === 'undefined') { var getGasPrice = (new Method({ name: 'getGasPrice', diff --git a/packages/web3-core-subscriptions/src/subscription.js b/packages/web3-core-subscriptions/src/subscription.js index 4ba0d913bb5..b0b134d7997 100644 --- a/packages/web3-core-subscriptions/src/subscription.js +++ b/packages/web3-core-subscriptions/src/subscription.js @@ -229,7 +229,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 && typeof this.options.params === 'object' && !!this.options.params ){ + if (this.lastBlock && !!this.options.params && typeof this.options.params === 'object'){ payload.params[1] = this.options.params; payload.params[1].fromBlock = formatters.inputBlockNumberFormatter(this.lastBlock + 1); } @@ -243,7 +243,7 @@ Subscription.prototype.subscribe = function() { this.options.params = payload.params[1]; // get past logs, if fromBlock is available - if(payload.params[0] === 'logs' && typeof payload.params[1] === 'object' && !!payload.params[1] && payload.params[1].hasOwnProperty('fromBlock') && isFinite(payload.params[1].fromBlock)) { + if(payload.params[0] === 'logs' && !!payload.params[1] && typeof payload.params[1] === 'object' && payload.params[1].hasOwnProperty('fromBlock') && isFinite(payload.params[1].fromBlock)) { // send the subscription request // copy the params to avoid race-condition with deletion below this block @@ -294,7 +294,7 @@ Subscription.prototype.subscribe = function() { var output = _this._formatOutput(resultItem); // Track current block (for gaps introduced by dropped connections) - _this.lastBlock = typeof output === 'object' && !!output ? output.blockNumber : null; + _this.lastBlock = !!output && typeof output === 'object' ? output.blockNumber : null; if (typeof _this.options.subscription.subscriptionHandler === 'function' ) { return _this.options.subscription.subscriptionHandler.call(_this, output); diff --git a/packages/web3-eth-abi/src/index.js b/packages/web3-eth-abi/src/index.js index ea880ac83fb..63728ac567c 100644 --- a/packages/web3-eth-abi/src/index.js +++ b/packages/web3-eth-abi/src/index.js @@ -27,7 +27,7 @@ var utils = require('web3-utils'); var EthersAbiCoder = require('@ethersproject/abi').AbiCoder; var ParamType = require('@ethersproject/abi').ParamType; var ethersAbiCoder = new EthersAbiCoder(function (type, value) { - if (type.match(/^u?int/) && !Array.isArray(value) && (!(typeof value === 'object' && !!value) || value.constructor.name !== 'BN')) { + if (type.match(/^u?int/) && !Array.isArray(value) && (!(!!value && typeof value === 'object') || value.constructor.name !== 'BN')) { return value.toString(); } return value; @@ -366,7 +366,7 @@ ABICoder.prototype.decodeParametersWith = function (outputs, bytes, loose) { returnValue[i] = decodedValue; - if ((typeof output === 'function' || typeof output === 'object' && !!output) && output.name) { + if ((typeof output === 'function' || !!output && typeof output === 'object') && output.name) { returnValue[output.name] = decodedValue; } diff --git a/packages/web3-eth-accounts/src/index.js b/packages/web3-eth-accounts/src/index.js index 5fc36c5c8a7..0a21ef48af1 100644 --- a/packages/web3-eth-accounts/src/index.js +++ b/packages/web3-eth-accounts/src/index.js @@ -333,7 +333,7 @@ Accounts.prototype.recover = function recover(message, signature, preFixed) { var args = [].slice.apply(arguments); - if (typeof message === 'object' && !!message) { + if (!!message && typeof message === 'object') { return this.recover(message.messageHash, Account.encodeSignature([message.v, message.r, message.s]), true); } @@ -358,7 +358,7 @@ Accounts.prototype.decrypt = function(v3Keystore, password, nonStrict) { throw new Error('No password given.'); } - var json = (typeof v3Keystore === 'object' && !!v3Keystore) ? v3Keystore : JSON.parse(nonStrict ? v3Keystore.toLowerCase() : v3Keystore); + var json = (!!v3Keystore && typeof v3Keystore === 'object') ? v3Keystore : JSON.parse(nonStrict ? v3Keystore.toLowerCase() : v3Keystore); if (json.version !== 3) { throw new Error('Not a valid V3 wallet'); diff --git a/packages/web3-eth-contract/src/index.js b/packages/web3-eth-contract/src/index.js index 9d35999492b..e597eef7b39 100644 --- a/packages/web3-eth-contract/src/index.js +++ b/packages/web3-eth-contract/src/index.js @@ -76,11 +76,11 @@ var Contract = function Contract(jsonInterface, address, options) { this.options = {}; var lastArg = args[args.length - 1]; - if(typeof lastArg === 'object' && !!lastArg && !Array.isArray(lastArg)) { + if(!!lastArg && typeof lastArg === 'object' && !Array.isArray(lastArg)) { options = lastArg; this.options = { ...this.options, ...this._getOrSetDefaultOptions(options)}; - if(typeof address === 'object' && !!address) { + if(!!address && typeof address === 'object') { address = null; } } @@ -325,7 +325,7 @@ Contract.setProvider = function(provider, accounts) { * @return {Function} the callback */ Contract.prototype._getCallback = function getCallback(args) { - if (args && typeof args[args.length - 1] === 'function' && !!args[args.length- 1 ]) { + if (args && !!args[args.length- 1 ] && typeof args[args.length - 1] === 'function') { return args.pop(); // modify the args array! } }; @@ -634,7 +634,7 @@ Contract.prototype._generateEventOptions = function() { var callback = this._getCallback(args); // get the options - var options = (typeof args[args.length - 1]) === 'object' && !!args[args.length - 1] ? args.pop() : {}; + var options = (!!args[args.length - 1] && typeof args[args.length - 1]) === 'object' ? args.pop() : {}; var eventName = (typeof args[0] === 'string') ? args[0] : 'allevents'; var event = (eventName.toLowerCase() === 'allevents') ? { @@ -847,7 +847,7 @@ Contract.prototype._processExecuteArguments = function _processExecuteArguments( processedArgs.defaultBlock = args.pop(); // get the options - processedArgs.options = (typeof args[args.length - 1]) === 'object' && !!args[args.length - 1] ? args.pop() : {}; + processedArgs.options = (!!args[args.length - 1] && typeof args[args.length - 1]) === 'object' ? args.pop() : {}; // get the generateRequest argument for batch requests processedArgs.generateRequest = (args[args.length - 1] === true)? args.pop() : false; diff --git a/packages/web3-utils/src/index.js b/packages/web3-utils/src/index.js index d9f312d04c2..1eec4b76c3d 100644 --- a/packages/web3-utils/src/index.js +++ b/packages/web3-utils/src/index.js @@ -43,8 +43,8 @@ var _fireError = function (error, emitter, reject, callback, optionalData) { /*jshint maxcomplexity: 10 */ // add data if given - if(typeof error === 'object' && !!error && !(error instanceof Error) && error.data) { - if(typeof error.data === 'object' && !!error.data || Array.isArray(error.data)) { + if(!!error && typeof error === 'object' && !(error instanceof Error) && error.data) { + if(!!error.data && typeof error.data === 'object' || Array.isArray(error.data)) { error.data = JSON.stringify(error.data, null, 2); } @@ -93,7 +93,7 @@ var _fireError = function (error, emitter, reject, callback, optionalData) { * @return {String} full function/event name */ var _jsonInterfaceMethodToString = function (json) { - if (typeof json === 'object' && !!json && json.name && json.name.indexOf('(') !== -1) { + if (!!json && typeof json === 'object' && json.name && json.name.indexOf('(') !== -1) { return json.name; } diff --git a/packages/web3-utils/src/soliditySha3.js b/packages/web3-utils/src/soliditySha3.js index 657b20ff441..3366180c446 100644 --- a/packages/web3-utils/src/soliditySha3.js +++ b/packages/web3-utils/src/soliditySha3.js @@ -179,7 +179,7 @@ var _processSolidityEncodePackedArgs = function (arg) { var hexArg, arraySize; // if type is given - if (typeof arg === 'object' && !!arg && (arg.hasOwnProperty('v') || arg.hasOwnProperty('t') || arg.hasOwnProperty('value') || arg.hasOwnProperty('type'))) { + if (!!arg && typeof arg === 'object' && (arg.hasOwnProperty('v') || arg.hasOwnProperty('t') || arg.hasOwnProperty('value') || arg.hasOwnProperty('type'))) { type = arg.hasOwnProperty('t') ? arg.t : arg.type; value = arg.hasOwnProperty('v') ? arg.v : arg.value; From ea7b28c08b66603c0d565edd7c0f76c392517050 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 8 Jul 2021 15:14:20 -0400 Subject: [PATCH 19/19] fixing test case --- packages/web3-core-method/src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/web3-core-method/src/index.js b/packages/web3-core-method/src/index.js index dd2d3bd991d..7335adbb7be 100644 --- a/packages/web3-core-method/src/index.js +++ b/packages/web3-core-method/src/index.js @@ -711,6 +711,7 @@ Method.prototype.buildCall = function () { // If wallet was found, sign tx, and send using sendRawTransaction if (wallet && wallet.privateKey) { + var tx = JSON.parse(JSON.stringify(tx)); delete tx.from; if (method.defaultChain && !tx.chain) {