@hardkas/kaspa-rpc 0.5.3-alpha → 0.5.4-alpha

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/index.d.ts CHANGED
@@ -106,6 +106,7 @@ interface RpcReadinessWaitOptions extends RpcHealthCheckOptions {
106
106
  }
107
107
  interface RpcHealthResult {
108
108
  readonly endpoint: string;
109
+ readonly protocol: string;
109
110
  readonly status: RpcHealthState;
110
111
  readonly ready: boolean;
111
112
  readonly checkedAt: string;
package/dist/index.js CHANGED
@@ -588,6 +588,7 @@ async function checkKaspaRpcHealth(options) {
588
588
  client2.disconnect();
589
589
  return {
590
590
  endpoint: url,
591
+ protocol: url.startsWith("ws") ? "WebSocket" : "JSON-RPC",
591
592
  status: "healthy",
592
593
  ready: true,
593
594
  checkedAt,
@@ -603,6 +604,7 @@ async function checkKaspaRpcHealth(options) {
603
604
  client2.disconnect();
604
605
  return {
605
606
  endpoint: url,
607
+ protocol: url.startsWith("ws") ? "WebSocket" : "JSON-RPC",
606
608
  status: "unreachable",
607
609
  ready: false,
608
610
  checkedAt,
@@ -616,6 +618,7 @@ async function checkKaspaRpcHealth(options) {
616
618
  const health = await client.healthCheck();
617
619
  return {
618
620
  endpoint: url,
621
+ protocol: "JSON-RPC",
619
622
  status: health.status,
620
623
  ready: health.status === "healthy" || health.status === "degraded",
621
624
  checkedAt,
@@ -632,6 +635,7 @@ async function checkKaspaRpcHealth(options) {
632
635
  } catch (e) {
633
636
  return {
634
637
  endpoint: url,
638
+ protocol: "JSON-RPC",
635
639
  status: "unreachable",
636
640
  ready: false,
637
641
  checkedAt,
@@ -641,7 +645,8 @@ async function checkKaspaRpcHealth(options) {
641
645
  }
642
646
  }
643
647
  async function waitForKaspaRpcReady(options) {
644
- const intervalMs = options?.intervalMs || 1e3;
648
+ let currentIntervalMs = options?.intervalMs || 250;
649
+ const maxIntervalMs = 2e3;
645
650
  const maxWaitMs = options?.maxWaitMs || 6e4;
646
651
  const start = Date.now();
647
652
  let lastResult;
@@ -653,10 +658,12 @@ async function waitForKaspaRpcReady(options) {
653
658
  if (lastResult.ready) {
654
659
  return lastResult;
655
660
  }
656
- await new Promise((resolve) => setTimeout(resolve, intervalMs));
661
+ await new Promise((resolve) => setTimeout(resolve, currentIntervalMs));
662
+ currentIntervalMs = Math.min(currentIntervalMs * 2, maxIntervalMs);
657
663
  }
658
664
  return lastResult || {
659
665
  endpoint: options?.url || "ws://127.0.0.1:18210",
666
+ protocol: (options?.url || "ws://127.0.0.1:18210").startsWith("ws") ? "WebSocket" : "JSON-RPC",
660
667
  status: "unreachable",
661
668
  ready: false,
662
669
  checkedAt: (/* @__PURE__ */ new Date()).toISOString(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hardkas/kaspa-rpc",
3
- "version": "0.5.3-alpha",
3
+ "version": "0.5.4-alpha",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -9,8 +9,8 @@
9
9
  },
10
10
  "dependencies": {
11
11
  "ws": "^8.18.0",
12
- "@hardkas/core": "0.5.3-alpha",
13
- "@hardkas/tx-builder": "0.5.3-alpha"
12
+ "@hardkas/core": "0.5.4-alpha",
13
+ "@hardkas/tx-builder": "0.5.4-alpha"
14
14
  },
15
15
  "devDependencies": {
16
16
  "@types/ws": "^8.5.13",