Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Types of the management modules improved #2720

Merged
merged 31 commits into from
Apr 27, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
253456b
txpool module types and documentation improved
Apr 23, 2019
6769cb6
SetEtherbaseMethod with inputAddressFormatter extended and types updated
Apr 23, 2019
1eaa23c
eth-admin module types improved
Apr 23, 2019
9060500
txpool module types updated
Apr 23, 2019
438d4ae
README files updated 'package => module'
Apr 23, 2019
38b36a7
Merge branch '1.0' into types/new-modules
nivida Apr 23, 2019
5d88dd7
txpool and debug module method names improved, types tests updated an…
Apr 23, 2019
dbe44d4
eth-debug types updated and debug documentation extended
Apr 23, 2019
e41e10c
debug documentation updated
Apr 24, 2019
6a60ae2
return values in debug documentation updated
Apr 24, 2019
8a22a56
debug types and related test updated
Apr 24, 2019
1ca0d84
txpool types test updated
Apr 24, 2019
8e30b18
methods name of the eth-debug module improved
Apr 24, 2019
cda1167
web3-eth-debug documentation updated
Apr 24, 2019
97b7b97
debug-test.ts fixed
Apr 24, 2019
22a054a
MethodFactoryTest in txpool module updated
Apr 25, 2019
c3aa3da
doc titles updated
Apr 25, 2019
e42ffab
getPeer type improved
Apr 25, 2019
4940e1a
SetEtherBaseMethodTest extended
Apr 25, 2019
b20efdb
index.rst and web3-eth-debug.rst updated
Apr 25, 2019
fa6d581
web3.rst updated
Apr 25, 2019
c51ec67
types updated in eth-debug module
Apr 25, 2019
60d8e1c
DumpBlockMethod with beforeExecution extended
Apr 25, 2019
bcb8006
missing beforeExecution methods added
Apr 25, 2019
5776a99
method tests of the new modules updated
Apr 25, 2019
5903ecd
web3-eth-debug docs updated
Apr 25, 2019
138d1e7
eth-debug documentation updated
Apr 25, 2019
c655b07
return values in debug documentation examples updated
Apr 25, 2019
cf2ff9e
Merge branch '1.0' into types/new-modules
nivida Apr 25, 2019
0003913
Merge branch '1.0' into types/new-modules
nivida Apr 26, 2019
0470903
Merge branch '1.0' into types/new-modules
nivida Apr 27, 2019
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
27 changes: 14 additions & 13 deletions docs/web3-eth-txpool.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.. include:: include_announcement.rst

==================
Web3 Txpool Module
Web3 TxPool Module
==================


Expand All @@ -13,10 +13,11 @@ The ``web3-eth-txpool`` package gives you access to several non-standard RPC met
.. code-block:: javascript

import Web3 from 'web3';
import {Txpool} from 'web3-eth-txpool';
import {TxPool} from 'web3-eth-txpool';

// "Web3.givenProvider" will be set if in an Ethereum supported browser.
const txpool = new Txpool(Web3.givenProvider || 'ws://some.local-or-remote.node:8546', null, options);
const txPool = new TxPool(Web3.givenProvider || 'ws://some.local-or-remote.node:8546', null, options);


------------------------------------------------------------------------------

Expand All @@ -34,7 +35,7 @@ content

.. code-block:: javascript

txpool.content([callback])
txPool.getContent([callback])

This API can be used to list the exact details of all the transactions currently pending for inclusion in the next block(s), as well as the ones that are being scheduled for future executions.
The RPC method used is ``txpool_content``.
Expand All @@ -51,8 +52,8 @@ Returns

``Promise<Object>`` - The list of pending as well as queued transactions.

- ``pending`` - ``string{}``: List of pending transactions with transaction details.
- ``queued`` - ``string{}``: List of queued transactions with transaction details.
- ``pending`` - ``Object``: List of pending transactions with transaction details.
- ``queued`` - ``Object``: List of queued transactions with transaction details.

