@atomiqlabs/chain-starknet 4.0.0-dev.13 → 4.0.0-dev.14
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.
|
@@ -1,5 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare class
|
|
1
|
+
import { RPC08, RPC09, RpcProvider, RpcProviderOptions } from "starknet";
|
|
2
|
+
export declare class Rpc08ChannelWithRetries extends RPC08.RpcChannel {
|
|
3
|
+
readonly retryPolicy?: {
|
|
4
|
+
maxRetries?: number;
|
|
5
|
+
delay?: number;
|
|
6
|
+
exponential?: boolean;
|
|
7
|
+
};
|
|
8
|
+
constructor(options?: RpcProviderOptions, retryPolicy?: {
|
|
9
|
+
maxRetries?: number;
|
|
10
|
+
delay?: number;
|
|
11
|
+
exponential?: boolean;
|
|
12
|
+
});
|
|
13
|
+
protected fetchEndpoint(method: any, params?: any): Promise<any>;
|
|
14
|
+
}
|
|
15
|
+
export declare class Rpc09ChannelWithRetries extends RPC09.RpcChannel {
|
|
3
16
|
readonly retryPolicy?: {
|
|
4
17
|
maxRetries?: number;
|
|
5
18
|
delay?: number;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RpcProviderWithRetries = exports.
|
|
3
|
+
exports.RpcProviderWithRetries = exports.Rpc09ChannelWithRetries = exports.Rpc08ChannelWithRetries = void 0;
|
|
4
4
|
const starknet_1 = require("starknet");
|
|
5
5
|
const Utils_1 = require("../../utils/Utils");
|
|
6
|
-
class
|
|
6
|
+
class Rpc08ChannelWithRetries extends starknet_1.RPC08.RpcChannel {
|
|
7
7
|
constructor(options, retryPolicy) {
|
|
8
8
|
super(options);
|
|
9
9
|
this.retryPolicy = retryPolicy;
|
|
@@ -22,11 +22,38 @@ class RpcChannelWithRetries extends starknet_1.RpcChannel {
|
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
exports.
|
|
25
|
+
exports.Rpc08ChannelWithRetries = Rpc08ChannelWithRetries;
|
|
26
|
+
class Rpc09ChannelWithRetries extends starknet_1.RPC09.RpcChannel {
|
|
27
|
+
constructor(options, retryPolicy) {
|
|
28
|
+
super(options);
|
|
29
|
+
this.retryPolicy = retryPolicy;
|
|
30
|
+
}
|
|
31
|
+
fetchEndpoint(method, params) {
|
|
32
|
+
return (0, Utils_1.tryWithRetries)(() => super.fetchEndpoint(method, params), this.retryPolicy, e => {
|
|
33
|
+
if (!e.message.startsWith("RPC: "))
|
|
34
|
+
return false;
|
|
35
|
+
const arr = e.message.split("\n");
|
|
36
|
+
const errorCode = parseInt(arr[arr.length - 1]);
|
|
37
|
+
if (isNaN(errorCode))
|
|
38
|
+
return false;
|
|
39
|
+
if (errorCode < 0)
|
|
40
|
+
return false; //Not defined error, e.g. Rate limit (-32097)
|
|
41
|
+
return true;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.Rpc09ChannelWithRetries = Rpc09ChannelWithRetries;
|
|
26
46
|
class RpcProviderWithRetries extends starknet_1.RpcProvider {
|
|
27
47
|
constructor(options, retryPolicy) {
|
|
48
|
+
if (options.specVersion == null)
|
|
49
|
+
options.specVersion = options.nodeUrl.endsWith("v0_8") ? "0.8.1" : "0.9.0";
|
|
28
50
|
super(options);
|
|
29
|
-
this.channel
|
|
51
|
+
if (this.channel.id === "RPC081") {
|
|
52
|
+
this.channel = new Rpc08ChannelWithRetries({ ...options, waitMode: false }, retryPolicy);
|
|
53
|
+
}
|
|
54
|
+
else if (this.channel.id === "RPC090") {
|
|
55
|
+
this.channel = new Rpc09ChannelWithRetries({ ...options, waitMode: false }, retryPolicy);
|
|
56
|
+
}
|
|
30
57
|
}
|
|
31
58
|
}
|
|
32
59
|
exports.RpcProviderWithRetries = RpcProviderWithRetries;
|
package/package.json
CHANGED
|
@@ -1,11 +1,37 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
RPC08, RPC09,
|
|
3
3
|
RpcProvider,
|
|
4
4
|
RpcProviderOptions
|
|
5
5
|
} from "starknet";
|
|
6
6
|
import {tryWithRetries} from "../../utils/Utils";
|
|
7
7
|
|
|
8
|
-
export class
|
|
8
|
+
export class Rpc08ChannelWithRetries extends RPC08.RpcChannel {
|
|
9
|
+
|
|
10
|
+
readonly retryPolicy?: {
|
|
11
|
+
maxRetries?: number, delay?: number, exponential?: boolean
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
constructor(options?: RpcProviderOptions, retryPolicy?: {
|
|
15
|
+
maxRetries?: number, delay?: number, exponential?: boolean
|
|
16
|
+
}) {
|
|
17
|
+
super(options);
|
|
18
|
+
this.retryPolicy = retryPolicy;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
protected fetchEndpoint(method: any, params?: any): Promise<any> {
|
|
22
|
+
return tryWithRetries(() => super.fetchEndpoint(method, params), this.retryPolicy, e => {
|
|
23
|
+
if(!e.message.startsWith("RPC: ")) return false;
|
|
24
|
+
const arr = e.message.split("\n");
|
|
25
|
+
const errorCode = parseInt(arr[arr.length-1]);
|
|
26
|
+
if(isNaN(errorCode)) return false;
|
|
27
|
+
if(errorCode < 0) return false; //Not defined error, e.g. Rate limit (-32097)
|
|
28
|
+
return true;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class Rpc09ChannelWithRetries extends RPC09.RpcChannel {
|
|
9
35
|
|
|
10
36
|
readonly retryPolicy?: {
|
|
11
37
|
maxRetries?: number, delay?: number, exponential?: boolean
|
|
@@ -36,8 +62,13 @@ export class RpcProviderWithRetries extends RpcProvider {
|
|
|
36
62
|
constructor(options?: RpcProviderOptions, retryPolicy?: {
|
|
37
63
|
maxRetries?: number, delay?: number, exponential?: boolean
|
|
38
64
|
}) {
|
|
65
|
+
if(options.specVersion==null) options.specVersion = options.nodeUrl.endsWith("v0_8") ? "0.8.1" : "0.9.0";
|
|
39
66
|
super(options);
|
|
40
|
-
this.channel
|
|
67
|
+
if(this.channel.id==="RPC081") {
|
|
68
|
+
this.channel = new Rpc08ChannelWithRetries({ ...options, waitMode: false }, retryPolicy);
|
|
69
|
+
} else if(this.channel.id==="RPC090") {
|
|
70
|
+
this.channel = new Rpc09ChannelWithRetries({ ...options, waitMode: false }, retryPolicy);
|
|
71
|
+
}
|
|
41
72
|
}
|
|
42
73
|
|
|
43
74
|
}
|