@hardkas/kaspa-rpc 0.7.3-alpha → 0.7.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.js +99 -22
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -52,7 +52,12 @@ function calculateConfidence(metrics) {
|
|
|
52
52
|
const issues = [];
|
|
53
53
|
let score = 100;
|
|
54
54
|
if (!metrics.reachable) {
|
|
55
|
-
return {
|
|
55
|
+
return {
|
|
56
|
+
state: "unreachable",
|
|
57
|
+
confidence: "low",
|
|
58
|
+
score: 0,
|
|
59
|
+
issues: ["Endpoint is unreachable"]
|
|
60
|
+
};
|
|
56
61
|
}
|
|
57
62
|
if (metrics.circuitOpen) {
|
|
58
63
|
score -= 50;
|
|
@@ -244,7 +249,8 @@ var KaspaJsonRpcClient = class {
|
|
|
244
249
|
networkId: String(data.networkId),
|
|
245
250
|
isSynced: Boolean(data.isSynced)
|
|
246
251
|
};
|
|
247
|
-
if (data.virtualDaaScore !== void 0)
|
|
252
|
+
if (data.virtualDaaScore !== void 0)
|
|
253
|
+
info.virtualDaaScore = BigInt(data.virtualDaaScore);
|
|
248
254
|
if (data.mempoolSize !== void 0) info.mempoolSize = Number(data.mempoolSize);
|
|
249
255
|
return info;
|
|
250
256
|
}
|
|
@@ -258,7 +264,9 @@ var KaspaJsonRpcClient = class {
|
|
|
258
264
|
return dagInfo;
|
|
259
265
|
}
|
|
260
266
|
async getUtxosByAddress(address) {
|
|
261
|
-
const data = await this.callRpc("getUtxosByAddressesRequest", {
|
|
267
|
+
const data = await this.callRpc("getUtxosByAddressesRequest", {
|
|
268
|
+
addresses: [address]
|
|
269
|
+
});
|
|
262
270
|
const entries = data.entries || [];
|
|
263
271
|
return entries.map((e) => ({
|
|
264
272
|
address: e.address,
|
|
@@ -281,7 +289,10 @@ var KaspaJsonRpcClient = class {
|
|
|
281
289
|
}
|
|
282
290
|
async getMempoolEntry(txId) {
|
|
283
291
|
try {
|
|
284
|
-
const result = await this.callRpc("getMempoolEntryRequest", {
|
|
292
|
+
const result = await this.callRpc("getMempoolEntryRequest", {
|
|
293
|
+
txId,
|
|
294
|
+
includeOrphanPool: true
|
|
295
|
+
});
|
|
285
296
|
return {
|
|
286
297
|
txId,
|
|
287
298
|
acceptedAt: String(result.entry.acceptedAt)
|
|
@@ -299,7 +310,9 @@ var KaspaJsonRpcClient = class {
|
|
|
299
310
|
}
|
|
300
311
|
}
|
|
301
312
|
async submitTransaction(rawTx) {
|
|
302
|
-
const result = await this.callRpc("submitTransactionRequest", {
|
|
313
|
+
const result = await this.callRpc("submitTransactionRequest", {
|
|
314
|
+
transaction: rawTx
|
|
315
|
+
});
|
|
303
316
|
return { transactionId: result.transactionId };
|
|
304
317
|
}
|
|
305
318
|
async getServerInfo() {
|
|
@@ -465,7 +478,9 @@ var KaspaWrpcClient = class {
|
|
|
465
478
|
return new Promise((resolve, reject) => {
|
|
466
479
|
const timer = setTimeout(() => {
|
|
467
480
|
this.disconnect();
|
|
468
|
-
reject(
|
|
481
|
+
reject(
|
|
482
|
+
new Error(`WebSocket connection timeout after ${timeoutMs}ms to ${this.url}`)
|
|
483
|
+
);
|
|
469
484
|
}, timeoutMs);
|
|
470
485
|
try {
|
|
471
486
|
this.ws = new WebSocket(this.url);
|
|
@@ -499,7 +514,10 @@ var KaspaWrpcClient = class {
|
|
|
499
514
|
}
|
|
500
515
|
} catch (parseErr) {
|
|
501
516
|
if (this.debug) {
|
|
502
|
-
console.debug(
|
|
517
|
+
console.debug(
|
|
518
|
+
"[wRPC] Non-JSON message received:",
|
|
519
|
+
data.toString().slice(0, 200)
|
|
520
|
+
);
|
|
503
521
|
}
|
|
504
522
|
}
|
|
505
523
|
});
|
|
@@ -690,7 +708,9 @@ var LoadBalancedRpcProvider = class {
|
|
|
690
708
|
const healths = await Promise.all(this.clients.map((c) => c.healthCheck()));
|
|
691
709
|
const primaryHealth = healths[this.currentIndex];
|
|
692
710
|
const allHealthy = healths.every((h) => h.status === "healthy");
|
|
693
|
-
const anyHealthy = healths.some(
|
|
711
|
+
const anyHealthy = healths.some(
|
|
712
|
+
(h) => h.status === "healthy" || h.status === "degraded"
|
|
713
|
+
);
|
|
694
714
|
return {
|
|
695
715
|
endpoint: `LoadBalancedProvider(${this.clients.length} nodes)`,
|
|
696
716
|
status: allHealthy ? "healthy" : anyHealthy ? "degraded" : "unreachable",
|
|
@@ -759,14 +779,26 @@ var JsonWrpcKaspaClient = class {
|
|
|
759
779
|
this.timeoutMs = options.timeoutMs ?? 1e4;
|
|
760
780
|
}
|
|
761
781
|
async getInfo() {
|
|
762
|
-
const response = await this.safeRequest([
|
|
782
|
+
const response = await this.safeRequest([
|
|
783
|
+
"getInfo",
|
|
784
|
+
"getInfoRequest",
|
|
785
|
+
"GetInfo",
|
|
786
|
+
"get_info"
|
|
787
|
+
]);
|
|
763
788
|
const info = mapKaspaNodeInfo(response);
|
|
764
789
|
if (info.virtualDaaScore === void 0) {
|
|
765
790
|
try {
|
|
766
|
-
const dagResponse = await this.safeRequest([
|
|
791
|
+
const dagResponse = await this.safeRequest([
|
|
792
|
+
"getBlockDagInfo",
|
|
793
|
+
"getBlockDagInfoRequest",
|
|
794
|
+
"GetBlockDagInfo",
|
|
795
|
+
"get_block_dag_info"
|
|
796
|
+
]);
|
|
767
797
|
const dagData = dagResponse?.params || dagResponse;
|
|
768
798
|
if (dagData && typeof dagData === "object" && "virtualDaaScore" in dagData) {
|
|
769
|
-
info.virtualDaaScore = BigInt(
|
|
799
|
+
info.virtualDaaScore = BigInt(
|
|
800
|
+
dagData.virtualDaaScore
|
|
801
|
+
);
|
|
770
802
|
}
|
|
771
803
|
} catch (e) {
|
|
772
804
|
}
|
|
@@ -793,21 +825,44 @@ var JsonWrpcKaspaClient = class {
|
|
|
793
825
|
}
|
|
794
826
|
async getBalanceByAddress(address) {
|
|
795
827
|
const response = await this.safeRequest(
|
|
796
|
-
[
|
|
828
|
+
[
|
|
829
|
+
"getBalancesByAddresses",
|
|
830
|
+
"getBalancesByAddressesRequest",
|
|
831
|
+
"getBalanceByAddressRequest",
|
|
832
|
+
"GetBalancesByAddresses",
|
|
833
|
+
"get_balances_by_addresses",
|
|
834
|
+
"GetBalanceByAddress",
|
|
835
|
+
"getBalanceByAddress",
|
|
836
|
+
"get_balance_by_address"
|
|
837
|
+
],
|
|
797
838
|
{ addresses: [address], address }
|
|
798
839
|
);
|
|
799
840
|
return mapKaspaAddressBalance(response, address);
|
|
800
841
|
}
|
|
801
842
|
async getUtxosByAddress(address) {
|
|
802
843
|
const response = await this.safeRequest(
|
|
803
|
-
[
|
|
844
|
+
[
|
|
845
|
+
"getUtxosByAddresses",
|
|
846
|
+
"getUtxosByAddressesRequest",
|
|
847
|
+
"getUtxosByAddressRequest",
|
|
848
|
+
"GetUtxosByAddresses",
|
|
849
|
+
"get_utxos_by_addresses",
|
|
850
|
+
"GetUtxosByAddress",
|
|
851
|
+
"getUtxosByAddress",
|
|
852
|
+
"get_utxos_by_address"
|
|
853
|
+
],
|
|
804
854
|
{ addresses: [address], address }
|
|
805
855
|
);
|
|
806
856
|
return mapKaspaRpcUtxos(response, address);
|
|
807
857
|
}
|
|
808
858
|
async submitTransaction(rawTransaction) {
|
|
809
859
|
const response = await this.safeRequest(
|
|
810
|
-
[
|
|
860
|
+
[
|
|
861
|
+
"submitTransaction",
|
|
862
|
+
"submitTransactionRequest",
|
|
863
|
+
"SubmitTransaction",
|
|
864
|
+
"submit_transaction"
|
|
865
|
+
],
|
|
811
866
|
{ transaction: rawTransaction, transactionHex: rawTransaction, rawTransaction }
|
|
812
867
|
);
|
|
813
868
|
return mapKaspaSubmitTransactionResult(response);
|
|
@@ -955,7 +1010,11 @@ var JsonWrpcKaspaClient = class {
|
|
|
955
1010
|
const ws = new WebSocket2(this.rpcUrl);
|
|
956
1011
|
const timeout = setTimeout(() => {
|
|
957
1012
|
ws.close();
|
|
958
|
-
reject(
|
|
1013
|
+
reject(
|
|
1014
|
+
new Error(
|
|
1015
|
+
`Cannot connect to Kaspa RPC at ${this.rpcUrl}. Connection timed out.`
|
|
1016
|
+
)
|
|
1017
|
+
);
|
|
959
1018
|
}, this.timeoutMs);
|
|
960
1019
|
ws.on("open", () => {
|
|
961
1020
|
clearTimeout(timeout);
|
|
@@ -994,9 +1053,13 @@ function mapKaspaAddressBalance(result, address) {
|
|
|
994
1053
|
if (!result) return { address, balanceSompi: 0n, raw: result };
|
|
995
1054
|
let entry = result;
|
|
996
1055
|
if (Array.isArray(result)) {
|
|
997
|
-
entry = result.find(
|
|
1056
|
+
entry = result.find(
|
|
1057
|
+
(e) => (e.address || e.addressString || e.address_string) === address
|
|
1058
|
+
) || result[0];
|
|
998
1059
|
} else if (result.entries && Array.isArray(result.entries)) {
|
|
999
|
-
entry = result.entries.find(
|
|
1060
|
+
entry = result.entries.find(
|
|
1061
|
+
(e) => (e.address || e.addressString || e.address_string) === address
|
|
1062
|
+
) || result.entries[0];
|
|
1000
1063
|
}
|
|
1001
1064
|
const balance = entry.balance !== void 0 ? entry.balance : entry.balanceSompi !== void 0 ? entry.balanceSompi : entry.amount;
|
|
1002
1065
|
const balanceSompi = balance !== void 0 ? BigInt(balance) : 0n;
|
|
@@ -1025,12 +1088,20 @@ function mapKaspaRpcUtxos(result, address) {
|
|
|
1025
1088
|
const outpoint = entry.outpoint || entry;
|
|
1026
1089
|
return {
|
|
1027
1090
|
outpoint: {
|
|
1028
|
-
transactionId: String(
|
|
1029
|
-
|
|
1091
|
+
transactionId: String(
|
|
1092
|
+
outpoint.transactionId || outpoint.transaction_id || outpoint.txId || outpoint.tx_id || outpoint.transaction_hash || ""
|
|
1093
|
+
),
|
|
1094
|
+
index: Number(
|
|
1095
|
+
outpoint.index !== void 0 ? outpoint.index : outpoint.outputIndex !== void 0 ? outpoint.outputIndex : outpoint.output_index
|
|
1096
|
+
)
|
|
1030
1097
|
},
|
|
1031
1098
|
address: entry.address || address,
|
|
1032
|
-
amountSompi: BigInt(
|
|
1033
|
-
|
|
1099
|
+
amountSompi: BigInt(
|
|
1100
|
+
utxoEntry.amount || utxoEntry.amountSompi || utxoEntry.amount_sompi || 0
|
|
1101
|
+
),
|
|
1102
|
+
scriptPublicKey: String(
|
|
1103
|
+
utxoEntry.scriptPublicKey || utxoEntry.script_public_key || ""
|
|
1104
|
+
),
|
|
1034
1105
|
blockDaaScore: utxoEntry.blockDaaScore || utxoEntry.block_daa_score,
|
|
1035
1106
|
isCoinbase: Boolean(utxoEntry.isCoinbase || utxoEntry.is_coinbase),
|
|
1036
1107
|
raw: entry
|
|
@@ -1052,7 +1123,13 @@ var MockKaspaRpcClient = class {
|
|
|
1052
1123
|
networkId;
|
|
1053
1124
|
utxosByAddress = /* @__PURE__ */ new Map();
|
|
1054
1125
|
async getInfo() {
|
|
1055
|
-
return {
|
|
1126
|
+
return {
|
|
1127
|
+
networkId: this.networkId,
|
|
1128
|
+
serverVersion: "mock",
|
|
1129
|
+
isSynced: true,
|
|
1130
|
+
virtualDaaScore: 0n,
|
|
1131
|
+
raw: {}
|
|
1132
|
+
};
|
|
1056
1133
|
}
|
|
1057
1134
|
async healthCheck() {
|
|
1058
1135
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hardkas/kaspa-rpc",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.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.7.
|
|
13
|
-
"@hardkas/tx-builder": "0.7.
|
|
12
|
+
"@hardkas/core": "0.7.4-alpha",
|
|
13
|
+
"@hardkas/tx-builder": "0.7.4-alpha"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@types/ws": "^8.5.13",
|