1 | class RPCError extends Error {
|
2 | constructor(object) {
|
3 | super(object);
|
4 | Object.assign(this, object);
|
5 | }
|
6 | }
|
7 |
|
8 | class BaseProvider {
|
9 | |
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | constructor(url, {
|
17 | timeout = 5 * 60 * 1000,
|
18 | logger = { info: () => undefined, error: () => undefined },
|
19 | } = {}) {
|
20 | this.url = url;
|
21 | this.timeout = timeout;
|
22 | this.logger = logger;
|
23 | }
|
24 |
|
25 | |
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | requestId() {
|
32 | return `${Date.now()}${Math.random().toFixed(7).substring(2)}`;
|
33 | }
|
34 |
|
35 | async call() {
|
36 | throw new Error(`NotImplementError: ${this.constructor.name}.call not implement.`);
|
37 | }
|
38 |
|
39 | close() {}
|
40 | }
|
41 |
|
42 | module.exports = BaseProvider;
|
43 | module.exports.RPCError = RPCError;
|