@chainflip/rpc 2.1.4 → 2.1.6

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 CHANGED
@@ -1,5 +1,7 @@
1
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
1
2
  const require_common = require('./common.cjs');
2
3
  let _chainflip_utils_async = require("@chainflip/utils/async");
4
+ let timers_promises = require("timers/promises");
3
5
 
4
6
  //#region src/Client.ts
5
7
  var Client = class {
@@ -7,10 +9,12 @@ var Client = class {
7
9
  timer = null;
8
10
  requestMap = /* @__PURE__ */ new Map();
9
11
  archiveNodeUrl;
12
+ retryOnHeaderNotFound;
10
13
  eventTarget = new EventTarget();
11
14
  constructor(url, opts = {}) {
12
15
  this.url = url;
13
16
  this.archiveNodeUrl = opts.archiveNodeUrl;
17
+ this.retryOnHeaderNotFound = opts.retryOnHeaderNotFound ?? false;
14
18
  }
15
19
  getRequestId() {
16
20
  try {
@@ -54,7 +58,7 @@ var Client = class {
54
58
  item.deferred.reject(/* @__PURE__ */ new Error("Could not find the result for the request"));
55
59
  });
56
60
  }
57
- sendRequest(method, ...params) {
61
+ enqueueRequest(method, params) {
58
62
  if (!require_common.rpcResult[method]) return Promise.reject(/* @__PURE__ */ new Error(`Unknown method: ${method}`));
59
63
  const deferred = (0, _chainflip_utils_async.deferredPromise)();
60
64
  const body = this.formatRequest(method, params);
@@ -67,19 +71,36 @@ var Client = class {
67
71
  this.timer = null;
68
72
  this.handleBatch();
69
73
  }, 0);
70
- return deferred.promise.catch((error) => {
71
- if (error instanceof Error) {
72
- if (this.archiveNodeUrl && error.message.includes("Unknown block: State already discarded")) {
73
- this.eventTarget.dispatchEvent(new CustomEvent("archiveNodeFallback", { detail: {
74
- method,
75
- params
76
- } }));
77
- return new this.constructor(this.archiveNodeUrl).sendRequest(method, ...params);
78
- }
79
- Error.captureStackTrace(error);
74
+ return deferred.promise;
75
+ }
76
+ async sendRequest(method, ...params) {
77
+ const retries = this.retryOnHeaderNotFound ? 5 : 0;
78
+ let lastError;
79
+ for (let i = 0; i <= retries; i += 1) {
80
+ const result = await this.enqueueRequest(method, params).then((value) => ({
81
+ ok: true,
82
+ value
83
+ }), (error) => ({
84
+ ok: false,
85
+ error
86
+ }));
87
+ if (result.ok) return result.value;
88
+ lastError = result.error;
89
+ if (i < retries && lastError.message.includes("Unknown block: Header was not found in the database")) {
90
+ await (0, timers_promises.setTimeout)(6e3);
91
+ continue;
80
92
  }
81
- throw error;
82
- });
93
+ break;
94
+ }
95
+ if (this.archiveNodeUrl && lastError.message.includes("Unknown block: State already discarded")) {
96
+ this.eventTarget.dispatchEvent(new CustomEvent("archiveNodeFallback", { detail: {
97
+ method,
98
+ params
99
+ } }));
100
+ return new this.constructor(this.archiveNodeUrl).sendRequest(method, ...params);
101
+ }
102
+ if (lastError instanceof Error) Error.captureStackTrace(lastError);
103
+ throw lastError;
83
104
  }
84
105
  methods() {
85
106
  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
- sendRequest(method, ...params) {
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.catch((error) => {
71
- if (error instanceof Error) {
72
- if (this.archiveNodeUrl && error.message.includes("Unknown block: State already discarded")) {
73
- this.eventTarget.dispatchEvent(new CustomEvent("archiveNodeFallback", { detail: {
74
- method,
75
- params
76
- } }));
77
- return new this.constructor(this.archiveNodeUrl).sendRequest(method, ...params);
78
- }
79
- Error.captureStackTrace(error);
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
- throw error;
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/WsClient.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
1
2
  const require_parsers = require('./parsers.cjs');
2
3
  require('./common.cjs');
3
4
  const require_Client = require('./Client.cjs');
@@ -1,5 +1,10 @@
1
1
  //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
3
8
  var __exportAll = (all, no_symbols) => {
4
9
  let target = {};
5
10
  for (var name in all) {
@@ -13,7 +18,26 @@ var __exportAll = (all, no_symbols) => {
13
18
  }
14
19
  return target;
15
20
  };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
24
+ key = keys[i];
25
+ if (!__hasOwnProp.call(to, key) && key !== except) {
26
+ __defProp(to, key, {
27
+ get: ((k) => from[k]).bind(null, key),
28
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
29
+ });
30
+ }
31
+ }
32
+ }
33
+ return to;
34
+ };
35
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
36
+ value: mod,
37
+ enumerable: true
38
+ }) : target, mod));
16
39
 
17
40
  //#endregion
18
41
 
19
- exports.__exportAll = __exportAll;
42
+ exports.__exportAll = __exportAll;
43
+ exports.__toESM = __toESM;
package/dist/common.cjs CHANGED
@@ -1,4 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
3
  const require_parsers = require('./parsers.cjs');
3
4
  let zod = require("zod");
4
5
 
@@ -50,7 +51,8 @@ const rpcResult = {
50
51
  cf_lending_config: require_parsers.cfLendingConfig,
51
52
  cf_loan_accounts: require_parsers.cfLoanAccounts,
52
53
  cf_lending_pool_supply_balances: require_parsers.cfLendingPoolSupplyBalances,
53
- cf_get_vault_addresses: require_parsers.cfVaultAddresses
54
+ cf_get_vault_addresses: require_parsers.cfVaultAddresses,
55
+ cf_ingress_egress_events: require_parsers.cfIngressEgressEvents
54
56
  };
55
57
 
56
58
  //#endregion