made net a separate package again

This commit is contained in:
Fabian Vogelsteller 2017-03-10 11:02:46 +01:00
parent 15e4643bfb
commit 605a8754d6
No known key found for this signature in database
GPG Key ID: E51EADA77F1A4124
11 changed files with 181 additions and 98 deletions

View File

@ -81,6 +81,36 @@ Example
------------------------------------------------------------------------------
currentProvider
=====================
.. code-block:: javascript
web3.currentProvider
web3.eth.currentProvider
web3.shh.currentProvider
web3.bzz.currentProvider
...
Will return the current provider, otherwise ``null``.
-------
Returns
-------
``Object``: The current provider set or ``null``;
-------
Example
-------
.. code-block:: javascript
if(!web3.currentProvider)
web3.setProvider(new web3.providers.HttpProvider("http://localhost:8545"));
------------------------------------------------------------------------------
BatchRequest
=====================

View File

@ -1,3 +1,5 @@
.. _eth:
========
web3.eth
========

View File

@ -1,3 +1,5 @@
.. _shh:
========
web3.shh
========

View File

@ -1,3 +1,5 @@
.. _utils:
========
web3.utils
========

View File

@ -11,11 +11,13 @@ The web3.js object is a umbrella package to house all ethereum related modules.
// "Web3.providers.givenProvider" will be set if in an Ethereum supported browser.
var web3 = new Web3(Web3.givenProvider || new Web3.providers.WebsocketProvider('ws://some.local-or-remote.node:8546'));
// -> web3.eth
// -> web3.personal
// -> web3.shh
// -> web3.bzz
// -> web3.utils
> web3.eth
> web3.personal
> web3.shh
> web3.bzz
> web3.utils
------------------------------------------------------------------------------
@ -44,23 +46,36 @@ Example
web3.version;
> "1.0.0"
------------------------------------------------------------------------------
providers
.. include:: package-core.rst
------------------------------------------------------------------------------
modules
=====================
.. code-block:: javascript
web3.providers
web3.modules
Will return an object with different available providers to use when instantiating ``Web3``
Will return an object with the classes of all major sub modules, to be able to instantiate them manually.
-------
Returns
-------
``Object``: A list of providers.
``Object``: A list of modules:
- ``Eth`` - ``Function``: the Eth module for interacting with the ethereum network see :ref:`web3.eth <eth>` for more.
- ``Net`` - ``Function``: the Net module for interacting with network properties see :ref:`web3.eth.net <eth-net>` for more.
- ``Personal`` - ``Function``: the Personal module for interacting with the ethereum accounts see :ref:`web3.personal <personal>` for more.
- ``Shh`` - ``Function``: the Shh module for interacting with the whisper protocol see :ref:`web3.shh <shh>` for more.
- ``Bzz`` - ``Function``: the Bzz module for interacting with the swarm network see :ref:`web3.bzz <bzz>` for more.
-------
Example
@ -68,69 +83,13 @@ Example
.. code-block:: javascript
web3.providers
web3.modules
> {
HttpProvider: HttpProvider,
IpcProvider: IpcProvider,
WebsocketProvider: WebsocketProvider
Eth: Eth function(provider),
Net: Net function(provider),
Personal: Personal function(provider),
Shh: Shh function(provider),
Bzz: Bzz function(provider),
}
------------------------------------------------------------------------------
setProvider
=====================
.. code-block:: javascript
web3.setProvider(myProvider)
When called changes the current provider for all modules.
----------
Parameters
----------
``Object`` - **myProvider**: a valid provider with at least ``send``, ``on`` function
-------
Returns
-------
``undefined``
-------
Example
-------
.. code-block:: javascript
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));
------------------------------------------------------------------------------
currentProvider
=====================
.. code-block:: javascript
web3.currentProvider
Will return the current provider, otherwise ``null``.
-------
Returns
-------
``Object``: The current provider set or ``null``;
-------
Example
-------
.. code-block:: javascript
if(!web3.currentProvider)
web3.setProvider(new web3.providers.HttpProvider("http://localhost:8545"));
------------------------------------------------------------------------------

View File

@ -0,0 +1,13 @@
{
"name": "web3-eth-net",
"version": "1.0.0",
"description": "Web3 module to interact with the Ethereum nodes networking properties.",
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-eth-net",
"license": "LGPL-3.0",
"main": "src/index.js",
"dependencies": {
"web3-core": "^1.0.0",
"web3-core-method": "^1.0.0",
"web3-utils": "^1.0.0"
}
}

