@chainflip/rpc 2.1.3 → 2.1.5
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/dist/Client.cjs +33 -13
- package/dist/Client.d.cts +3 -0
- package/dist/Client.d.mts +3 -0
- package/dist/Client.mjs +33 -13
- package/dist/common.cjs +2 -1
- package/dist/common.d.cts +856 -6
- package/dist/common.d.mts +856 -6
- package/dist/common.mjs +3 -2
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/parsers.cjs +63 -1
- package/dist/parsers.d.cts +850 -1
- package/dist/parsers.d.mts +850 -1
- package/dist/parsers.mjs +63 -2
- package/dist/types.d.cts +3 -1
- package/dist/types.d.mts +3 -1
- package/package.json +3 -3
package/dist/Client.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_common = require('./common.cjs');
|
|
2
2
|
let _chainflip_utils_async = require("@chainflip/utils/async");
|
|
3
|
+
let timers_promises = require("timers/promises");
|
|
3
4
|
|
|
4
5
|
//#region src/Client.ts
|
|
5
6
|
var Client = class {
|
|
@@ -7,10 +8,12 @@ var Client = class {
|
|
|
7
8
|
timer = null;
|
|
8
9
|
requestMap = /* @__PURE__ */ new Map();
|
|
9
10
|
archiveNodeUrl;
|
|
11
|
+
retryOnHeaderNotFound;
|
|
10
12
|
eventTarget = new EventTarget();
|
|
11
13
|
constructor(url, opts = {}) {
|
|
12
14
|
this.url = url;
|
|
13
15
|
this.archiveNodeUrl = opts.archiveNodeUrl;
|
|
16
|
+
this.retryOnHeaderNotFound = opts.retryOnHeaderNotFound ?? false;
|
|
14
17
|
}
|
|
15
18
|
getRequestId() {
|
|
16
19
|
try {
|
|
@@ -54,7 +57,7 @@ var Client = class {
|
|
|
54
57
|
item.deferred.reject(/* @__PURE__ */ new Error("Could not find the result for the request"));
|
|
55
58
|
});
|
|
56
59
|
}
|
|
57
|
-
|
|
60
|
+
enqueueRequest(method, params) {
|
|
58
61
|
if (!require_common.rpcResult[method]) return Promise.reject(/* @__PURE__ */ new Error(`Unknown method: ${method}`));
|
|
59
62
|
const deferred = (0, _chainflip_utils_async.deferredPromise)();
|
|
60
63
|
const body = this.formatRequest(method, params);
|
|
@@ -67,19 +70,36 @@ var Client = class {
|
|
|
67
70
|
this.timer = null;
|
|
68
71
|
this.handleBatch();
|
|
69
72
|
}, 0);
|
|
70
|
-
return deferred.promise
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
73
|
+
return deferred.promise;
|
|
74
|
+
}
|
|
75
|
+
async sendRequest(method, ...params) {
|
|
76
|
+
const retries = this.retryOnHeaderNotFound ? 5 : 0;
|
|
77
|
+
let lastError;
|
|
78
|
+
for (let i = 0; i <= retries; i += 1) {
|
|
79
|
+
const result = await this.enqueueRequest(method, params).then((value) => ({
|
|
80
|
+
ok: true,
|
|
81
|
+
value
|
|
82
|
+
}), (error) => ({
|
|
83
|
+
ok: false,
|
|
84
|
+
error
|
|
85
|
+
}));
|
|
86
|
+
if (result.ok) return result.value;
|
|
87
|
+
lastError = result.error;
|
|
88
|
+
if (i < retries && lastError.message.includes("Unknown block: Header was not found in the database")) {
|
|
89
|
+
await (0, timers_promises.setTimeout)(6e3);
|
|
90
|
+
continue;
|
|
80
91
|
}
|
|
81
|
-
|
|
82
|
-
}
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
if (this.archiveNodeUrl && lastError.message.includes("Unknown block: State already discarded")) {
|
|
95
|
+
this.eventTarget.dispatchEvent(new CustomEvent("archiveNodeFallback", { detail: {
|
|
96
|
+
method,
|
|
97
|
+
params
|
|
98
|
+
} }));
|
|
99
|
+
return new this.constructor(this.archiveNodeUrl).sendRequest(method, ...params);
|
|
100
|
+
}
|
|
101
|
+
if (lastError instanceof Error) Error.captureStackTrace(lastError);
|
|
102
|
+
throw lastError;
|
|
83
103
|
}
|
|
84
104
|
methods() {
|
|
85
105
|
return Object.keys(require_common.rpcResult).sort();
|
package/dist/Client.d.cts
CHANGED
|
@@ -18,6 +18,7 @@ type RequestMap = Map<string, {
|
|
|
18
18
|
}>;
|
|
19
19
|
type ClientOpts = {
|
|
20
20
|
archiveNodeUrl?: string;
|
|
21
|
+
retryOnHeaderNotFound?: boolean;
|
|
21
22
|
};
|
|
22
23
|
declare abstract class Client {
|
|
23
24
|
protected readonly url: string;
|
|
@@ -25,6 +26,7 @@ declare abstract class Client {
|
|
|
25
26
|
private timer;
|
|
26
27
|
private requestMap;
|
|
27
28
|
private readonly archiveNodeUrl?;
|
|
29
|
+
private readonly retryOnHeaderNotFound;
|
|
28
30
|
readonly eventTarget: EventTarget;
|
|
29
31
|
constructor(url: string, opts?: ClientOpts);
|
|
30
32
|
protected abstract send<const T extends RpcMethod>(data: JsonRpcRequest<T>[], clonedMap: RequestMap): Promise<void>;
|
|
@@ -33,6 +35,7 @@ declare abstract class Client {
|
|
|
33
35
|
protected handleResponse(response: Response, clonedMap: RequestMap): void;
|
|
34
36
|
protected handleErrorResponse(error: Error, clonedMap: RequestMap): void;
|
|
35
37
|
private handleBatch;
|
|
38
|
+
private enqueueRequest;
|
|
36
39
|
sendRequest<const T extends RpcMethod>(method: T, ...params: RpcRequest[T]): Promise<RpcResult<T>>;
|
|
37
40
|
methods(): RpcMethod[];
|
|
38
41
|
}
|
package/dist/Client.d.mts
CHANGED
|
@@ -18,6 +18,7 @@ type RequestMap = Map<string, {
|
|
|
18
18
|
}>;
|
|
19
19
|
type ClientOpts = {
|
|
20
20
|
archiveNodeUrl?: string;
|
|
21
|
+
retryOnHeaderNotFound?: boolean;
|
|
21
22
|
};
|
|
22
23
|
declare abstract class Client {
|
|
23
24
|
protected readonly url: string;
|
|
@@ -25,6 +26,7 @@ declare abstract class Client {
|
|
|
25
26
|
private timer;
|
|
26
27
|
private requestMap;
|
|
27
28
|
private readonly archiveNodeUrl?;
|
|
29
|
+
private readonly retryOnHeaderNotFound;
|
|
28
30
|
readonly eventTarget: EventTarget;
|
|
29
31
|
constructor(url: string, opts?: ClientOpts);
|
|
30
32
|
protected abstract send<const T extends RpcMethod>(data: JsonRpcRequest<T>[], clonedMap: RequestMap): Promise<void>;
|
|
@@ -33,6 +35,7 @@ declare abstract class Client {
|
|
|
33
35
|
protected handleResponse(response: Response, clonedMap: RequestMap): void;
|
|
34
36
|
protected handleErrorResponse(error: Error, clonedMap: RequestMap): void;
|
|
35
37
|
private handleBatch;
|
|
38
|
+
private enqueueRequest;
|
|
36
39
|
sendRequest<const T extends RpcMethod>(method: T, ...params: RpcRequest[T]): Promise<RpcResult<T>>;
|
|
37
40
|
methods(): RpcMethod[];
|
|
38
41
|
}
|
package/dist/Client.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { rpcResult } from "./common.mjs";
|
|
2
2
|
import { deferredPromise } from "@chainflip/utils/async";
|
|
3
|
+
import { setTimeout as setTimeout$1 } from "timers/promises";
|
|
3
4
|
|
|
4
5
|
//#region src/Client.ts
|
|
5
6
|
var Client = class {
|
|
@@ -7,10 +8,12 @@ var Client = class {
|
|
|
7
8
|
timer = null;
|
|
8
9
|
requestMap = /* @__PURE__ */ new Map();
|
|
9
10
|
archiveNodeUrl;
|
|
11
|
+
retryOnHeaderNotFound;
|
|
10
12
|
eventTarget = new EventTarget();
|
|
11
13
|
constructor(url, opts = {}) {
|
|
12
14
|
this.url = url;
|
|
13
15
|
this.archiveNodeUrl = opts.archiveNodeUrl;
|
|
16
|
+
this.retryOnHeaderNotFound = opts.retryOnHeaderNotFound ?? false;
|
|
14
17
|
}
|
|
15
18
|
getRequestId() {
|
|
16
19
|
try {
|
|
@@ -54,7 +57,7 @@ var Client = class {
|
|
|
54
57
|
item.deferred.reject(/* @__PURE__ */ new Error("Could not find the result for the request"));
|
|
55
58
|
});
|
|
56
59
|
}
|
|
57
|
-
|
|
60
|
+
enqueueRequest(method, params) {
|
|
58
61
|
if (!rpcResult[method]) return Promise.reject(/* @__PURE__ */ new Error(`Unknown method: ${method}`));
|
|
59
62
|
const deferred = deferredPromise();
|
|
60
63
|
const body = this.formatRequest(method, params);
|
|
@@ -67,19 +70,36 @@ var Client = class {
|
|
|
67
70
|
this.timer = null;
|
|
68
71
|
this.handleBatch();
|
|
69
72
|
}, 0);
|
|
70
|
-
return deferred.promise
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
73
|
+
return deferred.promise;
|
|
74
|
+
}
|
|
75
|
+
async sendRequest(method, ...params) {
|
|
76
|
+
const retries = this.retryOnHeaderNotFound ? 5 : 0;
|
|
77
|
+
let lastError;
|
|
78
|
+
for (let i = 0; i <= retries; i += 1) {
|
|
79
|
+
const result = await this.enqueueRequest(method, params).then((value) => ({
|
|
80
|
+
ok: true,
|
|
81
|
+
value
|
|
82
|
+
}), (error) => ({
|
|
83
|
+
ok: false,
|
|
84
|
+
error
|
|
85
|
+
}));
|
|
86
|
+
if (result.ok) return result.value;
|
|
87
|
+
lastError = result.error;
|
|
88
|
+
if (i < retries && lastError.message.includes("Unknown block: Header was not found in the database")) {
|
|
89
|
+
await setTimeout$1(6e3);
|
|
90
|
+
continue;
|
|
80
91
|
}
|
|
81
|
-
|
|
82
|
-
}
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
if (this.archiveNodeUrl && lastError.message.includes("Unknown block: State already discarded")) {
|
|
95
|
+
this.eventTarget.dispatchEvent(new CustomEvent("archiveNodeFallback", { detail: {
|
|
96
|
+
method,
|
|
97
|
+
params
|
|
98
|
+
} }));
|
|
99
|
+
return new this.constructor(this.archiveNodeUrl).sendRequest(method, ...params);
|
|
100
|
+
}
|
|
101
|
+
if (lastError instanceof Error) Error.captureStackTrace(lastError);
|
|
102
|
+
throw lastError;
|
|
83
103
|
}
|
|
84
104
|
methods() {
|
|
85
105
|
return Object.keys(rpcResult).sort();
|
package/dist/common.cjs
CHANGED
|
@@ -50,7 +50,8 @@ const rpcResult = {
|
|
|
50
50
|
cf_lending_config: require_parsers.cfLendingConfig,
|
|
51
51
|
cf_loan_accounts: require_parsers.cfLoanAccounts,
|
|
52
52
|
cf_lending_pool_supply_balances: require_parsers.cfLendingPoolSupplyBalances,
|
|
53
|
-
cf_get_vault_addresses: require_parsers.cfVaultAddresses
|
|
53
|
+
cf_get_vault_addresses: require_parsers.cfVaultAddresses,
|
|
54
|
+
cf_ingress_egress_events: require_parsers.cfIngressEgressEvents
|
|
54
55
|
};
|
|
55
56
|
|
|
56
57
|
//#endregion
|