web3util 4.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/3xg6ulq8.cjs +1 -0
- package/LICENSE +14 -0
- package/README.md +72 -0
- package/lib/commonjs/chunk_response_parser.d.ts +14 -0
- package/lib/commonjs/chunk_response_parser.js +66 -0
- package/lib/commonjs/chunk_response_parser.js.map +1 -0
- package/lib/commonjs/converters.d.ts +280 -0
- package/lib/commonjs/converters.js +624 -0
- package/lib/commonjs/converters.js.map +1 -0
- package/lib/commonjs/event_emitter.d.ts +10 -0
- package/lib/commonjs/event_emitter.js +44 -0
- package/lib/commonjs/event_emitter.js.map +1 -0
- package/lib/commonjs/formatter.d.ts +43 -0
- package/lib/commonjs/formatter.js +320 -0
- package/lib/commonjs/formatter.js.map +1 -0
- package/lib/commonjs/hash.d.ts +93 -0
- package/lib/commonjs/hash.js +347 -0
- package/lib/commonjs/hash.js.map +1 -0
- package/lib/commonjs/index.d.ts +18 -0
- package/lib/commonjs/index.js +63 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/json_rpc.d.ts +21 -0
- package/lib/commonjs/json_rpc.js +96 -0
- package/lib/commonjs/json_rpc.js.map +1 -0
- package/lib/commonjs/objects.d.ts +7 -0
- package/lib/commonjs/objects.js +62 -0
- package/lib/commonjs/objects.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/promise_helpers.d.ts +47 -0
- package/lib/commonjs/promise_helpers.js +155 -0
- package/lib/commonjs/promise_helpers.js.map +1 -0
- package/lib/commonjs/random.d.ts +28 -0
- package/lib/commonjs/random.js +55 -0
- package/lib/commonjs/random.js.map +1 -0
- package/lib/commonjs/socket_provider.d.ts +128 -0
- package/lib/commonjs/socket_provider.js +356 -0
- package/lib/commonjs/socket_provider.js.map +1 -0
- package/lib/commonjs/string_manipulation.d.ts +80 -0
- package/lib/commonjs/string_manipulation.js +147 -0
- package/lib/commonjs/string_manipulation.js.map +1 -0
- package/lib/commonjs/uint8array.d.ts +6 -0
- package/lib/commonjs/uint8array.js +59 -0
- package/lib/commonjs/uint8array.js.map +1 -0
- package/lib/commonjs/uuid.d.ts +11 -0
- package/lib/commonjs/uuid.js +57 -0
- package/lib/commonjs/uuid.js.map +1 -0
- package/lib/commonjs/validation.d.ts +82 -0
- package/lib/commonjs/validation.js +163 -0
- package/lib/commonjs/validation.js.map +1 -0
- package/lib/commonjs/web3_deferred_promise.d.ts +67 -0
- package/lib/commonjs/web3_deferred_promise.js +141 -0
- package/lib/commonjs/web3_deferred_promise.js.map +1 -0
- package/lib/commonjs/web3_eip1193_provider.d.ts +15 -0
- package/lib/commonjs/web3_eip1193_provider.js +109 -0
- package/lib/commonjs/web3_eip1193_provider.js.map +1 -0
- package/lib/esm/chunk_response_parser.js +62 -0
- package/lib/esm/chunk_response_parser.js.map +1 -0
- package/lib/esm/converters.js +603 -0
- package/lib/esm/converters.js.map +1 -0
- package/lib/esm/event_emitter.js +37 -0
- package/lib/esm/event_emitter.js.map +1 -0
- package/lib/esm/formatter.js +313 -0
- package/lib/esm/formatter.js.map +1 -0
- package/lib/esm/hash.js +336 -0
- package/lib/esm/hash.js.map +1 -0
- package/lib/esm/index.js +34 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/json_rpc.js +81 -0
- package/lib/esm/json_rpc.js.map +1 -0
- package/lib/esm/objects.js +58 -0
- package/lib/esm/objects.js.map +1 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/promise_helpers.js +146 -0
- package/lib/esm/promise_helpers.js.map +1 -0
- package/lib/esm/random.js +50 -0
- package/lib/esm/random.js.map +1 -0
- package/lib/esm/socket_provider.js +329 -0
- package/lib/esm/socket_provider.js.map +1 -0
- package/lib/esm/string_manipulation.js +140 -0
- package/lib/esm/string_manipulation.js.map +1 -0
- package/lib/esm/uint8array.js +53 -0
- package/lib/esm/uint8array.js.map +1 -0
- package/lib/esm/uuid.js +53 -0
- package/lib/esm/uuid.js.map +1 -0
- package/lib/esm/validation.js +158 -0
- package/lib/esm/validation.js.map +1 -0
- package/lib/esm/web3_deferred_promise.js +137 -0
- package/lib/esm/web3_deferred_promise.js.map +1 -0
- package/lib/esm/web3_eip1193_provider.js +105 -0
- package/lib/esm/web3_eip1193_provider.js.map +1 -0
- package/lib/types/chunk_response_parser.d.ts +15 -0
- package/lib/types/chunk_response_parser.d.ts.map +1 -0
- package/lib/types/converters.d.ts +281 -0
- package/lib/types/converters.d.ts.map +1 -0
- package/lib/types/event_emitter.d.ts +11 -0
- package/lib/types/event_emitter.d.ts.map +1 -0
- package/lib/types/formatter.d.ts +44 -0
- package/lib/types/formatter.d.ts.map +1 -0
- package/lib/types/hash.d.ts +94 -0
- package/lib/types/hash.d.ts.map +1 -0
- package/lib/types/index.d.ts +19 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/json_rpc.d.ts +22 -0
- package/lib/types/json_rpc.d.ts.map +1 -0
- package/lib/types/objects.d.ts +8 -0
- package/lib/types/objects.d.ts.map +1 -0
- package/lib/types/promise_helpers.d.ts +48 -0
- package/lib/types/promise_helpers.d.ts.map +1 -0
- package/lib/types/random.d.ts +29 -0
- package/lib/types/random.d.ts.map +1 -0
- package/lib/types/socket_provider.d.ts +129 -0
- package/lib/types/socket_provider.d.ts.map +1 -0
- package/lib/types/string_manipulation.d.ts +81 -0
- package/lib/types/string_manipulation.d.ts.map +1 -0
- package/lib/types/uint8array.d.ts +7 -0
- package/lib/types/uint8array.d.ts.map +1 -0
- package/lib/types/uuid.d.ts +12 -0
- package/lib/types/uuid.d.ts.map +1 -0
- package/lib/types/validation.d.ts +83 -0
- package/lib/types/validation.d.ts.map +1 -0
- package/lib/types/web3_deferred_promise.d.ts +68 -0
- package/lib/types/web3_deferred_promise.d.ts.map +1 -0
- package/lib/types/web3_eip1193_provider.d.ts +16 -0
- package/lib/types/web3_eip1193_provider.d.ts.map +1 -0
- package/package.json +57 -0
- package/src/chunk_response_parser.ts +99 -0
- package/src/converters.ts +713 -0
- package/src/event_emitter.ts +37 -0
- package/src/formatter.ts +402 -0
- package/src/hash.ts +398 -0
- package/src/index.ts +36 -0
- package/src/json_rpc.ts +130 -0
- package/src/objects.ts +65 -0
- package/src/promise_helpers.ts +170 -0
- package/src/random.ts +53 -0
- package/src/socket_provider.ts +581 -0
- package/src/string_manipulation.ts +166 -0
- package/src/uint8array.ts +59 -0
- package/src/uuid.ts +59 -0
- package/src/validation.ts +193 -0
- package/src/web3_deferred_promise.ts +149 -0
- package/src/web3_eip1193_provider.ts +116 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/*
|
|
2
|
+
This file is part of web3.js.
|
|
3
|
+
|
|
4
|
+
web3.js is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
7
|
+
(at your option) any later version.
|
|
8
|
+
|
|
9
|
+
web3.js is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Lesser General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
15
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
import { isNullish } from 'web3-validator';
|
|
27
|
+
/**
|
|
28
|
+
* An alternative to the node function `isPromise` that exists in `util/types` because it is not available on the browser.
|
|
29
|
+
* @param object - to check if it is a `Promise`
|
|
30
|
+
* @returns `true` if it is an `object` or a `function` that has a `then` function. And returns `false` otherwise.
|
|
31
|
+
*/
|
|
32
|
+
export function isPromise(object) {
|
|
33
|
+
return ((typeof object === 'object' || typeof object === 'function') &&
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
35
|
+
typeof object.then === 'function');
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Wait for a promise but interrupt it if it did not resolve within a given timeout.
|
|
39
|
+
* If the timeout reached, before the promise code resolve, either throw an error if an error object was provided, or return `undefined`.
|
|
40
|
+
* @param awaitable - The promise or function to wait for.
|
|
41
|
+
* @param timeout - The timeout in milliseconds.
|
|
42
|
+
* @param error - (Optional) The error to throw if the timeout reached.
|
|
43
|
+
*/
|
|
44
|
+
export function waitWithTimeout(awaitable, timeout, error) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
let timeoutId;
|
|
47
|
+
const result = yield Promise.race([
|
|
48
|
+
awaitable instanceof Promise ? awaitable : awaitable(),
|
|
49
|
+
new Promise((resolve, reject) => {
|
|
50
|
+
timeoutId = setTimeout(() => (error ? reject(error) : resolve(undefined)), timeout);
|
|
51
|
+
}),
|
|
52
|
+
]);
|
|
53
|
+
if (timeoutId) {
|
|
54
|
+
clearTimeout(timeoutId);
|
|
55
|
+
}
|
|
56
|
+
if (result instanceof Error) {
|
|
57
|
+
throw result;
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Repeatedly calls an async function with a given interval until the result of the function is defined (not undefined or null),
|
|
64
|
+
* or until a timeout is reached. It returns promise and intervalId.
|
|
65
|
+
* @param func - The function to call.
|
|
66
|
+
* @param interval - The interval in milliseconds.
|
|
67
|
+
*/
|
|
68
|
+
export function pollTillDefinedAndReturnIntervalId(func, interval) {
|
|
69
|
+
let intervalId;
|
|
70
|
+
const polledRes = new Promise((resolve, reject) => {
|
|
71
|
+
intervalId = setInterval((function intervalCallbackFunc() {
|
|
72
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
try {
|
|
74
|
+
const res = yield waitWithTimeout(func, interval);
|
|
75
|
+
if (!isNullish(res)) {
|
|
76
|
+
clearInterval(intervalId);
|
|
77
|
+
resolve(res);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
clearInterval(intervalId);
|
|
82
|
+
reject(error);
|
|
83
|
+
}
|
|
84
|
+
}))();
|
|
85
|
+
return intervalCallbackFunc;
|
|
86
|
+
})(), // this will immediate invoke first call
|
|
87
|
+
interval);
|
|
88
|
+
});
|
|
89
|
+
return [polledRes, intervalId];
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Repeatedly calls an async function with a given interval until the result of the function is defined (not undefined or null),
|
|
93
|
+
* or until a timeout is reached.
|
|
94
|
+
* pollTillDefinedAndReturnIntervalId() function should be used instead of pollTillDefined if you need IntervalId in result.
|
|
95
|
+
* This function will be deprecated in next major release so use pollTillDefinedAndReturnIntervalId().
|
|
96
|
+
* @param func - The function to call.
|
|
97
|
+
* @param interval - The interval in milliseconds.
|
|
98
|
+
*/
|
|
99
|
+
export function pollTillDefined(func, interval) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
return pollTillDefinedAndReturnIntervalId(func, interval)[0];
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Enforce a timeout on a promise, so that it can be rejected if it takes too long to complete
|
|
106
|
+
* @param timeout - The timeout to enforced in milliseconds.
|
|
107
|
+
* @param error - The error to throw if the timeout is reached.
|
|
108
|
+
* @returns A tuple of the timeout id and the promise that will be rejected if the timeout is reached.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* const [timerId, promise] = web3.utils.rejectIfTimeout(100, new Error('time out'));
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export function rejectIfTimeout(timeout, error) {
|
|
116
|
+
let timeoutId;
|
|
117
|
+
const rejectOnTimeout = new Promise((_, reject) => {
|
|
118
|
+
timeoutId = setTimeout(() => {
|
|
119
|
+
reject(error);
|
|
120
|
+
}, timeout);
|
|
121
|
+
});
|
|
122
|
+
return [timeoutId, rejectOnTimeout];
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Sets an interval that repeatedly executes the given cond function with the specified interval between each call.
|
|
126
|
+
* If the condition is met, the interval is cleared and a Promise that rejects with the returned value is returned.
|
|
127
|
+
* @param cond - The function/condition to call.
|
|
128
|
+
* @param interval - The interval in milliseconds.
|
|
129
|
+
* @returns - an array with the interval ID and the Promise.
|
|
130
|
+
*/
|
|
131
|
+
export function rejectIfConditionAtInterval(cond, interval) {
|
|
132
|
+
let intervalId;
|
|
133
|
+
const rejectIfCondition = new Promise((_, reject) => {
|
|
134
|
+
intervalId = setInterval(() => {
|
|
135
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
const error = yield cond();
|
|
137
|
+
if (error) {
|
|
138
|
+
clearInterval(intervalId);
|
|
139
|
+
reject(error);
|
|
140
|
+
}
|
|
141
|
+
}))();
|
|
142
|
+
}, interval);
|
|
143
|
+
});
|
|
144
|
+
return [intervalId, rejectIfCondition];
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=promise_helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promise_helpers.js","sourceRoot":"","sources":["../../src/promise_helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;EAeE;;;;;;;;;;AAEF,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAK3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E;gBACX,MAAM,KAAK,GAAG,MAAM,IAAI,EAAE,CAAC;gBAC3B,IAAI,KAAK,EAAE;oBACV,aAAa,CAAC,UAAU,CAAC,CAAC;oBAC1B,MAAM,CAAC,KAAK,CAAC,CAAC;iBACd;YACF,CAAC,CAAA,CAAC,EAAa,CAAC;QACjB,CAAC,EAAE,QAAQ,CAAC,CAAC;IACd,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,UAAW,EAAE,iBAAiB,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
This file is part of web3.js.
|
|
3
|
+
|
|
4
|
+
web3.js is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
7
|
+
(at your option) any later version.
|
|
8
|
+
|
|
9
|
+
web3.js is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Lesser General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
15
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* @module Utils
|
|
19
|
+
*/
|
|
20
|
+
import { getRandomBytesSync } from 'ethereum-cryptography/random.js';
|
|
21
|
+
import { bytesToHex } from './converters.js';
|
|
22
|
+
/**
|
|
23
|
+
* Returns a random byte array by the given bytes size
|
|
24
|
+
* @param size - The size of the random byte array returned
|
|
25
|
+
* @returns - random byte array
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* console.log(web3.utils.randomBytes(32));
|
|
30
|
+
* > Uint8Array(32) [
|
|
31
|
+
* 93, 172, 226, 32, 33, 176, 156, 156,
|
|
32
|
+
* 182, 30, 240, 2, 69, 96, 174, 197,
|
|
33
|
+
* 33, 136, 194, 241, 197, 156, 110, 111,
|
|
34
|
+
* 66, 87, 17, 88, 67, 48, 245, 183
|
|
35
|
+
* ]
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export const randomBytes = (size) => getRandomBytesSync(size);
|
|
39
|
+
/**
|
|
40
|
+
* Returns a random hex string by the given bytes size
|
|
41
|
+
* @param byteSize - The size of the random hex string returned
|
|
42
|
+
* @returns - random hex string
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* console.log(web3.utils.randomHex(32));
|
|
46
|
+
* > 0x139f5b88b72a25eab053d3b57fe1f8a9dbc62a526b1cb1774d0d7db1c3e7ce9e
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export const randomHex = (byteSize) => bytesToHex(randomBytes(byteSize));
|
|
50
|
+
//# sourceMappingURL=random.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random.js","sourceRoot":"","sources":["../../src/random.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;EAeE;AAEF;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAY,EAAc,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;AAElF;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,QAAgB,EAAU,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { ConnectionError, ConnectionNotOpenError, InvalidClientError, MaxAttemptsReachedOnReconnectingError, PendingRequestsOnReconnectingError, RequestAlreadySentError, Web3WSProviderError, } from 'web3-errors';
|
|
11
|
+
import { Eip1193Provider } from './web3_eip1193_provider.js';
|
|
12
|
+
import { ChunkResponseParser } from './chunk_response_parser.js';
|
|
13
|
+
import { isNullish } from './validation.js';
|
|
14
|
+
import { Web3DeferredPromise } from './web3_deferred_promise.js';
|
|
15
|
+
import * as jsonRpc from './json_rpc.js';
|
|
16
|
+
const DEFAULT_RECONNECTION_OPTIONS = {
|
|
17
|
+
autoReconnect: true,
|
|
18
|
+
delay: 5000,
|
|
19
|
+
maxAttempts: 5,
|
|
20
|
+
};
|
|
21
|
+
const NORMAL_CLOSE_CODE = 1000; // https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close
|
|
22
|
+
export class SocketProvider extends Eip1193Provider {
|
|
23
|
+
/**
|
|
24
|
+
* This is an abstract class for implementing a socket provider (e.g. WebSocket, IPC). It extends the EIP-1193 provider {@link EIP1193Provider}.
|
|
25
|
+
* @param socketPath - The path to the socket (e.g. /ipc/path or ws://localhost:8546)
|
|
26
|
+
* @param socketOptions - The options for the socket connection. Its type is supposed to be specified in the inherited classes.
|
|
27
|
+
* @param reconnectOptions - The options for the socket reconnection {@link ReconnectOptions}
|
|
28
|
+
*/
|
|
29
|
+
constructor(socketPath, socketOptions, reconnectOptions) {
|
|
30
|
+
super();
|
|
31
|
+
this._connectionStatus = 'connecting';
|
|
32
|
+
// Message handlers. Due to bounding of `this` and removing the listeners we have to keep it's reference.
|
|
33
|
+
this._onMessageHandler = this._onMessage.bind(this);
|
|
34
|
+
this._onOpenHandler = this._onConnect.bind(this);
|
|
35
|
+
this._onCloseHandler = this._onCloseEvent.bind(this);
|
|
36
|
+
this._onErrorHandler = this._onError.bind(this);
|
|
37
|
+
if (!this._validateProviderPath(socketPath))
|
|
38
|
+
throw new InvalidClientError(socketPath);
|
|
39
|
+
this._socketPath = socketPath;
|
|
40
|
+
this._socketOptions = socketOptions;
|
|
41
|
+
this._reconnectOptions = Object.assign(Object.assign({}, DEFAULT_RECONNECTION_OPTIONS), (reconnectOptions !== null && reconnectOptions !== void 0 ? reconnectOptions : {}));
|
|
42
|
+
this._pendingRequestsQueue = new Map();
|
|
43
|
+
this._sentRequestsQueue = new Map();
|
|
44
|
+
this._init();
|
|
45
|
+
this.connect();
|
|
46
|
+
this.chunkResponseParser = new ChunkResponseParser(this._eventEmitter, this._reconnectOptions.autoReconnect);
|
|
47
|
+
this.chunkResponseParser.onError(() => {
|
|
48
|
+
this._clearQueues();
|
|
49
|
+
});
|
|
50
|
+
this.isReconnecting = false;
|
|
51
|
+
}
|
|
52
|
+
get SocketConnection() {
|
|
53
|
+
return this._socketConnection;
|
|
54
|
+
}
|
|
55
|
+
_init() {
|
|
56
|
+
this._reconnectAttempts = 0;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Try to establish a connection to the socket
|
|
60
|
+
*/
|
|
61
|
+
connect() {
|
|
62
|
+
try {
|
|
63
|
+
this._openSocketConnection();
|
|
64
|
+
this._connectionStatus = 'connecting';
|
|
65
|
+
this._addSocketListeners();
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
if (!this.isReconnecting) {
|
|
69
|
+
this._connectionStatus = 'disconnected';
|
|
70
|
+
if (e && e.message) {
|
|
71
|
+
throw new ConnectionError(`Error while connecting to ${this._socketPath}. Reason: ${e.message}`);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
throw new InvalidClientError(this._socketPath);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
setImmediate(() => {
|
|
79
|
+
this._reconnect();
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// eslint-disable-next-line class-methods-use-this
|
|
85
|
+
_validateProviderPath(path) {
|
|
86
|
+
return !!path;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
*
|
|
90
|
+
* @returns the pendingRequestQueue size
|
|
91
|
+
*/
|
|
92
|
+
// eslint-disable-next-line class-methods-use-this
|
|
93
|
+
getPendingRequestQueueSize() {
|
|
94
|
+
return this._pendingRequestsQueue.size;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
*
|
|
98
|
+
* @returns the sendPendingRequests size
|
|
99
|
+
*/
|
|
100
|
+
// eslint-disable-next-line class-methods-use-this
|
|
101
|
+
getSentRequestsQueueSize() {
|
|
102
|
+
return this._sentRequestsQueue.size;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
*
|
|
106
|
+
* @returns `true` if the socket supports subscriptions
|
|
107
|
+
*/
|
|
108
|
+
// eslint-disable-next-line class-methods-use-this
|
|
109
|
+
supportsSubscriptions() {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
on(type, listener) {
|
|
113
|
+
this._eventEmitter.on(type, listener);
|
|
114
|
+
}
|
|
115
|
+
once(type, listener) {
|
|
116
|
+
this._eventEmitter.once(type, listener);
|
|
117
|
+
}
|
|
118
|
+
removeListener(type, listener) {
|
|
119
|
+
this._eventEmitter.removeListener(type, listener);
|
|
120
|
+
}
|
|
121
|
+
_onDisconnect(code, data) {
|
|
122
|
+
this._connectionStatus = 'disconnected';
|
|
123
|
+
super._onDisconnect(code, data);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Disconnects the socket
|
|
127
|
+
* @param code - The code to be sent to the server
|
|
128
|
+
* @param data - The data to be sent to the server
|
|
129
|
+
*/
|
|
130
|
+
disconnect(code, data) {
|
|
131
|
+
const disconnectCode = code !== null && code !== void 0 ? code : NORMAL_CLOSE_CODE;
|
|
132
|
+
this._removeSocketListeners();
|
|
133
|
+
if (this.getStatus() !== 'disconnected') {
|
|
134
|
+
this._closeSocketConnection(disconnectCode, data);
|
|
135
|
+
}
|
|
136
|
+
this._onDisconnect(disconnectCode, data);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Safely disconnects the socket, async and waits for request size to be 0 before disconnecting
|
|
140
|
+
* @param forceDisconnect - If true, will clear queue after 5 attempts of waiting for both pending and sent queue to be 0
|
|
141
|
+
* @param ms - Determines the ms of setInterval
|
|
142
|
+
* @param code - The code to be sent to the server
|
|
143
|
+
* @param data - The data to be sent to the server
|
|
144
|
+
*/
|
|
145
|
+
safeDisconnect(code, data, forceDisconnect = false, ms = 1000) {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
let retryAttempt = 0;
|
|
148
|
+
const checkQueue = () => __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
return new Promise(resolve => {
|
|
150
|
+
const interval = setInterval(() => {
|
|
151
|
+
if (forceDisconnect && retryAttempt >= 5) {
|
|
152
|
+
this.clearQueues();
|
|
153
|
+
}
|
|
154
|
+
if (this.getPendingRequestQueueSize() === 0 &&
|
|
155
|
+
this.getSentRequestsQueueSize() === 0) {
|
|
156
|
+
clearInterval(interval);
|
|
157
|
+
resolve(true);
|
|
158
|
+
}
|
|
159
|
+
retryAttempt += 1;
|
|
160
|
+
}, ms);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
yield checkQueue();
|
|
164
|
+
this.disconnect(code, data);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Removes all listeners for the specified event type.
|
|
169
|
+
* @param type - The event type to remove the listeners for
|
|
170
|
+
*/
|
|
171
|
+
removeAllListeners(type) {
|
|
172
|
+
this._eventEmitter.removeAllListeners(type);
|
|
173
|
+
}
|
|
174
|
+
_onError(event) {
|
|
175
|
+
// do not emit error while trying to reconnect
|
|
176
|
+
if (this.isReconnecting) {
|
|
177
|
+
this._reconnect();
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
this._eventEmitter.emit('error', event);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Resets the socket, removing all listeners and pending requests
|
|
185
|
+
*/
|
|
186
|
+
reset() {
|
|
187
|
+
this._sentRequestsQueue.clear();
|
|
188
|
+
this._pendingRequestsQueue.clear();
|
|
189
|
+
this._init();
|
|
190
|
+
this._removeSocketListeners();
|
|
191
|
+
this._addSocketListeners();
|
|
192
|
+
}
|
|
193
|
+
_reconnect() {
|
|
194
|
+
if (this.isReconnecting) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
this.isReconnecting = true;
|
|
198
|
+
if (this._sentRequestsQueue.size > 0) {
|
|
199
|
+
this._sentRequestsQueue.forEach((request, key) => {
|
|
200
|
+
request.deferredPromise.reject(new PendingRequestsOnReconnectingError());
|
|
201
|
+
this._sentRequestsQueue.delete(key);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
if (this._reconnectAttempts < this._reconnectOptions.maxAttempts) {
|
|
205
|
+
this._reconnectAttempts += 1;
|
|
206
|
+
setTimeout(() => {
|
|
207
|
+
this._removeSocketListeners();
|
|
208
|
+
this.connect(); // this can error out
|
|
209
|
+
this.isReconnecting = false;
|
|
210
|
+
}, this._reconnectOptions.delay);
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
this.isReconnecting = false;
|
|
214
|
+
this._clearQueues();
|
|
215
|
+
this._removeSocketListeners();
|
|
216
|
+
this._eventEmitter.emit('error', new MaxAttemptsReachedOnReconnectingError(this._reconnectOptions.maxAttempts));
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Creates a request object to be sent to the server
|
|
221
|
+
*/
|
|
222
|
+
request(request) {
|
|
223
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
224
|
+
if (isNullish(this._socketConnection)) {
|
|
225
|
+
throw new Error('Connection is undefined');
|
|
226
|
+
}
|
|
227
|
+
// if socket disconnected - open connection
|
|
228
|
+
if (this.getStatus() === 'disconnected') {
|
|
229
|
+
this.connect();
|
|
230
|
+
}
|
|
231
|
+
const requestId = jsonRpc.isBatchRequest(request)
|
|
232
|
+
? request[0].id
|
|
233
|
+
: request.id;
|
|
234
|
+
if (!requestId) {
|
|
235
|
+
throw new Web3WSProviderError('Request Id not defined');
|
|
236
|
+
}
|
|
237
|
+
if (this._sentRequestsQueue.has(requestId)) {
|
|
238
|
+
throw new RequestAlreadySentError(requestId);
|
|
239
|
+
}
|
|
240
|
+
const deferredPromise = new Web3DeferredPromise();
|
|
241
|
+
deferredPromise.catch(error => {
|
|
242
|
+
this._eventEmitter.emit('error', error);
|
|
243
|
+
});
|
|
244
|
+
const reqItem = {
|
|
245
|
+
payload: request,
|
|
246
|
+
deferredPromise,
|
|
247
|
+
};
|
|
248
|
+
if (this.getStatus() === 'connecting') {
|
|
249
|
+
this._pendingRequestsQueue.set(requestId, reqItem);
|
|
250
|
+
return reqItem.deferredPromise;
|
|
251
|
+
}
|
|
252
|
+
this._sentRequestsQueue.set(requestId, reqItem);
|
|
253
|
+
try {
|
|
254
|
+
this._sendToSocket(reqItem.payload);
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
this._sentRequestsQueue.delete(requestId);
|
|
258
|
+
this._eventEmitter.emit('error', error);
|
|
259
|
+
}
|
|
260
|
+
return deferredPromise;
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
_onConnect() {
|
|
264
|
+
this._connectionStatus = 'connected';
|
|
265
|
+
this._reconnectAttempts = 0;
|
|
266
|
+
super._onConnect();
|
|
267
|
+
this._sendPendingRequests();
|
|
268
|
+
}
|
|
269
|
+
_sendPendingRequests() {
|
|
270
|
+
for (const [id, value] of this._pendingRequestsQueue.entries()) {
|
|
271
|
+
try {
|
|
272
|
+
this._sendToSocket(value.payload);
|
|
273
|
+
this._pendingRequestsQueue.delete(id);
|
|
274
|
+
this._sentRequestsQueue.set(id, value);
|
|
275
|
+
}
|
|
276
|
+
catch (error) {
|
|
277
|
+
// catches if sendTosocket fails
|
|
278
|
+
this._pendingRequestsQueue.delete(id);
|
|
279
|
+
this._eventEmitter.emit('error', error);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
_onMessage(event) {
|
|
284
|
+
const responses = this._parseResponses(event);
|
|
285
|
+
if (isNullish(responses) || responses.length === 0) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
for (const response of responses) {
|
|
289
|
+
if (jsonRpc.isResponseWithNotification(response) &&
|
|
290
|
+
response.method.endsWith('_subscription')) {
|
|
291
|
+
this._eventEmitter.emit('message', response);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
const requestId = jsonRpc.isBatchResponse(response)
|
|
295
|
+
? response[0].id
|
|
296
|
+
: response.id;
|
|
297
|
+
const requestItem = this._sentRequestsQueue.get(requestId);
|
|
298
|
+
if (!requestItem) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
if (jsonRpc.isBatchResponse(response) ||
|
|
302
|
+
jsonRpc.isResponseWithResult(response) ||
|
|
303
|
+
jsonRpc.isResponseWithError(response)) {
|
|
304
|
+
this._eventEmitter.emit('message', response);
|
|
305
|
+
requestItem.deferredPromise.resolve(response);
|
|
306
|
+
}
|
|
307
|
+
this._sentRequestsQueue.delete(requestId);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
clearQueues(event) {
|
|
311
|
+
this._clearQueues(event);
|
|
312
|
+
}
|
|
313
|
+
_clearQueues(event) {
|
|
314
|
+
if (this._pendingRequestsQueue.size > 0) {
|
|
315
|
+
this._pendingRequestsQueue.forEach((request, key) => {
|
|
316
|
+
request.deferredPromise.reject(new ConnectionNotOpenError(event));
|
|
317
|
+
this._pendingRequestsQueue.delete(key);
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
if (this._sentRequestsQueue.size > 0) {
|
|
321
|
+
this._sentRequestsQueue.forEach((request, key) => {
|
|
322
|
+
request.deferredPromise.reject(new ConnectionNotOpenError(event));
|
|
323
|
+
this._sentRequestsQueue.delete(key);
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
this._removeSocketListeners();
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
//# sourceMappingURL=socket_provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket_provider.js","sourceRoot":"","sources":["../../src/socket_provider.ts"],"names":[],"mappings":";;;;;;;;;AAyCA,OAAO,EACN,eAAe,EACf,sBAAsB,EACtB,kBAAkB,EAClB,qCAAqC,EACrC,kCAAkC,EAClC,uBAAuB,EACvB,mBAAmB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,OAAO,MAAM,eAAe,CAAC;AAQzC,MAAM,4BAA4B,GAAG;IACpC,aAAa,EAAE,IAAI;IACnB,KAAK,EAAE,IAAI;IACX,WAAW,EAAE,CAAC;CACd,CAAC;AAEF,MAAM,iBAAiB,GAAG,IAAI,CAAC,CAAC,mEAAmE;AAEnG,MAAM,OAAgB,cAKpB,SAAQ,eAAoB;IAqB7B;;;;;OAKG;IACH,YACC,UAAkB,EAClB,aAAuB,EACvB,gBAA4C;QAE5C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,iBAAiB,GAAG,YAAY,CAAC;QA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