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

Provider related improvements #3190

Merged
merged 184 commits into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
184 commits
Select commit Hold shift + click to select a range
1a05194
requestManager handling and add of 'data' listener improved
nivida Oct 24, 2019
4f856c8
Merge branch '1.x' into issue/1648
nivida Oct 30, 2019
9c028ad
packageInit, setProvider and related listener issue fixed with adding…
nivida Oct 30, 2019
0a978d8
periodically occuring 'connection not open on send()' fixed
nivida Oct 31, 2019
57be867
Attach ws event listeners using EventTarget API
gabmontes Sep 5, 2018
7c8451c
Add `once` to the WS provider interface
gabmontes Sep 5, 2018
53a7d36
Merge logic for resubscription
gabmontes Sep 5, 2018
666f087
Clear subscription id before resubscribing
gabmontes Sep 5, 2018
9c366e4
Avoid reentry when removing subscriptions
gabmontes Sep 5, 2018
f35fc88
Broadcast provider error to subscribers
gabmontes Sep 5, 2018
4af2f2b
Add support for WebSocket reconnections
gabmontes Sep 6, 2018
fbba26e
Try to reconnect on timeout too
gabmontes Sep 6, 2018
5f5c2b8
Remove WS provider once listener on next tick
gabmontes Oct 7, 2019
6305262
Ensure resubscription is done on silent reconnects
gabmontes Oct 7, 2019
ed96084
Fix indentation
gabmontes Oct 22, 2019
d31f7e2
Add subscribe tests / failing reconnection test
cgewecke Nov 6, 2019
6b639e5
dynamic parameter detection is required
nivida Nov 6, 2019
4e4d341
already out-commented but not removed line removed in Registry.js
nivida Nov 6, 2019
d624492
Merge branch '1.x' into issue/1648
nivida Nov 6, 2019
8715096
Update packages/web3-providers-ws/src/index.js
nivida Nov 7, 2019
3cc23f5
subscriptions are now hold in a Map in the RequestManager, and resubs…
nivida Nov 7, 2019
b0c22c3
Merge branch 'issue/1648' into provider-related-improvements
nivida Nov 8, 2019
62fc1b5
Merge branch 'issue/3092' into provider-related-improvements
nivida Nov 8, 2019
3c77b99
Merge branch 'resubscribing-improved' into provider-related-improvements
nivida Nov 8, 2019
d2de9fd
subscriptions handling updated in RequestManager
nivida Nov 8, 2019
5c4b2da
websocketprovider.once() updated
nivida Nov 8, 2019
a62c543
missing _this added
nivida Nov 8, 2019
4230f78
websocketprovider.send() does use the internal once() method now
nivida Nov 8, 2019
155adc5
no longer requried _reconnectIntervalId property removed in subscript…
nivida Nov 8, 2019
f37a305
requestQueue added to WebsocketProvider
nivida Nov 8, 2019
68a5a33
explicit delete will now be used on connect to remove the request ite…
nivida Nov 8, 2019
e5eacfb
close and connect handler for requestQueue extended with stoping of r…
nivida Nov 8, 2019
b223a20
missing removeListener added to close requestQueue handler
nivida Nov 8, 2019
e991785
removeListener moved to bottom of both requestQueue handlers and erro…
nivida Nov 8, 2019
7b6c48b
websocket-reconnector removed and reconnecting as first draft impleme…
nivida Nov 8, 2019
08d83b0
no longer required private methods removed
nivida Nov 8, 2019
0b8bedb
missing funcDocs added in WebsocketProvider
nivida Nov 8, 2019
e7c41be
missing object properties added to WebsocketProvider and eventemitter…
nivida Nov 8, 2019
de090b4
websocketprovider.onMessage() updated for normal requests
nivida Nov 8, 2019
44688ef
websocketprovider.onMessage() updated for subscriptions
nivida Nov 8, 2019
909b6c3
not required else and var remove in websocketprovider.onMessage() and…
nivida Nov 8, 2019
1c9f306
maxReconnectAttempts options added to WebsocketProvider
nivida Nov 8, 2019
091851a
websocketprovider.reconnect() reconnect attempts condition updated
nivida Nov 8, 2019
e3be52f
maxReconnectAttempts error handling updated
nivida Nov 8, 2019
4161ec5
reconnecting property will now get set to false if the maximum of att…
nivida Nov 8, 2019
e182974
WS check removed because WS does exists in any case
nivida Nov 8, 2019
21ae48f
removeAllSocketListeners added to WebsocketProvider
nivida Nov 8, 2019
30da469
funcDoc updated and wrongly defined removeAllSocketListeners deleted
nivida Nov 8, 2019
22c91d1
addSocketListeners and removeAllSocketListeners with underscore as pr…
nivida Nov 8, 2019
879fbca
addDefaultEvents function removed from WebsocketProvider
nivida Nov 8, 2019
d982f9f
funcDoc updated for _addSocketListeners
nivida Nov 8, 2019
1fbea04
parse-url.js -> helpers.js renamed and btoa export added
nivida Nov 8, 2019
99b5da9
_removeAllSocketListeners -> _removeSocketListeners renamed in Websoc…
nivida Nov 8, 2019
aaf4a30
state object property 'reconnecting' removed and event 'reconnect' added
nivida Nov 8, 2019
c75da8b
timeout removed in _parseResponse because the timeout in send will co…
nivida Nov 8, 2019
1fdb56f
removed web3-core-helpers package because it's not in usage anymore
nivida Nov 8, 2019
f0c57a3
not required var removed in reconnect and constructor typo fixed
nivida Nov 8, 2019
56376f7
underscore dependency removed because it's no longer in usage
nivida Nov 8, 2019
16efbf2
isArray check fixed in Websocketprovider
nivida Nov 8, 2019
dc88690
onError updated and send simplified in WebsocketProvider
nivida Nov 8, 2019
d796635
error msg updated in onClose listener
nivida Nov 8, 2019
7b3b122
close listener added to RequestManager
nivida Nov 8, 2019
9d2f65b
timeout handling moved back to _parseResponse to have it applied on s…
nivida Nov 8, 2019
5931584
timeout event name property added and applied
nivida Nov 8, 2019
b344092
scope issue fixed in WebsocketProvider
nivida Nov 8, 2019
581cdbc
ddefault value '1000' for the optional and newly added parameter code…
nivida Nov 8, 2019
1f0689d
timeout handling changed in WS provider to save a event listener in t…
nivida Nov 8, 2019
a1e5762
recconectAttempts reset added, TODOs added, and order updated in the …
nivida Nov 8, 2019
0c1a32c
WebsocketProvider reconnecting options extended
nivida Nov 8, 2019
9ee548f
WebsocketProvider timeout handling does now clean the requestQueue if…
nivida Nov 8, 2019
52385b4
reconnectOptions fixed in WebsocketProvider
nivida Nov 8, 2019
4a30c79
'connect' listener updated in RequestManager, func doc improved, and …
nivida Nov 10, 2019
297ffc9
not required if removed in request-manager
nivida Nov 10, 2019
8e8c6b3
setting of reconnectOptions in WebsocketProvider updated
nivida Nov 10, 2019
2be288f
inheritance and typo fixed in WebsocketProvider
nivida Nov 11, 2019
11989cd
removeSubscription fixed in RequestManager
nivida Nov 11, 2019
569f481
test/contract.js updated because the RequestManager is now using a Ma…
nivida Nov 11, 2019
9043ab3
version updated on severall places 1.2.1 -> 1.2.2 and package-lock if…
nivida Nov 11, 2019
bd2857a
subscription error handling updated
nivida Nov 11, 2019
5559969
event handling and send method updated in WebsocketProvider
nivida Nov 11, 2019
c552e98
gave the listeners a name in the request-manager to improve the DX du…
nivida Nov 11, 2019
8f0a2cf
'error is not defined' fixed in subscription.js
nivida Nov 11, 2019
eb27a23
reconnecting test updated and disconnect method simplified in Websock…
nivida Nov 11, 2019
3c0904d
eth.subscribe.ganache test updated and the error handling of Websocke…
nivida Nov 18, 2019
1d05111
call of removeListener added to error and close listener in send meth…
nivida Nov 18, 2019
1e6efaa
test case added to eth.subscribe.ganache and error handling in the cl…
nivida Nov 18, 2019
453c742
test case for the connected listener added to eth.subscribe.ganache.js
nivida Nov 18, 2019
318c345
RequestManager inheritance fixed for web3-shh package
nivida Nov 18, 2019
6df7456
provider handling for contracts updated. This was required because of…
nivida Nov 18, 2019
2958284
clearSubscriptions fixed in web3-eth-contract
nivida Nov 18, 2019
2951da7
error and close event handling improved in WebsocketProvider.send wit…
nivida Nov 18, 2019
c5b0471
WebsocketProvider.send simplified
nivida Nov 18, 2019
5727104
id handling and deletion of request item from queue updated in Websoc…
nivida Nov 18, 2019
349076d
missing requestQueue.has condition added to WebsocketProvider.send
nivida Nov 18, 2019
84ec342
error handling updated the errorQueue will now be used instead of usi…
nivida Nov 18, 2019
bf61074
Map objects changed to Set objects for both queue in the WebsocketPro…
nivida Nov 18, 2019
9160389
additional timeout wrapped in if because this case only happens if th…
nivida Nov 18, 2019
5b405f4
errorQueue renamed to responseQueue, send method simplified, and not …
nivida Nov 18, 2019
a82f899
order of removing and adding of a request from the response or reques…
nivida Nov 19, 2019
f90842e
Merge branch '1.x' into provider-related-improvements
nivida Dec 2, 2019
07565a4
exit option added to mocha for now until we are able to kill the gana…
nivida Dec 3, 2019
a27af13
Merge branch '1.x' into provider-related-improvements
nivida Dec 3, 2019
ebf9239
later added options added to README.md of the web3-providers-ws package
nivida Dec 3, 2019
1456620
not required waitMs function removed from test.utils
nivida Dec 3, 2019
ef63cf7
type definitions for providers corrected and extended
nivida Dec 3, 2019
d9b080f
code-style improved and ERR_CONNECTION_REFUSED case added in WS provider
nivida Dec 3, 2019
127b06c
code-style changes reverted
nivida Dec 4, 2019
f5a1217
Merge branch '1.x' into provider-related-improvements
nivida Dec 4, 2019
81474d9
Method object removed from changeset
nivida Dec 4, 2019
52e5c5c
Merge branch 'provider-related-improvements' of github.com:ethereum/w…
nivida Dec 4, 2019
a46dbcd
clean up of the requestQueue in the WebsocketProvider fixed on timeout
nivida Dec 16, 2019
0168764
Add tests for core-subscriptions edge cases
cgewecke Dec 17, 2019
6cf61ed
Remove console.log in test
cgewecke Dec 17, 2019
4c6bab9
Use done
cgewecke Dec 17, 2019
21d854c
Rewrite resubscribe test per review comment
cgewecke Dec 17, 2019
1cb8b80
Increase resubscribes timeout
cgewecke Dec 17, 2019
7790a26
Remove .only
cgewecke Dec 17, 2019
ac880f6
Add resubscribe to existing subscription case
cgewecke Dec 17, 2019
fb1d422
provider types moved back to web3-core-helpers package to not break e…
nivida Dec 18, 2019
80ea81c
the response and request queue does now get cleaned up if WebsocketPr…
nivida Dec 18, 2019
d21d746
Run initially emitted errors in a zero-length timeout (plus tests)
cgewecke Dec 19, 2019
9038a7a
Wrap more immediate errors in 0 length timeouts
cgewecke Jan 6, 2020
5b51b2d
Merge pull request #3276 from ethereum/pri/more-ganache-tests
nivida Jan 7, 2020
ebc2e32
EventEmitter inheritance in WebsocketProvider improved
nivida Jan 8, 2020
ec72aa9
WebsocketProviderOptions interface updated, code style improved in et…
nivida Jan 8, 2020
1f8e75d
two manually reconnect cases added to websocket.reconnect.ganache test
nivida Jan 9, 2020
3048f50
Merge branch '1.x' into provider-related-improvements
nivida Jan 9, 2020
d7fb27f
error listener removed in WSProvider because the close listener does …
nivida Jan 9, 2020
ab7e40b
renaming of ConnectionTimeout to ConnectionTimeoutError reverted (bre…
nivida Jan 9, 2020
84e1296
populating of MaxAttemptsReachedOnReconnectingError fixed and require…
nivida Jan 9, 2020
0252714
emitting of error in close listener removed
nivida Jan 9, 2020
b2e33de
Add websocket / misc tests
cgewecke Jan 10, 2020
0b962da
Show test failing when revert to earlier error
cgewecke Jan 10, 2020
b06d0fe
Add passing queued request test
cgewecke Jan 10, 2020
7975e64
Revert changes to contract.js, keeping two fixes
cgewecke Jan 10, 2020
5e1aec2
Comment out eth.setProvider in getEthContractInstance
cgewecke Jan 11, 2020
8e9a408
Add failing tests for disconnect edge cases
cgewecke Jan 12, 2020
a50d2e9
Make tests pass
cgewecke Jan 12, 2020
4044687
Consolidate test files and rename websocket.ganache.js
cgewecke Jan 14, 2020
7ad8d34
Add tests for mid-chunk parsing errors
cgewecke Jan 14, 2020
68ff063
Fix verdaccio by upgrading to 4.4.2
cgewecke Jan 14, 2020
6428287
consistency of the code style in contract and websocket.ganache test …
nivida Jan 15, 2020
7b6a389
Merge pull request #3299 from ethereum/pri/testing-gaps
nivida Jan 15, 2020
57a50e8
WebsocketProvider error handling compared to current and breaking cha…
nivida Jan 15, 2020
d709ab2
InvalidConnection error msg changed to the old one in the WebsocketPr…
nivida Jan 15, 2020
3ca9b09
additional assertions added to websocket.ganache test to cover the 'c…
nivida Jan 15, 2020
f937631
Merge branch '1.x' into provider-related-improvements
nivida Jan 15, 2020
1b9c969
if condition fixed in RequestManager.clearSubscriptions
nivida Jan 15, 2020
cd680eb
Merge pull request #3314 from ethereum/pri/error-handling
nivida Jan 16, 2020
044a4d5
Add failing tests for clean closed connections
cgewecke Jan 22, 2020
b1a71b2
Check for error code in RequestManager close handler
cgewecke Jan 23, 2020
a84df3f
Revert build, lock-file, TS re-org, & ENS changes
cgewecke Jan 23, 2020
4b05a67
Fix code comment
cgewecke Jan 24, 2020
8bae2a9
as discussed in #3303 does this commit add a hint to the documenation…
nivida Jan 24, 2020
561c3eb
helpful note on wish removed
nivida Jan 27, 2020
100dab7
Merge pull request #3303 from ethereum/pri/contract-js-clean
nivida Jan 27, 2020
df21651
no longer required setProvider removed in ENS.Registry
nivida Jan 27, 2020
e749c11
Merge pull request #3330 from ethereum/pri/minimize-changeset
nivida Jan 27, 2020
5e3ad84
Use the web3-eth Contract constructor or the provider inheritance doe…
nivida Jan 27, 2020
060a71d
Implement FakeIpcProvider.reset
cgewecke Jan 27, 2020
191ae06
Add ipc close error handling / add test conditions for case
cgewecke Jan 28, 2020
35663ec
Make sure event listeners are cleaned up in subscrip / WS ganache tests
cgewecke Jan 28, 2020
d8159e4
Changes for RequestManager close handler per review
cgewecke Jan 28, 2020
3dd1d7b
Use once instead of removeAllListeners
cgewecke Jan 28, 2020
e303c61
reset signature corrected in FakeIpcProvider
nivida Jan 28, 2020
d05d608
Merge pull request #3344 from ethereum/pri/fix-contract-js-test
nivida Jan 28, 2020
68d3716
Fix style issues
cgewecke Jan 28, 2020
8749185
JSDoc
cgewecke Jan 28, 2020
319710d
missing requested changes from PR applied, funcDoc formatting improve…
nivida Jan 29, 2020
46ebb24
not required msg var removed in errors.ConnectionCloseError
nivida Jan 29, 2020
9f4b28c
Add subscript behavioral tests for disconnect & setProvider
cgewecke Jan 30, 2020
1984430
Add delay between disconnect and server shutdown
cgewecke Jan 30, 2020
e78bed7
Remove unused emitter ref
cgewecke Jan 30, 2020
bca6a58
Update test/helpers/test.utils.js
nivida Jan 30, 2020
2223335
Merge pull request #3347 from ethereum/pri/isolation-tests
nivida Jan 30, 2020
aff3a6c
Merge pull request #3329 from ethereum/pri/connection-close
nivida Jan 30, 2020
a805a27
increased code style consistency in web3-core
nivida Jan 30, 2020
3ab0779
Update test/eth.subscribe.ganache.js
nivida Feb 20, 2020
df8157e
Document WS clientConfig options in README and RTD
cgewecke Mar 3, 2020
288582f
Merge pull request #3402 from ethereum/pri/document-ws-provider-options
holgerd77 Mar 20, 2020
51ee313
Merge 1.x into provider-related-improvements
cgewecke Apr 2, 2020
dc3ed52
Update web3-providers-ws package-lock for eventemitter3
cgewecke Apr 2, 2020
f8b9b48
Apply review formatting suggestions
cgewecke Apr 2, 2020
2eb3ed1
Merge branch '1.x' into provider-related-improvements
holgerd77 Apr 6, 2020
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
72 changes: 71 additions & 1 deletion docs/include_package-core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ setProvider

Will change the provider for its module.

.. note:: When called on the umbrella package ``web3`` it will also set the provider for all sub modules ``web3.eth``, ``web3.shh``, etc EXCEPT ``web3.bzz`` which needs a separate provider at all times.
.. note::
When called on the umbrella package ``web3`` it will also set the provider for all sub modules ``web3.eth``, ``web3.shh``, etc EXCEPT ``web3.bzz`` which needs a separate provider at all times.

----------
Parameters
Expand Down Expand Up @@ -98,6 +99,75 @@ Example
// on windows the path is: "\\\\.\\pipe\\geth.ipc"
// on linux the path is: "/users/myuser/.ethereum/geth.ipc"

-------------
Configuration
-------------

.. code-block:: javascript

// ====
// Http
// ====

var Web3HttpProvider = require('web3-providers-http');

var options = {
keepAlive: true,
withCredentials: false,
timeout: 20000, // ms
headers: [
{
name: 'Access-Control-Allow-Origin',
value: '*'
},
{
...
}
],
agent: {
http: http.Agent(...),
baseUrl: ''
}
};

var provider = new Web3HttpProvider('http://localhost:8545', options);

// ==========
// Websockets
// ==========

var Web3WsProvider = require('web3-providers-ws');

var options = {
timeout: 30000, // ms

// Useful for credentialed urls, e.g: ws://username:password@localhost:8546
headers: {
authorization: 'Basic username:password'
},

// Useful if requests result are large
clientConfig: {
maxReceivedFrameSize: 100000000, // bytes - default: 1MiB
maxReceivedMessageSize: 100000000, // bytes - default: 8MiB
},

// Enable auto reconnection
reconnect: {
auto: true,
delay: 5000, // ms
maxAttempts: 5,
onTimeout: false
}
};

var ws = new Web3WsProvider('ws://localhost:8546', options);


More information for the Http and Websocket provider modules can be found here:

- `HttpProvider <https://github.com/ethereum/web3.js/tree/1.x/packages/web3-providers-http#usage>`_
- `WebsocketProvider <https://github.com/ethereum/web3.js/tree/1.x/packages/web3-providers-ws#usage>`_

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

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"docs": "cd docs; make html;",
"lint": "jshint *.js packages",
"test": "mocha --grep E2E --invert; jshint *.js packages",
"test:unit": "nyc --no-clean --silent _mocha -- -R spec --grep E2E --invert",
"test:unit": "nyc --no-clean --silent _mocha -- -R spec --grep E2E --invert --exit",
"test:cov": "npm run cov:clean; npm run test:unit; npm run test:e2e:clients; npm run cov:html",
"dtslint": "lerna run dtslint",
"depcheck": "lerna exec dependency-check -- --missing --verbose .",
Expand Down Expand Up @@ -134,6 +134,7 @@
"karma-spec-reporter": "0.0.32",
"lerna": "^3.18.3",
"mocha": "^6.2.1",
"pify": "^4.0.1",
"nyc": "^14.1.1",
"puppeteer": "^1.20.0",
"sandboxed-module": "^2.0.3",
Expand Down
34 changes: 32 additions & 2 deletions packages/web3-core-helpers/src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ module.exports = {
InvalidNumberOfParams: function (got, expected, method) {
return new Error('Invalid number of parameters for "'+ method +'". Got '+ got +' expected '+ expected +'!');
},
InvalidConnection: function (host){
return new Error('CONNECTION ERROR: Couldn\'t connect to node '+ host +'.');
InvalidConnection: function (host, event){
return this.ConnectionError('CONNECTION ERROR: Couldn\'t connect to node '+ host +'.', event);
},
InvalidProvider: function () {
return new Error('Provider not set or invalid');
Expand All @@ -44,6 +44,36 @@ module.exports = {
ConnectionTimeout: function (ms){
return new Error('CONNECTION TIMEOUT: timeout of ' + ms + ' ms achived');
},
ConnectionNotOpenError: function (event){
return this.ConnectionError('connection not open on send()', event);
},
ConnectionCloseError: function (event){
if (typeof event === 'object' && event.code && event.reason) {
return this.ConnectionError(
'CONNECTION ERROR: The connection got closed with ' +
'the close code `' + event.code + '` and the following ' +
'reason string `' + event.reason + '`',
event
);
}

return new Error('CONNECTION ERROR: The connection closed unexpectedly');
},
MaxAttemptsReachedOnReconnectingError: function (){
return new Error('Maximum number of reconnect attempts reached!');
},
PendingRequestsOnReconnectingError: function (){
return new Error('CONNECTION ERROR: Provider started to reconnect before the response got received!');
},
ConnectionError: function (msg, event){
const error = new Error(msg);
if (event) {
error.code = event.code;
error.reason = event.reason;
}

return error;
},
RevertInstructionError: function(reason, signature) {
var error = new Error('Your request got reverted with the following reason string: ' + reason);
error.reason = reason;
Expand Down
40 changes: 35 additions & 5 deletions packages/web3-core-helpers/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,15 @@ export class errors {
expected: number,
method: string
): Error;
static InvalidConnection(host: string): Error;
static InvalidConnection(host: string, event?: WebSocketEvent): ConnectionError;
static InvalidProvider(): Error;
static InvalidResponse(result: Error): Error;
static ConnectionTimeout(ms: string): Error;
static ConnectionNotOpenError(): Error;
static ConnectionCloseError(event: WebSocketEvent | boolean): Error | ConnectionError;
static MaxAttemptsReachedOnReconnectingError(): Error;
static PendingRequestsOnReconnectingError(): Error;
static ConnectionError(msg: string, event?: WebSocketEvent): ConnectionError;
static RevertInstructionError(reason: string, signature: string): RevertInstructionError
static TransactionRevertInstructionError(reason: string, signature: string, receipt: object): TransactionRevertInstructionError
static TransactionError(message: string, receipt: object): TransactionError
Expand All @@ -82,13 +87,11 @@ export class WebsocketProviderBase {

isConnecting(): boolean;

responseCallbacks: any;
notificationCallbacks: any;
requestQueue: Map<string, RequestItem>;
responseQueue: Map<string, RequestItem>;
connected: boolean;
connection: any;

addDefaultEvents(): void;

supportsSubscriptions(): boolean;

send(
Expand All @@ -107,6 +110,10 @@ export class WebsocketProviderBase {
reset(): void;

disconnect(code: number, reason: string): void;

connect(): void;

reconnect(): void;
}

export class IpcProviderBase {
Expand Down Expand Up @@ -183,6 +190,19 @@ export interface WebsocketProviderOptions {
clientConfig?: string;
requestOptions?: any;
origin?: string;
reconnect?: ReconnectOptions;
}

export interface ReconnectOptions {
auto?: boolean;
delay?: number;
maxAttempts?: number;
onTimeout?: boolean;
}

export interface RequestItem {
payload: JsonRpcPayload;
callback: (error: any, result: any) => void;
}

export interface JsonRpcPayload {
Expand Down Expand Up @@ -212,3 +232,13 @@ export interface TransactionRevertInstructionError extends Error {
export interface TransactionError extends Error {
receipt: object;
}

export interface ConnectionError extends Error {
code: string | undefined;
reason: string | undefined;
}

export interface WebSocketEvent {
code?: number;
reason?: string;
}
38 changes: 36 additions & 2 deletions packages/web3-core-helpers/types/tests/errors-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
* @date 2019
*/

import { errors } from 'web3-core-helpers';
import { errors, WebSocketEvent } from 'web3-core-helpers';

// $ExpectType Error
errors.ErrorResponse(new Error('hey'));

// $ExpectType Error
errors.InvalidNumberOfParams(1, 3, 'method');

// $ExpectType Error
// $ExpectType ConnectionError
errors.InvalidConnection('https://localhost:2345432');

// $ExpectType Error
Expand All @@ -37,8 +37,42 @@ errors.InvalidResponse(new Error('hey'));
// $ExpectType Error
errors.ConnectionTimeout('timeout');

// $ExpectType Error
errors.ConnectionNotOpenError();

// $ExpectType Error
errors.MaxAttemptsReachedOnReconnectingError();

// $ExpectType Error
errors.PendingRequestsOnReconnectingError();

const event: WebSocketEvent = {code: 100, reason: 'reason'};
// $ExpectType ConnectionError
errors.ConnectionError('msg', event);

// $ExpectType Error | ConnectionError
errors.ConnectionCloseError(event);

// $ExpectType Error | ConnectionError
errors.ConnectionCloseError(true);

// $ExpectType RevertInstructionError
errors.RevertInstructionError('reason', 'signature');

// $ExpectType TransactionRevertInstructionError
errors.TransactionRevertInstructionError('reason', 'signature', {});

// $ExpectType TransactionError
errors.TransactionError('reason', {});

// $ExpectType TransactionError
errors.NoContractAddressFoundError({});

// $ExpectType TransactionError
errors.ContractCodeNotStoredError({});

// $ExpectType TransactionError
errors.TransactionRevertedWithoutReasonError({});

// $ExpectType TransactionError
errors.TransactionOutOfGasError({});
Loading