@0xobelisk/sui-client 1.1.6 → 1.1.8
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/README.md +20 -15
- package/dist/dubhe.d.ts +8 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +55 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -12
- package/dist/index.mjs.map +1 -1
- package/dist/libs/http/http.d.ts +2 -1
- package/dist/libs/suiIndexerClient/index.d.ts +7 -1
- package/dist/types/index.d.ts +9 -0
- package/package.json +9 -8
- package/src/dubhe.ts +52 -2
- package/src/index.ts +1 -0
- package/src/libs/http/errors.ts +5 -1
- package/src/libs/http/http.ts +3 -5
- package/src/libs/suiIndexerClient/index.ts +18 -2
- package/src/metadata/index.ts +2 -3
- package/src/types/index.ts +5 -0
package/dist/index.mjs
CHANGED
|
@@ -1089,6 +1089,11 @@ var parseValue = (value) => {
|
|
|
1089
1089
|
};
|
|
1090
1090
|
|
|
1091
1091
|
// src/libs/suiIndexerClient/index.ts
|
|
1092
|
+
var SubscriptionKind = /* @__PURE__ */ ((SubscriptionKind2) => {
|
|
1093
|
+
SubscriptionKind2["Event"] = "event";
|
|
1094
|
+
SubscriptionKind2["Schema"] = "schema";
|
|
1095
|
+
return SubscriptionKind2;
|
|
1096
|
+
})(SubscriptionKind || {});
|
|
1092
1097
|
var SuiIndexerClient = class {
|
|
1093
1098
|
constructor(http) {
|
|
1094
1099
|
this.http = http;
|
|
@@ -1121,6 +1126,13 @@ var SuiIndexerClient = class {
|
|
|
1121
1126
|
const response = await this.fetchGraphql(query, params);
|
|
1122
1127
|
return response.transactions;
|
|
1123
1128
|
}
|
|
1129
|
+
async getTransaction(digest) {
|
|
1130
|
+
const response = await this.getTransactions({
|
|
1131
|
+
first: 1,
|
|
1132
|
+
digest
|
|
1133
|
+
});
|
|
1134
|
+
return response.edges[0]?.node;
|
|
1135
|
+
}
|
|
1124
1136
|
async getSchemas(params) {
|
|
1125
1137
|
const query = `
|
|
1126
1138
|
query GetSchemas(
|
|
@@ -1262,8 +1274,8 @@ var SuiIndexerClient = class {
|
|
|
1262
1274
|
value: result
|
|
1263
1275
|
};
|
|
1264
1276
|
}
|
|
1265
|
-
async subscribe(
|
|
1266
|
-
return this.http.subscribe(
|
|
1277
|
+
async subscribe(types, handleData) {
|
|
1278
|
+
return this.http.subscribe(types, handleData);
|
|
1267
1279
|
}
|
|
1268
1280
|
};
|
|
1269
1281
|
|
|
@@ -1401,14 +1413,11 @@ var Http = class {
|
|
|
1401
1413
|
);
|
|
1402
1414
|
}
|
|
1403
1415
|
}
|
|
1404
|
-
async subscribe(
|
|
1416
|
+
async subscribe(types, handleData) {
|
|
1405
1417
|
const ws = createWebSocketClient(this.wsEndpoint);
|
|
1406
1418
|
ws.onopen = () => {
|
|
1407
1419
|
console.log("Connected to the WebSocket server");
|
|
1408
|
-
const subscribeMessage = JSON.stringify(
|
|
1409
|
-
type: "subscribe",
|
|
1410
|
-
names
|
|
1411
|
-
});
|
|
1420
|
+
const subscribeMessage = JSON.stringify(types);
|
|
1412
1421
|
ws.send(subscribeMessage);
|
|
1413
1422
|
};
|
|
1414
1423
|
ws.onmessage = (event) => {
|
|
@@ -2270,6 +2279,40 @@ var Dubhe = class {
|
|
|
2270
2279
|
orderBy
|
|
2271
2280
|
});
|
|
2272
2281
|
}
|
|
2282
|
+
async getTransaction(digest) {
|
|
2283
|
+
return await this.suiIndexerClient.getTransaction(digest);
|
|
2284
|
+
}
|
|
2285
|
+
async awaitIndexerTransaction(digest, options) {
|
|
2286
|
+
const {
|
|
2287
|
+
checkInterval = 100,
|
|
2288
|
+
timeout = 3e4,
|
|
2289
|
+
// 30 seconds default timeout
|
|
2290
|
+
maxRetries = 300
|
|
2291
|
+
// 300 times default max retries
|
|
2292
|
+
} = options ?? {};
|
|
2293
|
+
const startTime = Date.now();
|
|
2294
|
+
let retryCount = 0;
|
|
2295
|
+
while (retryCount < maxRetries) {
|
|
2296
|
+
try {
|
|
2297
|
+
if (Date.now() - startTime > timeout) {
|
|
2298
|
+
throw new Error(`Timeout waiting for transaction ${digest}`);
|
|
2299
|
+
}
|
|
2300
|
+
await new Promise((resolve) => setTimeout(resolve, checkInterval));
|
|
2301
|
+
const transaction = await this.getTransaction(digest);
|
|
2302
|
+
if (transaction) {
|
|
2303
|
+
return transaction;
|
|
2304
|
+
}
|
|
2305
|
+
retryCount++;
|
|
2306
|
+
} catch (error) {
|
|
2307
|
+
throw new Error(
|
|
2308
|
+
`Error while waiting for transaction ${digest}: ${error}`
|
|
2309
|
+
);
|
|
2310
|
+
}
|
|
2311
|
+
}
|
|
2312
|
+
throw new Error(
|
|
2313
|
+
`Max retries (${maxRetries}) reached while waiting for transaction ${digest}`
|
|
2314
|
+
);
|
|
2315
|
+
}
|
|
2273
2316
|
async getEvents({
|
|
2274
2317
|
first,
|
|
2275
2318
|
after,
|
|
@@ -2359,8 +2402,8 @@ var Dubhe = class {
|
|
|
2359
2402
|
});
|
|
2360
2403
|
return response;
|
|
2361
2404
|
}
|
|
2362
|
-
async subscribe(
|
|
2363
|
-
return this.suiIndexerClient.subscribe(
|
|
2405
|
+
async subscribe(types, handleData) {
|
|
2406
|
+
return this.suiIndexerClient.subscribe(types, handleData);
|
|
2364
2407
|
}
|
|
2365
2408
|
/**
|
|
2366
2409
|
* else:
|
|
@@ -2759,9 +2802,7 @@ async function loadMetadata(networkType, packageId, fullnodeUrls) {
|
|
|
2759
2802
|
fullnodeUrls = fullnodeUrls || [getFullnodeUrl(networkType)];
|
|
2760
2803
|
const suiInteractor = new SuiInteractor(fullnodeUrls);
|
|
2761
2804
|
if (packageId !== void 0) {
|
|
2762
|
-
const jsonData = await suiInteractor.getNormalizedMoveModulesByPackage(
|
|
2763
|
-
packageId
|
|
2764
|
-
);
|
|
2805
|
+
const jsonData = await suiInteractor.getNormalizedMoveModulesByPackage(packageId);
|
|
2765
2806
|
return jsonData;
|
|
2766
2807
|
} else {
|
|
2767
2808
|
console.error("please set your package id.");
|
|
@@ -2771,6 +2812,7 @@ export {
|
|
|
2771
2812
|
BcsType2 as BcsType,
|
|
2772
2813
|
Dubhe,
|
|
2773
2814
|
MultiSigClient,
|
|
2815
|
+
SubscriptionKind,
|
|
2774
2816
|
SuiAccountManager,
|
|
2775
2817
|
SuiContractFactory,
|
|
2776
2818
|
SuiTx,
|