- ``hash`` 32 Bytes - ``String``: Hash of the transaction.
- ``nonce`` - ``Number``: The number of transactions made by the sender prior to this one.
Expand All @@ -72,7 +73,7 @@ Example

.. code-block:: javascript

txpool.content().then(console.log);
txPool.getContent().then(console.log);
> {
pending: {
0x0216d5032f356960cd3749c31ab34eeff21b3395: {
Expand Down Expand Up @@ -148,7 +149,7 @@ inspect

.. code-block:: javascript

txpool.inspect([, callback])
txPool.getInspect([, callback])

The property can be queried to list a textual summary of all the transactions currently pending for inclusion in the next block(s), as well as the ones that are being scheduled for future executions.
The RPC method used is ``txpool_inspect``.
Expand All @@ -168,8 +169,8 @@ Returns

``Promise<Object>`` - The List of pending and queued transactions summary.

- ``pending`` - ``string{}``: List of pending transactions with transaction details.
- ``queued`` - ``string{}``: List of queued transactions with transaction details.
- ``pending`` - ``Object``: List of pending transactions with transaction details.
- ``queued`` - ``Object``: List of queued transactions with transaction details.

-------
Example
Expand All @@ -178,7 +179,7 @@ Example

.. code-block:: javascript

txpool.inspect().then(console.log);
txPool.getInspect().then(console.log);
> {
pending: {
0x26588a9301b0428d95e6fc3a5024fce8bec12d51: {
Expand Down Expand Up @@ -238,7 +239,7 @@ status

.. code-block:: javascript

txpool.status([, callback])
txPool.getStatus([, callback])

This will provide the number of transactions currently pending for inclusion in the next block(s), as well as the ones that are being scheduled for future executions.
The RPC method used is ``txpool_status``.
Expand Down Expand Up @@ -268,7 +269,7 @@ Example

.. code-block:: javascript

txpool.status().then(console.log);
txPool.getStatus().then(console.log);
> {
pending: 10,
queued: 7
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-core-method/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export VmoduleMethod from './methods/debug/VmoduleMethod';
export WriteBlockProfileMethod from './methods/debug/WriteBlockProfileMethod';
export WriteMemProfileMethod from './methods/debug/WriteMemProfileMethod';

// Txpool
// TxPool
export ContentMethod from './methods/txpool/ContentMethod';
export InspectMethod from './methods/txpool/InspectMethod';
export StatusMethod from './methods/txpool/StatusMethod';
Expand Down
11 changes: 11 additions & 0 deletions packages/web3-core-method/src/methods/miner/SetEtherBaseMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,15 @@ export default class SetEtherBaseMethod extends AbstractMethod {
constructor(utils, formatters, moduleInstance) {
super('miner_setEtherbase', 1, utils, formatters, moduleInstance);
}

/**
* This method will be executed before the RPC request.
*
* @method beforeExecution
*
* @param {AbstractWeb3Module} moduleInstance - The package where the method is called from for example Eth.
*/
beforeExecution(moduleInstance) {
this.parameters[0] = this.formatters.inputAddressFormatter(this.parameters[0]);
}
}
44 changes: 35 additions & 9 deletions packages/web3-core/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,30 @@ export interface Log {
}

export interface Content {
pending: any;
queued: any;
pending: TxPoolContent;
queued: TxPoolContent;
}

export interface TxPoolContent {
[address: string]: {
[nonce: number]: Array<Transaction>
}
}

export interface Inspect {
pending: TxPoolInspect;
queued: TxPoolInspect;
}

export interface TxPoolInspect {
[address: string]: {
[nonce: number]: Array<string>;
};
}

export interface TxPoolStatus {
pending: number;
queued: number;
}

export interface NodeInfo {
Expand All @@ -215,12 +237,16 @@ export interface NodeInfo {
discovery: string | number;
listener: string | number;
};
protocols: {
eth: {
difficulty: string | number;
genesis: string;
head: string;
network: string | number;
};
protocols: any // Any because it's not documented what each protocol (eth, shh etc.) is defining here
}

export interface PeerInfo {
caps: Array<string>;
id: string;
name: string;
network: {
localAddress: string;
remoteAddress: string;
};
protocols: any; // Any because it's not documented what each protocol (eth, shh etc.) is defining here
}
3 changes: 1 addition & 2 deletions packages/web3-eth-admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
"web3-core-method": "1.0.0-beta.52",
"web3-net": "1.0.0-beta.52",
"web3-providers": "1.0.0-beta.52",
"web3-utils": "1.0.0-beta.52",
"web3-eth-accounts": "1.0.0-beta.52"
"web3-utils": "1.0.0-beta.52"
},
"devDependencies": {
"definitelytyped-header-parser": "^1.0.1",
Expand Down
7 changes: 3 additions & 4 deletions packages/web3-eth-admin/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
*/

import {provider} from 'web3-providers';
import {AbstractWeb3Module, Web3ModuleOptions, NodeInfo} from 'web3-core';
import {Accounts} from 'web3-eth-accounts';
import {AbstractWeb3Module, Web3ModuleOptions, NodeInfo, PeerInfo} from 'web3-core';
import * as net from 'net';

export class Admin extends AbstractWeb3Module {
constructor(provider: provider, net?: net.Socket|null, options?: Web3ModuleOptions, accounts?: Accounts|null);
constructor(provider: provider, net?: net.Socket|null, options?: Web3ModuleOptions);

addPeer(
url: string,
Expand All @@ -40,7 +39,7 @@ export class Admin extends AbstractWeb3Module {

getPeers(
callback?: (error: Error, result: any[]) => void
): Promise<any[]>;
): Promise<PeerInfo[]>;

setSolc(
path: string,
Expand Down
3 changes: 1 addition & 2 deletions packages/web3-eth-miner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
"web3-core-method": "1.0.0-beta.52",
"web3-net": "1.0.0-beta.52",
"web3-providers": "1.0.0-beta.52",
"web3-utils": "1.0.0-beta.52",
"web3-eth-accounts": "1.0.0-beta.52"
"web3-utils": "1.0.0-beta.52"
},
"devDependencies": {
"definitelytyped-header-parser": "^1.0.1",
Expand Down
3 changes: 1 addition & 2 deletions packages/web3-eth-miner/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@

import {provider} from 'web3-providers';
import {AbstractWeb3Module, Web3ModuleOptions} from 'web3-core';
import {Accounts} from 'web3-eth-accounts';
import * as net from 'net';

export class Miner extends AbstractWeb3Module {
constructor(provider: provider, net?: net.Socket|null, options?: Web3ModuleOptions, accounts?: Accounts|null);
constructor(provider: provider, net?: net.Socket|null, options?: Web3ModuleOptions);

setEtherbase(
address: string,
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-eth-txpool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This is a sub package of [web3.js][repo]

This is the txpool package. This is an independent package. If you want to use this package, you need to import this in your project.
This is the TxPool module. This is an independent module. If you want to use this module, you need to import it in your project.
Please read the [documentation][docs] for more.

## Installation
Expand All @@ -16,7 +16,7 @@ npm install web3-eth-txpool
```js
import {TxPool} from 'web3-eth-txpool';

const txpool = new TxPool(
const txPool = new TxPool(
'http://127.0.0.1:8546',
null,
options
Expand Down
3 changes: 1 addition & 2 deletions packages/web3-eth-txpool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
"web3-core-method": "1.0.0-beta.52",
"web3-net": "1.0.0-beta.52",
"web3-providers": "1.0.0-beta.52",
"web3-utils": "1.0.0-beta.52",
"web3-eth-accounts": "1.0.0-beta.52"
"web3-utils": "1.0.0-beta.52"
},
"devDependencies": {
"definitelytyped-header-parser": "^1.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-txpool/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pkg from './package.json';
import rollupConfig from '../../rollup.config';

export default rollupConfig('Web3EthAdmin', pkg.name);
export default rollupConfig('Web3EthTxPool', pkg.name);
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file Txpool.js
* @file TxPool.js
* @author Prince Sinha <[email protected]>
* @date 2019
*/

import {AbstractWeb3Module} from 'web3-core';

export default class Txpool extends AbstractWeb3Module {
export default class TxPool extends AbstractWeb3Module {
/**
* @param {Web3EthereumProvider|HttpProvider|WebsocketProvider|IpcProvider|String} provider
* @param {MethodFactory} methodFactory
Expand Down
12 changes: 6 additions & 6 deletions packages/web3-eth-txpool/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ import * as Utils from 'web3-utils';
import {formatters} from 'web3-core-helpers';
import {ProviderResolver} from 'web3-providers';
import MethodFactory from './factories/MethodFactory';
import TxpoolModule from './Txpool.js';
import TxPoolModule from './TxPool.js';

/**
* Returns the Txpool object
* Returns the TxPool object
*
* @method Txpool
* @method TxPool
*
* @param {Web3EthereumProvider|HttpProvider|WebsocketProvider|IpcProvider|String} provider
* @param {Net.Socket} net
* @param {Object} options
*
* @returns {Txpool}
* @returns {TxPool}
*/
export function Txpool(provider, net = null, options = {}) {
export function TxPool(provider, net = null, options = {}) {
const resolvedProvider = new ProviderResolver().resolve(provider, net);

return new TxpoolModule(
return new TxPoolModule(
resolvedProvider,
new MethodFactory(Utils, formatters),
new Network(resolvedProvider, null, options),
Expand Down
6 changes: 3 additions & 3 deletions packages/web3-eth-txpool/tests/src/TxpoolTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import {formatters} from 'web3-core-helpers';
import {Network} from 'web3-net';
import {AbstractWeb3Module} from 'web3-core';
import MethodFactory from '../../src/factories/MethodFactory';
import Txpool from '../../src/Txpool';
import TxPool from '../../src/TxPool';

// Mocks
jest.mock('web3-utils');
jest.mock('web3-core-helpers');
jest.mock('web3-net');

/**
* Txpool test
* TxPool test
*/
describe('TxpoolTest', () => {
let txpool, providerMock, methodFactory, networkMock;
Expand All @@ -23,7 +23,7 @@ describe('TxpoolTest', () => {
new Network();
networkMock = Network.mock.instances[0];

txpool = new Txpool(providerMock, methodFactory, networkMock, Utils, formatters, {}, {});
txpool = new TxPool(providerMock, methodFactory, networkMock, Utils, formatters, {}, {});
});

it('constructor check', () => {
Expand Down
11 changes: 5 additions & 6 deletions packages/web3-eth-txpool/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@
*/

import {provider} from 'web3-providers';
import {AbstractWeb3Module, Web3ModuleOptions, Content} from 'web3-core';
import {Accounts} from 'web3-eth-accounts';
import {AbstractWeb3Module, Content, Inspect, Web3ModuleOptions} from 'web3-core';
import * as net from 'net';

export class Txpool extends AbstractWeb3Module {
constructor(provider: provider, net?: net.Socket|null, options?: Web3ModuleOptions, accounts?: Accounts|null);
constructor(provider: provider, net?: net.Socket | null, options?: Web3ModuleOptions);

content(callback?: (error: Error, result: Content) => void): Promise<Content>;
getContent(callback?: (error: Error, result: Content) => void): Promise<Content>;

inspect(callback?: (error: Error, result: Content) => void): Promise<Content>;
getInspect(callback?: (error: Error, result: Inspect) => void): Promise<Content>;

status(callback?: (error: Error, result: Content) => void): Promise<Content>;
getStatus(callback?: (error: Error, result: Content) => void): Promise<Content>;
}