@hardkas/kaspa-rpc 0.9.0-alpha → 0.9.2-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.js +56 -25
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -232,8 +232,8 @@ var KaspaJsonRpcClient = class {
|
|
|
232
232
|
reachable: false,
|
|
233
233
|
rpcUrl: this.url,
|
|
234
234
|
status: "unavailable",
|
|
235
|
-
error: e.message,
|
|
236
|
-
lastError: this.lastError || e.message,
|
|
235
|
+
error: e instanceof Error ? e instanceof Error ? e instanceof Error ? e.message : String(e) : String(e) : String(e),
|
|
236
|
+
lastError: this.lastError || (e instanceof Error ? e instanceof Error ? e instanceof Error ? e.message : String(e) : String(e) : String(e)),
|
|
237
237
|
successRate: this.getSuccessRate(),
|
|
238
238
|
circuitState: this.circuitState,
|
|
239
239
|
confidence: resilience.confidence,
|
|
@@ -345,8 +345,10 @@ var KaspaJsonRpcClient = class {
|
|
|
345
345
|
}
|
|
346
346
|
if (txAny.inputs && Array.isArray(txAny.inputs)) {
|
|
347
347
|
txAny.inputs.forEach((input) => {
|
|
348
|
-
if (typeof input.sequence === "string")
|
|
349
|
-
|
|
348
|
+
if (typeof input.sequence === "string")
|
|
349
|
+
input.sequence = Number(input.sequence);
|
|
350
|
+
if (typeof input.sigOpCount === "string")
|
|
351
|
+
input.sigOpCount = Number(input.sigOpCount);
|
|
350
352
|
});
|
|
351
353
|
}
|
|
352
354
|
}
|
|
@@ -392,7 +394,7 @@ var KaspaJsonRpcClient = class {
|
|
|
392
394
|
coreEvents.normalizeAndEmit({
|
|
393
395
|
kind: "rpc.error",
|
|
394
396
|
endpoint: this.url,
|
|
395
|
-
error: e.message,
|
|
397
|
+
error: e instanceof Error ? e instanceof Error ? e instanceof Error ? e.message : String(e) : String(e) : String(e),
|
|
396
398
|
retriable: isRetriable
|
|
397
399
|
});
|
|
398
400
|
if (attempt < this.retry.maxRetries && isRetriable) {
|
|
@@ -402,7 +404,8 @@ var KaspaJsonRpcClient = class {
|
|
|
402
404
|
throw e;
|
|
403
405
|
}
|
|
404
406
|
if (this.isDeterministicError(e)) {
|
|
405
|
-
|
|
407
|
+
const err = e;
|
|
408
|
+
throw new RpcValidationError(err instanceof Error ? err instanceof Error ? err.message : String(err) : String(err), err.code, err.data);
|
|
406
409
|
}
|
|
407
410
|
if (attempt === this.retry.maxRetries) break;
|
|
408
411
|
const delay = Math.min(
|
|
@@ -444,7 +447,7 @@ var KaspaJsonRpcClient = class {
|
|
|
444
447
|
return body.result;
|
|
445
448
|
} catch (e) {
|
|
446
449
|
clearTimeout(id);
|
|
447
|
-
if (e.name === "AbortError") throw new RpcTimeoutError();
|
|
450
|
+
if (e instanceof Error && e.name === "AbortError") throw new RpcTimeoutError();
|
|
448
451
|
throw e;
|
|
449
452
|
}
|
|
450
453
|
}
|
|
@@ -463,7 +466,7 @@ var KaspaJsonRpcClient = class {
|
|
|
463
466
|
this.circuitState = "CLOSED" /* CLOSED */;
|
|
464
467
|
}
|
|
465
468
|
onFailure(e) {
|
|
466
|
-
this.lastError = e.message;
|
|
469
|
+
this.lastError = e instanceof Error ? e instanceof Error ? e.message : String(e) : String(e);
|
|
467
470
|
if (e instanceof RpcValidationError || e instanceof RpcError && !e.isRetriable) {
|
|
468
471
|
return;
|
|
469
472
|
}
|
|
@@ -474,7 +477,7 @@ var KaspaJsonRpcClient = class {
|
|
|
474
477
|
}
|
|
475
478
|
}
|
|
476
479
|
isDeterministicError(e) {
|
|
477
|
-
const msg = (e.message || "").toLowerCase();
|
|
480
|
+
const msg = ((e instanceof Error ? e instanceof Error ? e.message : String(e) : String(e)) || "").toLowerCase();
|
|
478
481
|
const deterministicMarkers = [
|
|
479
482
|
"invalid address",
|
|
480
483
|
"insufficient funds",
|
|
@@ -538,7 +541,7 @@ var KaspaWrpcClient = class {
|
|
|
538
541
|
});
|
|
539
542
|
this.ws.on("error", (err) => {
|
|
540
543
|
clearTimeout(timer);
|
|
541
|
-
reject(new Error(`WebSocket error: ${err.message}`));
|
|
544
|
+
reject(new Error(`WebSocket error: ${err instanceof Error ? err instanceof Error ? err.message : String(err) : String(err)}`));
|
|
542
545
|
});
|
|
543
546
|
this.ws.on("message", (data) => {
|
|
544
547
|
try {
|
|
@@ -669,8 +672,8 @@ async function checkKaspaRpcHealth(options) {
|
|
|
669
672
|
status: "unreachable",
|
|
670
673
|
ready: false,
|
|
671
674
|
checkedAt,
|
|
672
|
-
error: e.message,
|
|
673
|
-
lastError: e.message
|
|
675
|
+
error: e instanceof Error ? e instanceof Error ? e instanceof Error ? e.message : String(e) : String(e) : String(e),
|
|
676
|
+
lastError: e instanceof Error ? e instanceof Error ? e instanceof Error ? e.message : String(e) : String(e) : String(e)
|
|
674
677
|
};
|
|
675
678
|
}
|
|
676
679
|
}
|
|
@@ -700,8 +703,8 @@ async function checkKaspaRpcHealth(options) {
|
|
|
700
703
|
status: "unreachable",
|
|
701
704
|
ready: false,
|
|
702
705
|
checkedAt,
|
|
703
|
-
error: e.message,
|
|
704
|
-
lastError: e.message
|
|
706
|
+
error: e instanceof Error ? e instanceof Error ? e instanceof Error ? e.message : String(e) : String(e) : String(e),
|
|
707
|
+
lastError: e instanceof Error ? e instanceof Error ? e instanceof Error ? e.message : String(e) : String(e) : String(e)
|
|
705
708
|
};
|
|
706
709
|
}
|
|
707
710
|
}
|
|
@@ -832,7 +835,8 @@ var JsonWrpcKaspaClient = class {
|
|
|
832
835
|
const res = await this.requestRaw("getServerInfo", {});
|
|
833
836
|
this.rpcFlavor = "wrpc";
|
|
834
837
|
} catch (e) {
|
|
835
|
-
|
|
838
|
+
const errMsg = e instanceof Error ? e instanceof Error ? e instanceof Error ? e.message : String(e) : String(e) : String(e);
|
|
839
|
+
if (errMsg.includes("Method not found")) {
|
|
836
840
|
this.rpcFlavor = "legacy";
|
|
837
841
|
} else {
|
|
838
842
|
this.rpcFlavor = "wrpc";
|
|
@@ -851,7 +855,10 @@ var JsonWrpcKaspaClient = class {
|
|
|
851
855
|
const info = mapKaspaNodeInfo(response);
|
|
852
856
|
if (info.virtualDaaScore === void 0) {
|
|
853
857
|
try {
|
|
854
|
-
const dagResponse = await this.callMethod(
|
|
858
|
+
const dagResponse = await this.callMethod(
|
|
859
|
+
"getBlockDagInfo",
|
|
860
|
+
"getBlockDagInfoRequest"
|
|
861
|
+
);
|
|
855
862
|
const dagData = dagResponse?.params || dagResponse;
|
|
856
863
|
if (dagData && typeof dagData === "object" && "virtualDaaScore" in dagData) {
|
|
857
864
|
info.virtualDaaScore = BigInt(dagData.virtualDaaScore);
|
|
@@ -883,14 +890,26 @@ var JsonWrpcKaspaClient = class {
|
|
|
883
890
|
await this.detectFlavor();
|
|
884
891
|
let response;
|
|
885
892
|
if (this.rpcFlavor === "legacy") {
|
|
886
|
-
response = await this.callMethod(
|
|
893
|
+
response = await this.callMethod(
|
|
894
|
+
"getBalanceByAddress",
|
|
895
|
+
"getBalanceByAddressRequest",
|
|
896
|
+
{ address }
|
|
897
|
+
);
|
|
887
898
|
} else {
|
|
888
|
-
response = await this.callMethod(
|
|
899
|
+
response = await this.callMethod(
|
|
900
|
+
"getBalancesByAddresses",
|
|
901
|
+
"getBalancesByAddressesRequest",
|
|
902
|
+
{ addresses: [address] }
|
|
903
|
+
);
|
|
889
904
|
}
|
|
890
905
|
return mapKaspaAddressBalance(response, address);
|
|
891
906
|
}
|
|
892
907
|
async getUtxosByAddress(address) {
|
|
893
|
-
const response = await this.callMethod(
|
|
908
|
+
const response = await this.callMethod(
|
|
909
|
+
"getUtxosByAddresses",
|
|
910
|
+
"getUtxosByAddressesRequest",
|
|
911
|
+
{ addresses: [address] }
|
|
912
|
+
);
|
|
894
913
|
return mapKaspaRpcUtxos(response, address);
|
|
895
914
|
}
|
|
896
915
|
async submitTransaction(rawTransaction) {
|
|
@@ -931,19 +950,29 @@ var JsonWrpcKaspaClient = class {
|
|
|
931
950
|
}
|
|
932
951
|
if (txAny.inputs && Array.isArray(txAny.inputs)) {
|
|
933
952
|
txAny.inputs.forEach((input) => {
|
|
934
|
-
if (typeof input.sequence === "string")
|
|
935
|
-
|
|
953
|
+
if (typeof input.sequence === "string")
|
|
954
|
+
input.sequence = Number(input.sequence);
|
|
955
|
+
if (typeof input.sigOpCount === "string")
|
|
956
|
+
input.sigOpCount = Number(input.sigOpCount);
|
|
936
957
|
});
|
|
937
958
|
}
|
|
938
959
|
}
|
|
939
960
|
} catch (e) {
|
|
940
961
|
}
|
|
941
|
-
const response = await this.callMethod(
|
|
962
|
+
const response = await this.callMethod(
|
|
963
|
+
"submitTransaction",
|
|
964
|
+
"submitTransactionRequest",
|
|
965
|
+
{ transaction: txObj, allowOrphan: false }
|
|
966
|
+
);
|
|
942
967
|
return mapKaspaSubmitTransactionResult(response);
|
|
943
968
|
}
|
|
944
969
|
async getMempoolEntry(txId) {
|
|
945
970
|
try {
|
|
946
|
-
const response = await this.callMethod(
|
|
971
|
+
const response = await this.callMethod(
|
|
972
|
+
"getMempoolEntry",
|
|
973
|
+
"getMempoolEntryRequest",
|
|
974
|
+
{ transactionId: txId, includeOrphanPool: true, filterTransactionPool: false }
|
|
975
|
+
);
|
|
947
976
|
if (!response) return null;
|
|
948
977
|
const resObj = response;
|
|
949
978
|
return {
|
|
@@ -956,7 +985,9 @@ var JsonWrpcKaspaClient = class {
|
|
|
956
985
|
}
|
|
957
986
|
async getTransaction(txId) {
|
|
958
987
|
try {
|
|
959
|
-
return await this.callMethod("getTransaction", "getTransactionRequest", {
|
|
988
|
+
return await this.callMethod("getTransaction", "getTransactionRequest", {
|
|
989
|
+
transactionId: txId
|
|
990
|
+
});
|
|
960
991
|
} catch (e) {
|
|
961
992
|
return null;
|
|
962
993
|
}
|
|
@@ -1012,7 +1043,7 @@ var JsonWrpcKaspaClient = class {
|
|
|
1012
1043
|
cleanup();
|
|
1013
1044
|
if (response.error) {
|
|
1014
1045
|
const err = response.error;
|
|
1015
|
-
const msg = err.message || (typeof err === "string" ? err : JSON.stringify(err));
|
|
1046
|
+
const msg = (err instanceof Error ? err instanceof Error ? err.message : String(err) : String(err)) || (typeof err === "string" ? err : JSON.stringify(err));
|
|
1016
1047
|
reject(new Error(msg));
|
|
1017
1048
|
} else {
|
|
1018
1049
|
resolve(response.result !== void 0 ? response.result : response.params);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hardkas/kaspa-rpc",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2-alpha",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"ws": "^8.18.0",
|
|
16
|
-
"@hardkas/core": "0.9.
|
|
17
|
-
"@hardkas/tx-builder": "0.9.
|
|
16
|
+
"@hardkas/core": "0.9.2-alpha",
|
|
17
|
+
"@hardkas/tx-builder": "0.9.2-alpha"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@types/ws": "^8.5.13",
|