@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/README.md
CHANGED
|
@@ -45,17 +45,17 @@ There are two ways to initialize the Dubhe client:
|
|
|
45
45
|
1. Using dynamic metadata loading:
|
|
46
46
|
|
|
47
47
|
```typescript
|
|
48
|
-
import { loadMetadata, Dubhe, NetworkType } from
|
|
48
|
+
import { loadMetadata, Dubhe, NetworkType } from '@0xobelisk/sui-client';
|
|
49
49
|
|
|
50
|
-
const network =
|
|
51
|
-
const packageId =
|
|
50
|
+
const network = 'devnet' as NetworkType;
|
|
51
|
+
const packageId = 'YOUR_PACKAGE_ID';
|
|
52
52
|
|
|
53
53
|
const metadata = await loadMetadata(network, packageId);
|
|
54
54
|
const dubhe = new Dubhe({
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
networkType: network,
|
|
56
|
+
packageId: packageId,
|
|
57
|
+
metadata: metadata,
|
|
58
|
+
secretKey: privkey,
|
|
59
59
|
});
|
|
60
60
|
```
|
|
61
61
|
|
|
@@ -65,10 +65,10 @@ const dubhe = new Dubhe({
|
|
|
65
65
|
import metadata from './metadata.json';
|
|
66
66
|
|
|
67
67
|
const dubhe = new Dubhe({
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
networkType: network,
|
|
69
|
+
packageId: packageId,
|
|
70
|
+
metadata: metadata,
|
|
71
|
+
secretKey: privkey,
|
|
72
72
|
});
|
|
73
73
|
```
|
|
74
74
|
|
|
@@ -77,11 +77,13 @@ const dubhe = new Dubhe({
|
|
|
77
77
|
To call contract methods:
|
|
78
78
|
|
|
79
79
|
```typescript
|
|
80
|
-
import { Transaction } from
|
|
80
|
+
import { Transaction } from '@0xobelisk/sui-client';
|
|
81
81
|
|
|
82
82
|
// Create transaction
|
|
83
83
|
const tx = new Transaction();
|
|
84
|
-
const params = [
|
|
84
|
+
const params = [
|
|
85
|
+
/* your parameters */
|
|
86
|
+
];
|
|
85
87
|
|
|
86
88
|
// Execute transaction
|
|
87
89
|
const response = await dubhe.tx.counter_system.inc(tx, params);
|
|
@@ -97,7 +99,9 @@ To query contract state:
|
|
|
97
99
|
|
|
98
100
|
```typescript
|
|
99
101
|
const tx = new Transaction();
|
|
100
|
-
const params = [
|
|
102
|
+
const params = [
|
|
103
|
+
/* your parameters */
|
|
104
|
+
];
|
|
101
105
|
const result = await dubhe.query.counter_system.get(tx, params);
|
|
102
106
|
|
|
103
107
|
// For BCS encoded results
|
|
@@ -162,7 +166,8 @@ const numberKey = await dubhe.entity_key_from_u256(123);
|
|
|
162
166
|
To query objects owned by a specific address:
|
|
163
167
|
|
|
164
168
|
```typescript
|
|
165
|
-
const owner =
|
|
169
|
+
const owner =
|
|
170
|
+
'0xfa99b5b0463fcfb7d0203c701a76da5eda21a96190eb1368ab36a437cc89195e';
|
|
166
171
|
const ownedObjects = await dubhe.getOwnedObjects(owner);
|
|
167
172
|
```
|
|
168
173
|
|
package/dist/dubhe.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { MapObjectStruct } from './types';
|
|
|
7
7
|
import { SuiContractFactory } from './libs/suiContractFactory';
|
|
8
8
|
import { SuiMoveMoudleFuncType } from './libs/suiContractFactory/types';
|
|
9
9
|
import { NetworkConfig } from './libs/suiInteractor';
|
|
10
|
-
import { DerivePathParams, FaucetNetworkType, MapMoudleFuncQuery, MapMoudleFuncTx, DubheParams, SuiTxArg, SuiObjectArg, SuiVecTxArg } from './types';
|
|
10
|
+
import { DerivePathParams, FaucetNetworkType, MapMoudleFuncQuery, MapMoudleFuncTx, DubheParams, SuiTxArg, SuiObjectArg, SuiVecTxArg, SubscribableType } from './types';
|
|
11
11
|
import { ConnectionResponse, IndexerTransaction, IndexerEvent, IndexerSchema, SuiIndexerClient, StorageResponse, StorageItemResponse } from './libs/suiIndexerClient';
|
|
12
12
|
import { Http } from './libs/http';
|
|
13
13
|
export declare function isUndefined(value?: unknown): value is undefined;
|
|
@@ -63,6 +63,12 @@ export declare class Dubhe {
|
|
|
63
63
|
checkpoint?: number;
|
|
64
64
|
orderBy?: string[];
|
|
65
65
|
}): Promise<ConnectionResponse<IndexerTransaction>>;
|
|
66
|
+
getTransaction(digest: string): Promise<IndexerTransaction | undefined>;
|
|
67
|
+
awaitIndexerTransaction(digest: string, options?: {
|
|
68
|
+
checkInterval?: number;
|
|
69
|
+
timeout?: number;
|
|
70
|
+
maxRetries?: number;
|
|
71
|
+
}): Promise<IndexerTransaction | undefined>;
|
|
66
72
|
getEvents({ first, after, name, sender, digest, checkpoint, orderBy, }: {
|
|
67
73
|
first?: number;
|
|
68
74
|
after?: string;
|
|
@@ -105,7 +111,7 @@ export declare class Dubhe {
|
|
|
105
111
|
last_update_digest?: string;
|
|
106
112
|
value?: any;
|
|
107
113
|
}): Promise<StorageItemResponse<IndexerSchema> | undefined>;
|
|
108
|
-
subscribe(
|
|
114
|
+
subscribe(types: SubscribableType[], handleData: (data: any) => void): Promise<WebSocket>;
|
|
109
115
|
/**
|
|
110
116
|
* else:
|
|
111
117
|
* it will generate signer from the mnemonic with the given derivePathParams.
|
package/dist/index.d.ts
CHANGED
|
@@ -11,5 +11,6 @@ export { SuiAccountManager } from './libs/suiAccountManager';
|
|
|
11
11
|
export { SuiTx } from './libs/suiTxBuilder';
|
|
12
12
|
export { MultiSigClient } from './libs/multiSig';
|
|
13
13
|
export { SuiContractFactory } from './libs/suiContractFactory';
|
|
14
|
+
export { SubscriptionKind } from './libs/suiIndexerClient';
|
|
14
15
|
export { loadMetadata } from './metadata';
|
|
15
16
|
export type * from './types';
|
package/dist/index.js
CHANGED
|
@@ -51,6 +51,7 @@ __export(src_exports, {
|
|
|
51
51
|
BcsType: () => import_bcs4.BcsType,
|
|
52
52
|
Dubhe: () => Dubhe,
|
|
53
53
|
MultiSigClient: () => MultiSigClient,
|
|
54
|
+
SubscriptionKind: () => SubscriptionKind,
|
|
54
55
|
SuiAccountManager: () => SuiAccountManager,
|
|
55
56
|
SuiContractFactory: () => SuiContractFactory,
|
|
56
57
|
SuiTx: () => SuiTx,
|
|
@@ -1115,6 +1116,11 @@ var parseValue = (value) => {
|
|
|
1115
1116
|
};
|
|
1116
1117
|
|
|
1117
1118
|
// src/libs/suiIndexerClient/index.ts
|
|
1119
|
+
var SubscriptionKind = /* @__PURE__ */ ((SubscriptionKind2) => {
|
|
1120
|
+
SubscriptionKind2["Event"] = "event";
|
|
1121
|
+
SubscriptionKind2["Schema"] = "schema";
|
|
1122
|
+
return SubscriptionKind2;
|
|
1123
|
+
})(SubscriptionKind || {});
|
|
1118
1124
|
var SuiIndexerClient = class {
|
|
1119
1125
|
constructor(http) {
|
|
1120
1126
|
this.http = http;
|
|
@@ -1147,6 +1153,13 @@ var SuiIndexerClient = class {
|
|
|
1147
1153
|
const response = await this.fetchGraphql(query, params);
|
|
1148
1154
|
return response.transactions;
|
|
1149
1155
|
}
|
|
1156
|
+
async getTransaction(digest) {
|
|
1157
|
+
const response = await this.getTransactions({
|
|
1158
|
+
first: 1,
|
|
1159
|
+
digest
|
|
1160
|
+
});
|
|
1161
|
+
return response.edges[0]?.node;
|
|
1162
|
+
}
|
|
1150
1163
|
async getSchemas(params) {
|
|
1151
1164
|
const query = `
|
|
1152
1165
|
query GetSchemas(
|
|
@@ -1288,8 +1301,8 @@ var SuiIndexerClient = class {
|
|
|
1288
1301
|
value: result
|
|
1289
1302
|
};
|
|
1290
1303
|
}
|
|
1291
|
-
async subscribe(
|
|
1292
|
-
return this.http.subscribe(
|
|
1304
|
+
async subscribe(types, handleData) {
|
|
1305
|
+
return this.http.subscribe(types, handleData);
|
|
1293
1306
|
}
|
|
1294
1307
|
};
|
|
1295
1308
|
|
|
@@ -1427,14 +1440,11 @@ var Http = class {
|
|
|
1427
1440
|
);
|
|
1428
1441
|
}
|
|
1429
1442
|
}
|
|
1430
|
-
async subscribe(
|
|
1443
|
+
async subscribe(types, handleData) {
|
|
1431
1444
|
const ws = createWebSocketClient(this.wsEndpoint);
|
|
1432
1445
|
ws.onopen = () => {
|
|
1433
1446
|
console.log("Connected to the WebSocket server");
|
|
1434
|
-
const subscribeMessage = JSON.stringify(
|
|
1435
|
-
type: "subscribe",
|
|
1436
|
-
names
|
|
1437
|
-
});
|
|
1447
|
+
const subscribeMessage = JSON.stringify(types);
|
|
1438
1448
|
ws.send(subscribeMessage);
|
|
1439
1449
|
};
|
|
1440
1450
|
ws.onmessage = (event) => {
|
|
@@ -2296,6 +2306,40 @@ var Dubhe = class {
|
|
|
2296
2306
|
orderBy
|
|
2297
2307
|
});
|
|
2298
2308
|
}
|
|
2309
|
+
async getTransaction(digest) {
|
|
2310
|
+
return await this.suiIndexerClient.getTransaction(digest);
|
|
2311
|
+
}
|
|
2312
|
+
async awaitIndexerTransaction(digest, options) {
|
|
2313
|
+
const {
|
|
2314
|
+
checkInterval = 100,
|
|
2315
|
+
timeout = 3e4,
|
|
2316
|
+
// 30 seconds default timeout
|
|
2317
|
+
maxRetries = 300
|
|
2318
|
+
// 300 times default max retries
|
|
2319
|
+
} = options ?? {};
|
|
2320
|
+
const startTime = Date.now();
|
|
2321
|
+
let retryCount = 0;
|
|
2322
|
+
while (retryCount < maxRetries) {
|
|
2323
|
+
try {
|
|
2324
|
+
if (Date.now() - startTime > timeout) {
|
|
2325
|
+
throw new Error(`Timeout waiting for transaction ${digest}`);
|
|
2326
|
+
}
|
|
2327
|
+
await new Promise((resolve) => setTimeout(resolve, checkInterval));
|
|
2328
|
+
const transaction = await this.getTransaction(digest);
|
|
2329
|
+
if (transaction) {
|
|
2330
|
+
return transaction;
|
|
2331
|
+
}
|
|
2332
|
+
retryCount++;
|
|
2333
|
+
} catch (error) {
|
|
2334
|
+
throw new Error(
|
|
2335
|
+
`Error while waiting for transaction ${digest}: ${error}`
|
|
2336
|
+
);
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
throw new Error(
|
|
2340
|
+
`Max retries (${maxRetries}) reached while waiting for transaction ${digest}`
|
|
2341
|
+
);
|
|
2342
|
+
}
|
|
2299
2343
|
async getEvents({
|
|
2300
2344
|
first,
|
|
2301
2345
|
after,
|
|
@@ -2385,8 +2429,8 @@ var Dubhe = class {
|
|
|
2385
2429
|
});
|
|
2386
2430
|
return response;
|
|
2387
2431
|
}
|
|
2388
|
-
async subscribe(
|
|
2389
|
-
return this.suiIndexerClient.subscribe(
|
|
2432
|
+
async subscribe(types, handleData) {
|
|
2433
|
+
return this.suiIndexerClient.subscribe(types, handleData);
|
|
2390
2434
|
}
|
|
2391
2435
|
/**
|
|
2392
2436
|
* else:
|
|
@@ -2785,9 +2829,7 @@ async function loadMetadata(networkType, packageId, fullnodeUrls) {
|
|
|
2785
2829
|
fullnodeUrls = fullnodeUrls || [(0, import_client3.getFullnodeUrl)(networkType)];
|
|
2786
2830
|
const suiInteractor = new SuiInteractor(fullnodeUrls);
|
|
2787
2831
|
if (packageId !== void 0) {
|
|
2788
|
-
const jsonData = await suiInteractor.getNormalizedMoveModulesByPackage(
|
|
2789
|
-
packageId
|
|
2790
|
-
);
|
|
2832
|
+
const jsonData = await suiInteractor.getNormalizedMoveModulesByPackage(packageId);
|
|
2791
2833
|
return jsonData;
|
|
2792
2834
|
} else {
|
|
2793
2835
|
console.error("please set your package id.");
|
|
@@ -2798,6 +2840,7 @@ async function loadMetadata(networkType, packageId, fullnodeUrls) {
|
|
|
2798
2840
|
BcsType,
|
|
2799
2841
|
Dubhe,
|
|
2800
2842
|
MultiSigClient,
|
|
2843
|
+
SubscriptionKind,
|
|
2801
2844
|
SuiAccountManager,
|
|
2802
2845
|
SuiContractFactory,
|
|
2803
2846
|
SuiTx,
|