View File

@ -0,0 +1,80 @@
/*
This file is part of web3.js.
web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file index.js
* @author Fabian Vogelsteller <fabian@ethereum.org>
* @date 2017
*/
"use strict";
var core = require('web3-core');
var Method = require('web3-core-method');
var utils = require('web3-utils');
var Net = function () {
var _this = this;
// sets _requestmanager
core.packageInit(this, arguments);
methods().forEach(function(method) {
method.attachToObject(_this);
method.setRequestManager(_this._requestManager);
});
};
core.addProviders(Net);
var methods = function () {
var getId = new Method({
name: 'getId',
call: 'net_version',
params: 0,
outputFormatter: utils.toNumber
});
var isListening = new Method({
name: 'isListening',
call: 'net_listening',
params: 0
});
var getPeerCount = new Method({
name: 'getPeerCount',
call: 'net_peerCount',
params: 0,
outputFormatter: utils.toNumber
});
return [
getId,
isListening,
getPeerCount
];
};
module.exports = Net;

View File

@ -10,6 +10,7 @@
"web3-core-helpers": "^1.0.0",
"web3-core-subscriptions": "^1.0.0",
"web3-core-method": "^1.0.0",
"web3-eth-net": "^1.0.0",
"web3-eth-iban": "^1.0.0",
"web3-eth-abi": "^1.0.0",
"web3-eth-contract": "^1.0.0",

View File

@ -28,10 +28,12 @@ var helpers = require('web3-core-helpers');
var Subscriptions = require('web3-core-subscriptions').subscriptions;
var utils = require('web3-utils');
var Method = require('web3-core-method');
var Net = require('web3-eth-net');
var abi = require('web3-eth-abi');
var Contract = require('web3-eth-contract');
var Iban = require('web3-eth-iban');
var getNetworkType = require('./getNetworkType.js');
var formatters = helpers.formatters;
@ -71,6 +73,8 @@ var Eth = function Eth() {
method.setRequestManager(_this._requestManager, _this); // second param means is Eth (necessary for promiEvent)
});
this.net = new Net(this.currentProvider);
// add contract
this.Contract = Contract;
this.Contract.prototype._eth = this;
@ -114,27 +118,6 @@ Object.defineProperty(Eth.prototype, 'defaultAccount', {
var methods = function () {
var getId = new Method({
name: 'net.getId',
call: 'net_version',
params: 0,
outputFormatter: utils.toNumber
});
var isListening = new Method({
name: 'net.isListening',
call: 'net_listening',
params: 0
});
var getPeerCount = new Method({
name: 'net.getPeerCount',
call: 'net_peerCount',
params: 0,
outputFormatter: utils.toNumber
});
var getVersion = new Method({
name: 'getProtocolVersion',
@ -439,9 +422,6 @@ var methods = function () {
return [
getId,
isListening,
getPeerCount,
getVersion,
getCoinbase,
getMining,

View File

@ -559,8 +559,7 @@ module.exports = {
// extractDisplayName: extractDisplayName,
// extractTypeName: extractTypeName,
_: _,
padLeft: padLeft,
padRight: padRight,
sha3: sha3,
toAddress: toAddress,
isAddress: isAddress,
checkAddressChecksum: checkAddressChecksum,
@ -580,6 +579,7 @@ module.exports = {
fromWei: fromWei,
isBN: isBN,
isBigNumber: isBigNumber,
sha3: sha3
padLeft: padLeft,
padRight: padRight
};

View File

@ -28,9 +28,11 @@
"use strict";
var version = require('../lerna.json');
var core = require('../packages/web3-core');
var Eth = require('../packages/web3-eth');
var Net = require('../packages/web3-eth-net');
var Personal = require('../packages/web3-personal');
var Shh = require('../packages/web3-shh');
var Bzz = require('../packages/web3-bzz');
@ -47,6 +49,8 @@ var providers = {
var Web3 = function Web3() {
this.version = version.version;
// sets _requestmanager etc
core.packageInit(this, arguments);
@ -71,12 +75,22 @@ var Web3 = function Web3() {
};
};
Web3.prototype.version = version.version;
Web3.providers = providers;
core.addProviders(Web3);
Web3.modules = {
Eth: Eth,
Net: Net,
Personal: Personal,
Shh: Shh,
Bzz: Bzz
};
module.exports = Web3;