Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove underscore #4069

Merged
merged 21 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -130,7 +129,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"
Expand Down
3 changes: 1 addition & 2 deletions packages/web3-bzz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions packages/web3-bzz/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

"use strict";

var _ = require('underscore');
var swarm = require("swarm-js");


Expand Down Expand Up @@ -52,7 +51,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 && typeof provider.bzz === 'string') {
luu-alex marked this conversation as resolved.
Show resolved Hide resolved
provider = provider.bzz;
// is no string, set default
}
Expand All @@ -61,7 +60,7 @@ Bzz.prototype.setProvider = function(provider) {
// }


if(_.isString(provider)) {
if(typeof provider === 'string') {
this.currentProvider = provider;
} else {
this.currentProvider = null;
Expand Down
1 change: 0 additions & 1 deletion packages/web3-core-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
},
"main": "lib/index.js",
"dependencies": {
"underscore": "1.12.1",
"web3-eth-iban": "1.4.0",
"web3-utils": "1.4.0"
},
Expand Down
19 changes: 9 additions & 10 deletions packages/web3-core-helpers/src/formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

"use strict";

var _ = require('underscore');
var utils = require('web3-utils');
var Iban = require('web3-eth-iban');

Expand Down Expand Up @@ -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);
};

/**
Expand Down Expand Up @@ -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!');
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
});
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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] : [];
}

Expand Down
1 change: 0 additions & 1 deletion packages/web3-core-method/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"main": "lib/index.js",
"dependencies": {
"@ethersproject/transactions": "^5.0.0-beta.135",
"underscore": "1.12.1",
"web3-core-helpers": "1.4.0",
"web3-core-promievent": "1.4.0",
"web3-core-subscriptions": "1.4.0",
Expand Down
46 changes: 23 additions & 23 deletions packages/web3-core-method/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -102,7 +101,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;
};

/**
Expand All @@ -113,7 +112,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!
}
};
Expand Down Expand Up @@ -161,7 +160,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;
});
Expand All @@ -180,6 +179,7 @@ Method.prototype.formatOutput = function (result) {
Method.prototype.toPayload = function (args) {
var call = this.getCall(args);
var callback = this.extractCallback(args);

var params = this.formatInput(args);
this.validateArgs(params);

Expand All @@ -206,8 +206,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]) && payload.params[0].gas) ? payload.params[0].gas : null,
luu-alex marked this conversation as resolved.
Show resolved Hide resolved
isContractDeployment = (typeof payload.params[0] === 'object' && !!payload.params[0]) &&
luu-alex marked this conversation as resolved.
Show resolved Hide resolved
payload.params[0].data &&
payload.params[0].from &&
!payload.params[0].to,
Expand Down Expand Up @@ -258,7 +258,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()
});
Expand Down Expand Up @@ -591,11 +591,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 && from.address && from.privateKey) {
wallet = from;

// search in wallet for address
Expand Down Expand Up @@ -689,10 +689,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);
};
Expand All @@ -706,29 +706,29 @@ 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) ? tx.from : null, method.accounts);


// If wallet was found, sign tx, and send using sendRawTransaction
if (wallet && wallet.privateKey) {
var txOptions = _.omit(tx, '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 (_.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) {
Expand Down Expand Up @@ -769,7 +769,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' && !!payload.params[0] && typeof payload.params[0].gasPrice === 'undefined') {

var getGasPrice = (new Method({
name: 'getGasPrice',
Expand Down Expand Up @@ -866,7 +866,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';
};

/**
Expand Down
1 change: 0 additions & 1 deletion packages/web3-core-requestmanager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"compile": "tsc -b tsconfig.json"
},
"dependencies": {
"underscore": "1.12.1",
"util": "^0.12.0",
"web3-core-helpers": "1.4.0",
"web3-providers-http": "1.4.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/web3-core-requestmanager/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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));
}

Expand Down
1 change: 0 additions & 1 deletion packages/web3-core-subscriptions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"main": "lib/index.js",
"dependencies": {
"eventemitter3": "4.0.4",
"underscore": "1.12.1",
"web3-core-helpers": "1.4.0"
},
"devDependencies": {
Expand Down
Loading