From 7abc4e57e9efb681707b663051b733c66b68be62 Mon Sep 17 00:00:00 2001 From: Samuel Furter Date: Wed, 8 May 2019 14:58:10 +0200 Subject: [PATCH 1/5] module api documentation improved --- docs/web3-core.rst | 14 +++++++++++ docs/web3-module.rst | 59 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/docs/web3-core.rst b/docs/web3-core.rst index 75f54ba42e0..b31994982e9 100644 --- a/docs/web3-core.rst +++ b/docs/web3-core.rst @@ -22,6 +22,20 @@ The ``AbstractWeb3Module`` does have the following constructor parameters: - ``methodFactory`` - ``AbstractMethodFactory`` The :ref:`AbstractMethodFactory ` will be used in the module proxy for the JSON-RPC method calls. (optional) - ``net`` - ``net.Socket`` The ``net.Socket`` object of the NodeJS net module. (optional) +------- +Example +------- + +.. code-block:: javascript + import {AbstractWeb3Module} from 'web3-core'; + import MyMethodFactory from '../factory/MyMethodFactory'; + + class Example extends AbstractWeb3Module { + constructor(provider, net, methodFactory, options) { + super(provider, net, methodFactory, options; + } + } + Interface of the ``AbstractWeb3Module`` class: diff --git a/docs/web3-module.rst b/docs/web3-module.rst index 1e78a4c5608..5011b3643ed 100644 --- a/docs/web3-module.rst +++ b/docs/web3-module.rst @@ -20,3 +20,62 @@ These are the core modules which are providing all the classes for the Web3 Modu - :ref:`web3-core-subscriptions ` - :ref:`Contract ` +------- +Example +------- + +.. code-block:: javascript + import * as Utils from 'web3-utils'; + import {formatters} from 'web3-core-formatters'; + import {AbstractWeb3Module} from 'web3-core'; + import {AbstractMethodFactory, GetBlockByNumberMethod, AbstractMethod} from 'web3-core-method'; + + class MethodFactory extends AbstractMethodFactory { + /** + * @param {Utils} utils + * @param {Object} formatters + * + * @constructor + */ + constructor(utils, formatters) { + super(utils, formatters); + + this.methods = { + getBlockByNumber: GetBlockByNumberMethod + }; + } + } + + class Example extends AbstractWeb3Module { + /** + * @param {AbstractSocketProvider|HttpProvider|String|EthereumProvider} provider + * @param {Web3ModuleOptions} options + * @param {Net.Socket} nodeNet + * + * @constructor + */ + constructor(provider, net, options) { + super(provider, net, new MethodFactory(Utils, formatters), options; + } + + sign() { + const method = new AbstractMethod('eth_sign', 2, utils, formatters, this); + method.setArguments(arguments) + + return method.execute(); + } + } + + const example = new Example(provider, net, options); + + example.sign('0x0', 'message').then(console.log); + // > "response" + + example.sign('0x0', 'message', (error, response) => { + console.log(response); + }; + // > "response" + + const block = example.getBlockByNumber(1).then(console.log); + // > {} + From ab92ce0d0f89659c4031375e3cbce8087a9d85fb Mon Sep 17 00:00:00 2001 From: Samuel Furter Date: Wed, 8 May 2019 15:01:07 +0200 Subject: [PATCH 2/5] import removed in web3-core example --- docs/web3-core.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/web3-core.rst b/docs/web3-core.rst index b31994982e9..8592b9e411b 100644 --- a/docs/web3-core.rst +++ b/docs/web3-core.rst @@ -28,7 +28,6 @@ Example .. code-block:: javascript import {AbstractWeb3Module} from 'web3-core'; - import MyMethodFactory from '../factory/MyMethodFactory'; class Example extends AbstractWeb3Module { constructor(provider, net, methodFactory, options) { From 846b489bde4c414b13b17d6bda1a800d20e56ceb Mon Sep 17 00:00:00 2001 From: Samuel Furter Date: Wed, 8 May 2019 15:07:36 +0200 Subject: [PATCH 3/5] subscription added to web3-module documentation --- docs/web3-module.rst | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/web3-module.rst b/docs/web3-module.rst index 5011b3643ed..a5289700ef7 100644 --- a/docs/web3-module.rst +++ b/docs/web3-module.rst @@ -25,6 +25,7 @@ Example ------- .. code-block:: javascript + import * as Utils from 'web3-utils'; import {formatters} from 'web3-core-formatters'; import {AbstractWeb3Module} from 'web3-core'; @@ -48,7 +49,7 @@ Example class Example extends AbstractWeb3Module { /** - * @param {AbstractSocketProvider|HttpProvider|String|EthereumProvider} provider + * @param {AbstractSocketProvider|HttpProvider|CustomProvider|String} provider * @param {Web3ModuleOptions} options * @param {Net.Socket} nodeNet * @@ -64,6 +65,10 @@ Example return method.execute(); } + + logs(options) { + return new LogSubscription(options, Utils, formatters, this, new GetPastLogsMethod(Utils, formatters, this)); + } } const example = new Example(provider, net, options); @@ -79,3 +84,6 @@ Example const block = example.getBlockByNumber(1).then(console.log); // > {} + example.logs(options).subscribe(console.log); + > {} + From 801abcbc1a365dc037aad44a82959b3eeea108ef Mon Sep 17 00:00:00 2001 From: Samuel Furter Date: Wed, 8 May 2019 15:45:56 +0200 Subject: [PATCH 4/5] func doc added to web3-core.rst exexamplee --- docs/web3-core.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/web3-core.rst b/docs/web3-core.rst index 8592b9e411b..bbb6d7d9baf 100644 --- a/docs/web3-core.rst +++ b/docs/web3-core.rst @@ -27,9 +27,18 @@ Example ------- .. code-block:: javascript + import {AbstractWeb3Module} from 'web3-core'; class Example extends AbstractWeb3Module { + /** + * @param {AbstractSocketProvider|HttpProvider|CustomProvider|String} provider + * @param {AbstractMethodFactory} methodFactory + * @param {Web3ModuleOptions} options + * @param {Net.Socket} nodeNet + * + * @constructor + */ constructor(provider, net, methodFactory, options) { super(provider, net, methodFactory, options; } From 57f7542a6e45f3dd5d2fa7e191d77a4cca881aa8 Mon Sep 17 00:00:00 2001 From: Samuel Furter Date: Wed, 8 May 2019 20:13:46 +0200 Subject: [PATCH 5/5] web3-module example updated --- docs/web3-module.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/web3-module.rst b/docs/web3-module.rst index a5289700ef7..c19e8bac296 100644 --- a/docs/web3-module.rst +++ b/docs/web3-module.rst @@ -67,7 +67,13 @@ Example } logs(options) { - return new LogSubscription(options, Utils, formatters, this, new GetPastLogsMethod(Utils, formatters, this)); + return new LogSubscription( + options, + Utils, + formatters, + this, + new GetPastLogsMethod(Utils, formatters, this) + ); } }