From cea3e2ba2d222397264d5368984b12a77f8886d0 Mon Sep 17 00:00:00 2001 From: Samuel Furter Date: Mon, 4 Feb 2019 15:52:23 +0100 Subject: [PATCH] provider resolving simpllyified, documenation updated, types updated --- docs/include_package-core.rst | 12 +- docs/web3-eth-abi.rst | 7 +- docs/web3.rst | 17 +-- packages/web3-core/src/AbstractWeb3Module.js | 8 +- .../tests/src/AbstractWeb3ModuleTest.js | 6 +- packages/web3-eth-ens/src/Ens.js | 5 +- .../web3-eth-ens/src/contracts/Registry.js | 7 +- packages/web3-eth-personal/src/Personal.js | 6 +- .../tests/src/PersonalTest.js | 4 +- packages/web3-eth/src/Eth.js | 13 +- packages/web3-eth/tests/src/EthTest.js | 10 +- .../src/resolvers/ProviderResolver.js | 8 +- .../src/resolvers/ProviderResolverTest.js | 13 -- packages/web3-providers/types/index.d.ts | 2 +- .../types/tests/provider-resolver-test.ts | 3 +- packages/web3-shh/src/Shh.js | 5 +- packages/web3-shh/tests/src/ShhTest.js | 8 +- packages/web3-utils/package-lock.json | 131 +++++------------- packages/web3/src/Web3.js | 28 ++-- packages/web3/tests/src/Web3Test.js | 14 +- 20 files changed, 104 insertions(+), 203 deletions(-) diff --git a/docs/include_package-core.rst b/docs/include_package-core.rst index aa92cb21269..c265e1287cb 100644 --- a/docs/include_package-core.rst +++ b/docs/include_package-core.rst @@ -227,7 +227,6 @@ Parameters ---------- 1. ``Object|String`` - ``provider``: a valid provider -2. ``Net`` - ``net``: (optional) the node.js Net package. This is only required for the IPC provider. ------- Returns @@ -254,10 +253,8 @@ Example web3.setProvider(new Web3.providers.WebsocketProvider('ws://localhost:8546')); // Using the IPC provider in node.js - const net = require('net'); - const web3 = new Web3('/Users/myuser/Library/Ethereum/geth.ipc', net); // mac os path + import net from 'net'; - // or const web3 = new Web3(new Web3.providers.IpcProvider('/Users/myuser/Library/Ethereum/geth.ipc', net)); // mac os path // on windows the path is: '\\\\.\\pipe\\geth.ipc' // on linux the path is: '/users/myuser/.ethereum/geth.ipc' @@ -291,17 +288,16 @@ Example .. code-block:: javascript - const Web3 = require('web3'); + import Web3 from 'web3'; + // use the given Provider, e.g in Mist, or instantiate a new websocket provider const web3 = new Web3(Web3.givenProvider || 'ws://localhost:8546'); // or const web3 = new Web3(Web3.givenProvider || new Web3.providers.WebsocketProvider('ws://localhost:8546')); // Using the IPC provider in node.js - const net = require('net'); + import net from 'net'; - const web3 = new Web3('/Users/myuser/Library/Ethereum/geth.ipc', net); // mac os path - // or const web3 = new Web3(new Web3.providers.IpcProvider('/Users/myuser/Library/Ethereum/geth.ipc', net)); // mac os path // on windows the path is: '\\\\.\\pipe\\geth.ipc' // on linux the path is: '/users/myuser/.ethereum/geth.ipc' diff --git a/docs/web3-eth-abi.rst b/docs/web3-eth-abi.rst index 520e18a3434..7811cdb76e2 100644 --- a/docs/web3-eth-abi.rst +++ b/docs/web3-eth-abi.rst @@ -17,16 +17,11 @@ This will be used for function calls to the EVM (Ethereum Virtual Machine). // or using the web3 umbrella package - - import {Web3} from 'web3'; const web3 = new Web3(Web3.givenProvider || 'ws://some.local-or-remote.node:8546', options); // -> web3.eth.abi - - - ------------------------------------------------------------------------------ @@ -191,6 +186,7 @@ Example } ); > "0x000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000002d000000000000000000000000000000000000000000000000000000000000004e" + ------------------------------------------------------------------------------ encodeParameters @@ -475,7 +471,6 @@ Example ------------------------------------------------------------------------------ - decodeLog ===================== diff --git a/docs/web3.rst b/docs/web3.rst index d11791c5fcf..cdcdd63d998 100644 --- a/docs/web3.rst +++ b/docs/web3.rst @@ -25,12 +25,6 @@ Web3 Web3.modules ===================== - Static property of the Web3 class - -.. code-block:: javascript - - Web3.modules - Will return an object with the classes of all major sub modules, to be able to instantiate them manually. ------- @@ -52,11 +46,11 @@ Example Web3.modules > { - Eth: Eth function(provider, options?, net?), - Net: Net function(provider, options?, net?), - Personal: Personal function(provider, options?, net?), - Shh: Shh function(provider, options?, net?), - Bzz: Bzz function(provider, options?, net?), + Eth: Eth function(provider, options?), + Net: Net function(provider, options?), + Personal: Personal function(provider, options?), + Shh: Shh function(provider, options?), + Bzz: Bzz function(provider, options?), } @@ -96,7 +90,6 @@ Example ------------------------------------------------------------------------------ - utils ===================== diff --git a/packages/web3-core/src/AbstractWeb3Module.js b/packages/web3-core/src/AbstractWeb3Module.js index c2d15caa421..764ad4c2e4f 100644 --- a/packages/web3-core/src/AbstractWeb3Module.js +++ b/packages/web3-core/src/AbstractWeb3Module.js @@ -259,18 +259,20 @@ export default class AbstractWeb3Module { } /** + * TODO: Remove the net parameter. Developers should pass a IpcProvider instance if they would like to connect to a + * local node. + * * Sets the currentProvider and provider property * * @method setProvider * * @param {EthereumProvider|HttpProvider|WebsocketProvider|IpcProvider|String} provider - * @param {Net} net * * @returns {Boolean|Error} */ - setProvider(provider, net) { + setProvider(provider) { if (!this.isSameProvider(provider)) { - const resolvedProvider = this.providerResolver.resolve(provider, net); + const resolvedProvider = this.providerResolver.resolve(provider); this.clearSubscriptions(); this._currentProvider = resolvedProvider; diff --git a/packages/web3-core/tests/src/AbstractWeb3ModuleTest.js b/packages/web3-core/tests/src/AbstractWeb3ModuleTest.js index 9da975c8e56..d44c8106652 100644 --- a/packages/web3-core/tests/src/AbstractWeb3ModuleTest.js +++ b/packages/web3-core/tests/src/AbstractWeb3ModuleTest.js @@ -188,7 +188,7 @@ describe('AbstractWeb3ModuleTest', () => { expect(providerResolverMock.resolve).toHaveBeenNthCalledWith(1, 'WS'); - expect(providerResolverMock.resolve).toHaveBeenNthCalledWith(2, 'SOCKET_PROVIDER', undefined); + expect(providerResolverMock.resolve).toHaveBeenNthCalledWith(2, 'SOCKET_PROVIDER'); expect(abstractWeb3Module.currentProvider).toEqual(providerMock); }); @@ -201,7 +201,7 @@ describe('AbstractWeb3ModuleTest', () => { expect(providerResolverMock.resolve).toHaveBeenNthCalledWith(1, 'WS'); - expect(providerResolverMock.resolve).toHaveBeenNthCalledWith(2, 'SOCKET_PROVIDER', undefined); + expect(providerResolverMock.resolve).toHaveBeenNthCalledWith(2, 'SOCKET_PROVIDER'); expect(providerMock.clearSubscriptions).toHaveBeenCalled(); @@ -224,7 +224,7 @@ describe('AbstractWeb3ModuleTest', () => { abstractWeb3Module.setProvider(provider); }).toThrow('Invalid provider'); - expect(providerResolverMock.resolve).toHaveBeenCalledWith(provider, undefined); + expect(providerResolverMock.resolve).toHaveBeenCalledWith(provider); }); it('calls setProvider and returns false because of the equal host', () => { diff --git a/packages/web3-eth-ens/src/Ens.js b/packages/web3-eth-ens/src/Ens.js index 96c5af34092..2f5bb914c4a 100644 --- a/packages/web3-eth-ens/src/Ens.js +++ b/packages/web3-eth-ens/src/Ens.js @@ -97,12 +97,11 @@ export default class Ens extends AbstractWeb3Module { * @method setProvider * * @param {HttpProvider|WebsocketProvider|IpcProvider|EthereumProvider|String} provider - * @param {Net} net * * @returns {Boolean} */ - setProvider(provider, net) { - return !!(super.setProvider(provider, net) && this.registry.setProvider(provider, net)); + setProvider(provider) { + return !!(super.setProvider(provider) && this.registry.setProvider(provider)); } /** diff --git a/packages/web3-eth-ens/src/contracts/Registry.js b/packages/web3-eth-ens/src/contracts/Registry.js index d900d4f75b3..d1e79caff4c 100644 --- a/packages/web3-eth-ens/src/contracts/Registry.js +++ b/packages/web3-eth-ens/src/contracts/Registry.js @@ -113,16 +113,15 @@ export default class Registry extends AbstractContract { * @method setProvider * * @param {HttpProvider|WebsocketProvider|IpcProvider|EthereumProvider|String} provider - * @param {Net} net * * @returns {Boolean} */ - setProvider(provider, net) { + setProvider(provider) { if (this.resolverContract) { - return !!(super.setProvider(provider, net) && this.resolverContract.setProvider(provider, net)); + return !!(super.setProvider(provider) && this.resolverContract.setProvider(provider)); } - return super.setProvider(provider, net); + return super.setProvider(provider); } /** diff --git a/packages/web3-eth-personal/src/Personal.js b/packages/web3-eth-personal/src/Personal.js index 22f2237b1fa..7e7441dd6bb 100644 --- a/packages/web3-eth-personal/src/Personal.js +++ b/packages/web3-eth-personal/src/Personal.js @@ -26,6 +26,7 @@ import {AbstractWeb3Module} from 'web3-core'; export default class Personal extends AbstractWeb3Module { /** * TODO: Add missing documentation for getAccounts, lockAccount and sendTransaction! + * * @param {EthereumProvider|HttpProvider|WebsocketProvider|IpcProvider|String} provider * @param {ProvidersModuleFactory} providersModuleFactory * @param {MethodModuleFactory} methodModuleFactory @@ -51,12 +52,11 @@ export default class Personal extends AbstractWeb3Module { * @method setProvider * * @param {Object|String} provider - * @param {Net} net * * @returns {Boolean} */ - setProvider(provider, net) { - return !!(super.setProvider(provider, net) && this.net.setProvider(provider, net)); + setProvider(provider) { + return !!(super.setProvider(provider) && this.net.setProvider(provider)); } /** diff --git a/packages/web3-eth-personal/tests/src/PersonalTest.js b/packages/web3-eth-personal/tests/src/PersonalTest.js index 2b372c5f914..25d7617acb7 100644 --- a/packages/web3-eth-personal/tests/src/PersonalTest.js +++ b/packages/web3-eth-personal/tests/src/PersonalTest.js @@ -119,9 +119,9 @@ describe('PersonalTest', () => { networkMock.setProvider = jest.fn(); networkMock.setProvider.mockReturnValueOnce(true); - expect(personal.setProvider('provider', 'net')).toEqual(true); + expect(personal.setProvider('provider')).toEqual(true); - expect(networkMock.setProvider).toHaveBeenCalledWith('provider', 'net'); + expect(networkMock.setProvider).toHaveBeenCalledWith('provider'); }); it('sets the defaultGasPrice property', () => { diff --git a/packages/web3-eth/src/Eth.js b/packages/web3-eth/src/Eth.js index 79c9fe6f9b9..282c22ce94e 100644 --- a/packages/web3-eth/src/Eth.js +++ b/packages/web3-eth/src/Eth.js @@ -353,20 +353,19 @@ export default class Eth extends AbstractWeb3Module { * This is required for updating the provider also in the sub packages and objects related to Eth. * * @param {Object|String} provider - * @param {Net} net * * @returns {Boolean} */ - setProvider(provider, net) { + setProvider(provider) { const setContractProviders = this.initiatedContracts.every((contract) => { - return contract.setProvider(provider, net); + return contract.setProvider(provider); }); return ( - this.net.setProvider(provider, net) && - this.personal.setProvider(provider, net) && - this.accounts.setProvider(provider, net) && - super.setProvider(provider, net) && + this.net.setProvider(provider) && + this.personal.setProvider(provider) && + this.accounts.setProvider(provider) && + super.setProvider(provider) && setContractProviders ); } diff --git a/packages/web3-eth/tests/src/EthTest.js b/packages/web3-eth/tests/src/EthTest.js index 1c754025f04..30bebcfb09b 100644 --- a/packages/web3-eth/tests/src/EthTest.js +++ b/packages/web3-eth/tests/src/EthTest.js @@ -435,14 +435,14 @@ describe('EthTest', () => { accountsMock.setProvider.mockReturnValueOnce(true); - expect(eth.setProvider('provider', 'net')).toEqual(true); + expect(eth.setProvider('provider')).toEqual(true); - expect(eth.initiatedContracts[0].setProvider).toHaveBeenCalledWith('provider', 'net'); + expect(eth.initiatedContracts[0].setProvider).toHaveBeenCalledWith('provider'); - expect(networkMock.setProvider).toHaveBeenCalledWith('provider', 'net'); + expect(networkMock.setProvider).toHaveBeenCalledWith('provider'); - expect(personalMock.setProvider).toHaveBeenCalledWith('provider', 'net'); + expect(personalMock.setProvider).toHaveBeenCalledWith('provider'); - expect(accountsMock.setProvider).toHaveBeenCalledWith('provider', 'net'); + expect(accountsMock.setProvider).toHaveBeenCalledWith('provider'); }); }); diff --git a/packages/web3-providers/src/resolvers/ProviderResolver.js b/packages/web3-providers/src/resolvers/ProviderResolver.js index 1bc89161304..7d7a0d2d56e 100644 --- a/packages/web3-providers/src/resolvers/ProviderResolver.js +++ b/packages/web3-providers/src/resolvers/ProviderResolver.js @@ -51,11 +51,10 @@ export default class ProviderResolver { * @method resolve * * @param {EthereumProvider|HttpProvider|WebsocketProvider|IpcProvider|String} provider - * @param {Net} net * * @returns {EthereumProvider|HttpProvider|WebsocketProvider|IpcProvider|Error} */ - resolve(provider, net) { + resolve(provider) { if (typeof provider === 'string') { // HTTP if (/^http(s)?:\/\//i.test(provider)) { @@ -65,11 +64,6 @@ export default class ProviderResolver { if (/^ws(s)?:\/\//i.test(provider)) { return this.providersModuleFactory.createWebsocketProvider(provider); } - - // IPC - if (provider && isObject(net) && isFunction(net.connect)) { - return this.providersModuleFactory.createIpcProvider(provider, net); - } } if (typeof global.mist !== 'undefined' && provider.constructor.name === 'EthereumProvider') { diff --git a/packages/web3-providers/tests/src/resolvers/ProviderResolverTest.js b/packages/web3-providers/tests/src/resolvers/ProviderResolverTest.js index 95ee156afcd..639458fbc22 100644 --- a/packages/web3-providers/tests/src/resolvers/ProviderResolverTest.js +++ b/packages/web3-providers/tests/src/resolvers/ProviderResolverTest.js @@ -47,19 +47,6 @@ describe('ProviderResolverTest', () => { expect(providersModuleFactoryMock.createWebsocketProvider).toHaveBeenCalledWith('ws://127.0.0.1:8545'); }); - it('calls resolve with Ipc path and net object', () => { - new IpcProvider({}, '/path/to/the/socket'); - const ipcProviderMock = IpcProvider.mock.instances[0]; - - const net = {connect: () => {}}; - - providersModuleFactory.createIpcProvider.mockReturnValueOnce(ipcProviderMock); - - expect(providerResolver.resolve('/path/to/the/socket', net)).toBeInstanceOf(IpcProvider); - - expect(providersModuleFactoryMock.createIpcProvider).toHaveBeenCalledWith('/path/to/the/socket', net); - }); - it('calls resolve with the HttpProvider', () => { new HttpProvider('host', {}, providersModuleFactoryMock); const httpProviderMock = HttpProvider.mock.instances[0]; diff --git a/packages/web3-providers/types/index.d.ts b/packages/web3-providers/types/index.d.ts index 7ae588d8d2f..97f695cbf2a 100644 --- a/packages/web3-providers/types/index.d.ts +++ b/packages/web3-providers/types/index.d.ts @@ -138,7 +138,7 @@ export class JsonRpcMapper { export class ProviderResolver { constructor(providersPackageFactory: ProvidersModuleFactory); - resolve(provider: provider, net: net.Socket): provider; + resolve(provider: provider): provider; } export class JsonRpcResponseValidator { diff --git a/packages/web3-providers/types/tests/provider-resolver-test.ts b/packages/web3-providers/types/tests/provider-resolver-test.ts index b987f3667ae..65fd055117a 100644 --- a/packages/web3-providers/types/tests/provider-resolver-test.ts +++ b/packages/web3-providers/types/tests/provider-resolver-test.ts @@ -20,7 +20,6 @@ * @date 2018 */ -import * as net from "net"; import {ProviderResolver, ProvidersModuleFactory, HttpProvider} from 'web3-providers'; const options = { @@ -37,4 +36,4 @@ const providersModuleFactory = new ProvidersModuleFactory(); const providerResolver = new ProviderResolver(providersModuleFactory); // $ExpectType provider -providerResolver.resolve(provider, new net.Socket()); +providerResolver.resolve(provider); diff --git a/packages/web3-shh/src/Shh.js b/packages/web3-shh/src/Shh.js index 83f740da4ac..750cc7df5c7 100644 --- a/packages/web3-shh/src/Shh.js +++ b/packages/web3-shh/src/Shh.js @@ -86,12 +86,11 @@ export default class Shh extends AbstractWeb3Module { * This is required for updating the provider also in the sub package Net. * * @param {Object|String} provider - * @param {Net} net * * @returns {Boolean} */ - setProvider(provider, net) { - return super.setProvider(provider, net) && this.net.setProvider(provider, net); + setProvider(provider) { + return super.setProvider(provider) && this.net.setProvider(provider); } /** diff --git a/packages/web3-shh/tests/src/ShhTest.js b/packages/web3-shh/tests/src/ShhTest.js index fd2ca59e51b..880545174b0 100644 --- a/packages/web3-shh/tests/src/ShhTest.js +++ b/packages/web3-shh/tests/src/ShhTest.js @@ -161,18 +161,18 @@ describe('ShhTest', () => { networkMock.setProvider = jest.fn(); networkMock.setProvider.mockReturnValueOnce(true); - expect(shh.setProvider('provider', 'net')).toEqual(true); + expect(shh.setProvider('provider')).toEqual(true); - expect(networkMock.setProvider).toHaveBeenCalledWith('provider', 'net'); + expect(networkMock.setProvider).toHaveBeenCalledWith('provider'); }); it('calls setProvider and returns false', () => { networkMock.setProvider = jest.fn(); networkMock.setProvider.mockReturnValueOnce(false); - expect(shh.setProvider('provider', 'net')).toEqual(false); + expect(shh.setProvider('provider')).toEqual(false); - expect(networkMock.setProvider).toHaveBeenCalledWith('provider', 'net'); + expect(networkMock.setProvider).toHaveBeenCalledWith('provider'); }); it('sets the defaultGasPrice property', () => { diff --git a/packages/web3-utils/package-lock.json b/packages/web3-utils/package-lock.json index 31e21a0ec7c..b5e30341ec9 100644 --- a/packages/web3-utils/package-lock.json +++ b/packages/web3-utils/package-lock.json @@ -1,8 +1,6 @@ { - "name": "web3-utils", - "version": "1.0.0-beta.41", - "lockfileVersion": 1, "requires": true, + "lockfileVersion": 1, "dependencies": { "@babel/runtime": { "version": "7.3.1", @@ -25,29 +23,20 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.18.tgz", "integrity": "sha512-fh+pAqt4xRzPfqA6eh3Z2y6fyZavRIumvjhaCL753+TVkGKGhpPeyrJG2JftD0T9q4GF00KjefsQ+PQNDdWQaQ==" }, - "@types/parsimmon": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/@types/parsimmon/-/parsimmon-1.10.0.tgz", - "integrity": "sha512-bsTIJFVQv7jnvNiC42ld2pQW2KRI+pAG243L+iATvqzy3X6+NH1obz2itRKDZZ8VVhN3wjwYax/VBGCcXzgTqQ==", - "dev": true - }, "ansi-regex": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", - "dev": true + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" }, "ansi-styles": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", - "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", - "dev": true + "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=" }, "argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", - "dev": true, "requires": { "sprintf-js": "~1.0.2" } @@ -56,7 +45,6 @@ "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", "integrity": "sha1-Y/1D99weO7fONZR9uP42mj9Yx0s=", - "dev": true, "requires": { "chalk": "^1.1.3", "esutils": "^2.0.2", @@ -67,7 +55,6 @@ "version": "1.1.3", "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", - "dev": true, "requires": { "ansi-styles": "^2.2.1", "escape-string-regexp": "^1.0.2", @@ -81,8 +68,7 @@ "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, "bn.js": { "version": "4.11.8", @@ -93,7 +79,6 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -112,14 +97,12 @@ "builtin-modules": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz", - "integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=", - "dev": true + "integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=" }, "chalk": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dev": true, "requires": { "ansi-styles": "^3.2.1", "escape-string-regexp": "^1.0.5", @@ -130,7 +113,6 @@ "version": "3.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, "requires": { "color-convert": "^1.9.0" } @@ -139,7 +121,6 @@ "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, "requires": { "has-flag": "^3.0.0" } @@ -150,7 +131,6 @@ "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, "requires": { "color-name": "1.1.3" } @@ -158,26 +138,22 @@ "color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", - "dev": true + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" }, "commander": { "version": "2.19.0", "resolved": "https://registry.npmjs.org/commander/-/commander-2.19.0.tgz", - "integrity": "sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg==", - "dev": true + "integrity": "sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg==" }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "crypto-js": { "version": "3.1.9-1", "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-3.1.9-1.tgz", - "integrity": "sha1-/aGedh/Ad+Af+/3G6f38WeiAbNg=", - "dev": true + "integrity": "sha1-/aGedh/Ad+Af+/3G6f38WeiAbNg=" }, "decode-uri-component": { "version": "0.2.0", @@ -192,20 +168,10 @@ "mimic-response": "^1.0.0" } }, - "definitelytyped-header-parser": { - "version": "github:Microsoft/definitelytyped-header-parser#e0561530379dfa01324a89936b75d90b20df9bd2", - "from": "github:Microsoft/definitelytyped-header-parser#production", - "dev": true, - "requires": { - "@types/parsimmon": "^1.3.0", - "parsimmon": "^1.2.0" - } - }, "diff": { "version": "3.5.0", "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", - "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", - "dev": true + "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==" }, "dom-walk": { "version": "0.1.1", @@ -216,13 +182,21 @@ "version": "0.4.2", "resolved": "https://registry.npmjs.org/dtslint/-/dtslint-0.4.2.tgz", "integrity": "sha512-ph4GXLw3HYzlQMJOFcpCqWHuL3MxJ/344OR7wn0wlQGchQGTIVNsSUl8iKEMatpy2geNMysgA9fQa6xVhHOkTQ==", - "dev": true, "requires": { - "definitelytyped-header-parser": "github:Microsoft/definitelytyped-header-parser#e0561530379dfa01324a89936b75d90b20df9bd2", "fs-extra": "^6.0.1", "strip-json-comments": "^2.0.1", "tslint": "^5.12.0", "typescript": "^3.3.0-dev.20190126" + }, + "dependencies": { + "definitelytyped-header-parser": { + "version": "github:Microsoft/definitelytyped-header-parser#e0561530379dfa01324a89936b75d90b20df9bd2", + "from": "github:Microsoft/definitelytyped-header-parser#e0561530379dfa01324a89936b75d90b20df9bd2", + "requires": { + "@types/parsimmon": "^1.3.0", + "parsimmon": "^1.2.0" + } + } } }, "elliptic": { @@ -242,20 +216,17 @@ "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", - "dev": true + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" }, "esprima": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", - "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", - "dev": true + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==" }, "esutils": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", - "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", - "dev": true + "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=" }, "eth-lib": { "version": "0.2.8", @@ -295,7 +266,6 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-6.0.1.tgz", "integrity": "sha512-GnyIkKhhzXZUWFCaJzvyDLEEgDkPfb4/TPvJCJVuS8MWZgoSsErf++QpiAlDnKFcqhRlm+tIOcencCjyJE6ZCA==", - "dev": true, "requires": { "graceful-fs": "^4.1.2", "jsonfile": "^4.0.0", @@ -305,14 +275,12 @@ "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "dev": true + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, "glob": { "version": "7.1.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", - "dev": true, "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -334,14 +302,12 @@ "graceful-fs": { "version": "4.1.15", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz", - "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==", - "dev": true + "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==" }, "has-ansi": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", - "dev": true, "requires": { "ansi-regex": "^2.0.0" } @@ -349,8 +315,7 @@ "has-flag": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", - "dev": true + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" }, "hash.js": { "version": "1.1.7", @@ -375,7 +340,6 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dev": true, "requires": { "once": "^1.3.0", "wrappy": "1" @@ -404,14 +368,12 @@ "js-tokens": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", - "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=", - "dev": true + "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=" }, "js-yaml": { "version": "3.12.1", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.1.tgz", "integrity": "sha512-um46hB9wNOKlwkHgiuyEVAybXBjwFUV0Z/RaHJblRd9DXltue9FTYvzCr9ErQrK9Adz5MU4gHWVaNUfdmrC8qA==", - "dev": true, "requires": { "argparse": "^1.0.7", "esprima": "^4.0.0" @@ -421,7 +383,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", - "dev": true, "requires": { "graceful-fs": "^4.1.6" } @@ -458,7 +419,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dev": true, "requires": { "brace-expansion": "^1.1.7" } @@ -501,23 +461,15 @@ "trim": "0.0.1" } }, - "parsimmon": { - "version": "1.12.0", - "resolved": "https://registry.npmjs.org/parsimmon/-/parsimmon-1.12.0.tgz", - "integrity": "sha512-uC/BjuSfb4jfaWajKCp1mVncXXq+V1twbcYChbTxN3GM7fn+8XoHwUdvUz+PTaFtDSCRQxU8+Rnh+iMhAkVwdw==", - "dev": true - }, "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "dev": true + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" }, "path-parse": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", - "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", - "dev": true + "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==" }, "process": { "version": "0.5.2", @@ -548,7 +500,6 @@ "version": "1.10.0", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.10.0.tgz", "integrity": "sha512-3sUr9aq5OfSg2S9pNtPA9hL1FVEAjvfOC4leW0SNf/mpnaakz2a9femSd6LqAww2RaFctwyf1lCqnTHuF1rxDg==", - "dev": true, "requires": { "path-parse": "^1.0.6" } @@ -556,8 +507,7 @@ "semver": { "version": "5.6.0", "resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz", - "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==", - "dev": true + "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==" }, "simple-concat": { "version": "1.0.0", @@ -577,8 +527,7 @@ "sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", - "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", - "dev": true + "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=" }, "strict-uri-encode": { "version": "1.1.0", @@ -589,7 +538,6 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", - "dev": true, "requires": { "ansi-regex": "^2.0.0" } @@ -605,14 +553,12 @@ "strip-json-comments": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", - "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", - "dev": true + "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=" }, "supports-color": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", - "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", - "dev": true + "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=" }, "timed-out": { "version": "4.0.1", @@ -627,14 +573,12 @@ "tslib": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", - "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==", - "dev": true + "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==" }, "tslint": { "version": "5.12.1", "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.12.1.tgz", "integrity": "sha512-sfodBHOucFg6egff8d1BvuofoOQ/nOeYNfbp7LDlKBcLNrL3lmS5zoiDGyOMdT7YsEXAwWpTdAHwOGOc8eRZAw==", - "dev": true, "requires": { "babel-code-frame": "^6.22.0", "builtin-modules": "^1.1.1", @@ -654,7 +598,6 @@ "version": "2.29.0", "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz", "integrity": "sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==", - "dev": true, "requires": { "tslib": "^1.8.1" } @@ -662,14 +605,12 @@ "typescript": { "version": "3.3.0-dev.20190126", "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.3.0-dev.20190126.tgz", - "integrity": "sha512-wx5ZIi0Dn61N/H+TDLQIyG+DPvtk46t/lHeKmu2jwk5sW7GIPjVRPUJ5AR9ohdSkV0pEUshZolWSABz5f1pTAA==", - "dev": true + "integrity": "sha512-wx5ZIi0Dn61N/H+TDLQIyG+DPvtk46t/lHeKmu2jwk5sW7GIPjVRPUJ5AR9ohdSkV0pEUshZolWSABz5f1pTAA==" }, "universalify": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", - "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", - "dev": true + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==" }, "url-set-query": { "version": "1.0.0", diff --git a/packages/web3/src/Web3.js b/packages/web3/src/Web3.js index ba50fefe9ae..b16dcf01b43 100644 --- a/packages/web3/src/Web3.js +++ b/packages/web3/src/Web3.js @@ -35,12 +35,11 @@ import {version} from '../package.json'; export default class Web3 extends AbstractWeb3Module { /** * @param {EthereumProvider|HttpProvider|WebsocketProvider|IpcProvider|String} provider - * @param {Net} net * @param {Object} options * * @constructor */ - constructor(provider, net, options = {}) { + constructor(provider, options = {}) { super(provider, new ProvidersModuleFactory(), null, null, options); this.eth = new Eth(provider, options); @@ -224,15 +223,14 @@ export default class Web3 extends AbstractWeb3Module { * @method setProvider * * @param {Object|String} provider - * @param {Net} net * * @returns {Boolean} */ - setProvider(provider, net) { + setProvider(provider) { return ( - super.setProvider(provider, net) && - this.eth.setProvider(provider, net) && - this.shh.setProvider(provider, net) && + super.setProvider(provider) && + this.eth.setProvider(provider) && + this.shh.setProvider(provider) && this.bzz.setProvider(provider) ); } @@ -255,17 +253,17 @@ export default class Web3 extends AbstractWeb3Module { const providerResolver = new ProvidersModuleFactory().createProviderResolver(); return { - Eth: (provider, options, net) => { - return new Eth(providerResolver.resolve(provider, net), options); + Eth: (provider, options) => { + return new Eth(providerResolver.resolve(provider), options); }, - Net: (provider, options, net) => { - return new Network(providerResolver.resolve(provider, net), options); + Net: (provider, options) => { + return new Network(providerResolver.resolve(provider), options); }, - Personal: (provider, options, net) => { - return new Personal(providerResolver.resolve(provider, net), options); + Personal: (provider, options) => { + return new Personal(providerResolver.resolve(provider), options); }, - Shh: (provider, options, net) => { - return new Shh(providerResolver.resolve(provider, net), options); + Shh: (provider, options) => { + return new Shh(providerResolver.resolve(provider), options); }, Bzz: (provider) => { return new Bzz(provider); diff --git a/packages/web3/tests/src/Web3Test.js b/packages/web3/tests/src/Web3Test.js index 9867c9079dd..72e7c48103d 100644 --- a/packages/web3/tests/src/Web3Test.js +++ b/packages/web3/tests/src/Web3Test.js @@ -120,13 +120,13 @@ describe('Web3Test', () => { shhMock.setProvider = jest.fn().mockReturnValueOnce(true); bzzMock.setProvider = jest.fn().mockReturnValueOnce(true); - expect(web3.setProvider('http://localhost', 'net')).toEqual(true); + expect(web3.setProvider('http://localhost')).toEqual(true); expect(web3.currentProvider.host).toEqual('http://localhost'); - expect(ethMock.setProvider).toHaveBeenCalledWith('http://localhost', 'net'); + expect(ethMock.setProvider).toHaveBeenCalledWith('http://localhost'); - expect(shhMock.setProvider).toHaveBeenCalledWith('http://localhost', 'net'); + expect(shhMock.setProvider).toHaveBeenCalledWith('http://localhost'); expect(bzzMock.setProvider).toHaveBeenCalledWith('http://localhost'); }); @@ -134,13 +134,13 @@ describe('Web3Test', () => { it('calls the static modules property and gets the expected object', () => { const modules = Web3.modules; - const eth = new modules.Eth('http://', 'net'); + const eth = new modules.Eth('http://', {}); - const net = new modules.Net('http://', 'net'); + const net = new modules.Net('http://', {}); - const personal = new modules.Personal('http://', 'net'); + const personal = new modules.Personal('http://', {}); - const shh = new modules.Shh('http://', 'net'); + const shh = new modules.Shh('http://', {}); const bzz = new modules.Bzz('http://');