@0xobelisk/sui-client 1.1.9 → 1.1.11

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/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, SubscribableType } from './types';
10
+ import { DerivePathParams, FaucetNetworkType, MapMoudleFuncQuery, MapMoudleFuncTx, DubheParams, SuiTxArg, SuiObjectArg, SuiVecTxArg, SubscribableType, IndexerTransactionResult } 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;
@@ -27,6 +27,7 @@ export declare class Dubhe {
27
27
  contractFactory: SuiContractFactory;
28
28
  packageId: string | undefined;
29
29
  metadata: SuiMoveNormalizedModules | undefined;
30
+ projectName: string | undefined;
30
31
  /**
31
32
  * Support the following ways to init the DubheClient:
32
33
  * 1. mnemonics
@@ -44,16 +45,18 @@ export declare class Dubhe {
44
45
  get tx(): MapMoudleFuncTx;
45
46
  get object(): MapObjectStruct;
46
47
  view(dryResult: DevInspectResults): any[];
47
- state({ tx, schema, params, }: {
48
+ state({ tx, schema, params, customModuleName, }: {
48
49
  tx: Transaction;
49
50
  schema: string;
50
51
  params: any[];
52
+ customModuleName?: string;
51
53
  }): Promise<any[] | undefined>;
52
- parseState({ schema, objectId, storageType, params, }: {
54
+ parseState({ schema, objectId, storageType, params, customModuleName, }: {
53
55
  schema: string;
54
56
  objectId: string;
55
57
  storageType: string;
56
58
  params: any[];
59
+ customModuleName?: string;
57
60
  }): Promise<any[] | undefined>;
58
61
  getTransactions({ first, after, sender, digest, checkpoint, orderBy, }: {
59
62
  first?: number;
@@ -64,11 +67,18 @@ export declare class Dubhe {
64
67
  orderBy?: string[];
65
68
  }): Promise<ConnectionResponse<IndexerTransaction>>;
66
69
  getTransaction(digest: string): Promise<IndexerTransaction | undefined>;
70
+ /**
71
+ * Wait for the transaction to be processed by the indexer and return all transaction-related data
72
+ * @param digest transaction digest
73
+ * @param options option parameters
74
+ * @returns result object containing transaction, events and schema data
75
+ */
67
76
  waitForIndexerTransaction(digest: string, options?: {
68
77
  checkInterval?: number;
69
78
  timeout?: number;
70
79
  maxRetries?: number;
71
- }): Promise<IndexerTransaction | undefined>;
80
+ pageSize?: number;
81
+ }): Promise<IndexerTransactionResult>;
72
82
  getEvents({ first, after, name, sender, digest, checkpoint, orderBy, }: {
73
83
  first?: number;
74
84
  after?: string;
package/dist/index.d.ts CHANGED
@@ -14,3 +14,4 @@ export { SuiContractFactory } from './libs/suiContractFactory';
14
14
  export { SubscriptionKind } from './libs/suiIndexerClient';
15
15
  export { loadMetadata } from './metadata';
16
16
  export type * from './types';
17
+ export type { IndexerEvent, IndexerSchema, IndexerTransaction, ConnectionResponse, StorageResponse, StorageItemResponse, PageInfo, } from './libs/suiIndexerClient';
package/dist/index.js CHANGED
@@ -2024,6 +2024,10 @@ var Dubhe = class {
2024
2024
  (moudlevalue) => {
2025
2025
  const data = moudlevalue;
2026
2026
  const moduleName = data.name;
2027
+ const itemModuleName = moduleName;
2028
+ if (itemModuleName.endsWith("_genesis")) {
2029
+ this.projectName = itemModuleName.replace("_genesis", "");
2030
+ }
2027
2031
  const objMoudleId = `${this.packageId}::${moduleName}`;
2028
2032
  if (data.enums) {
2029
2033
  Object.entries(data.enums).forEach(([enumName, enumType]) => {
@@ -2224,9 +2228,13 @@ var Dubhe = class {
2224
2228
  async state({
2225
2229
  tx,
2226
2230
  schema,
2227
- params
2231
+ params,
2232
+ customModuleName
2228
2233
  }) {
2229
- const moduleName = `schema`;
2234
+ if (!this.metadata) {
2235
+ throw new Error("Metadata is not loaded");
2236
+ }
2237
+ const moduleName = `${customModuleName ?? this.projectName}_schema`;
2230
2238
  const functionName = `get_${schema}`;
2231
2239
  let queryResponse = void 0;
2232
2240
  try {
@@ -2246,7 +2254,8 @@ var Dubhe = class {
2246
2254
  schema,
2247
2255
  objectId,
2248
2256
  storageType,
2249
- params
2257
+ params,
2258
+ customModuleName
2250
2259
  }) {
2251
2260
  const tx = new import_transactions3.Transaction();
2252
2261
  const schemaObject = tx.object(objectId);
@@ -2286,7 +2295,8 @@ var Dubhe = class {
2286
2295
  return this.state({
2287
2296
  tx,
2288
2297
  schema,
2289
- params: processedParams
2298
+ params: processedParams,
2299
+ customModuleName
2290
2300
  });
2291
2301
  }
2292
2302
  async getTransactions({
@@ -2309,25 +2319,60 @@ var Dubhe = class {
2309
2319
  async getTransaction(digest) {
2310
2320
  return await this.suiIndexerClient.getTransaction(digest);
2311
2321
  }
2322
+ /**
2323
+ * Wait for the transaction to be processed by the indexer and return all transaction-related data
2324
+ * @param digest transaction digest
2325
+ * @param options option parameters
2326
+ * @returns result object containing transaction, events and schema data
2327
+ */
2312
2328
  async waitForIndexerTransaction(digest, options) {
2313
2329
  const {
2314
2330
  checkInterval = 100,
2315
2331
  timeout = 3e4,
2316
- // 30 seconds default timeout
2317
- maxRetries = 300
2318
- // 300 times default max retries
2332
+ maxRetries = 300,
2333
+ pageSize = 100
2319
2334
  } = options ?? {};
2320
2335
  const startTime = Date.now();
2321
2336
  let retryCount = 0;
2322
2337
  while (retryCount < maxRetries) {
2323
2338
  try {
2324
2339
  if (Date.now() - startTime > timeout) {
2325
- throw new Error(`Timeout waiting for transaction ${digest}`);
2340
+ throw new Error(`Waiting for transaction ${digest} timed out`);
2326
2341
  }
2327
2342
  await new Promise((resolve) => setTimeout(resolve, checkInterval));
2328
- const transaction = await this.getTransaction(digest);
2329
- if (transaction) {
2330
- return transaction;
2343
+ const tx = await this.getTransaction(digest);
2344
+ if (tx) {
2345
+ const events = [];
2346
+ const schemaChanges = [];
2347
+ let hasNextEventsPage = true;
2348
+ let eventsCursor;
2349
+ while (hasNextEventsPage) {
2350
+ const eventsResponse = await this.getEvents({
2351
+ digest,
2352
+ first: pageSize,
2353
+ after: eventsCursor
2354
+ });
2355
+ events.push(...eventsResponse.edges.map((edge) => edge.node));
2356
+ hasNextEventsPage = eventsResponse.pageInfo.hasNextPage;
2357
+ eventsCursor = eventsResponse.pageInfo.endCursor;
2358
+ }
2359
+ let hasNextSchemasPage = true;
2360
+ let schemasCursor;
2361
+ while (hasNextSchemasPage) {
2362
+ const schemasResponse = await this.getStorage({
2363
+ last_update_digest: digest,
2364
+ first: pageSize,
2365
+ after: schemasCursor
2366
+ });
2367
+ schemaChanges.push(...schemasResponse.data);
2368
+ hasNextSchemasPage = schemasResponse.pageInfo.hasNextPage;
2369
+ schemasCursor = schemasResponse.pageInfo.endCursor;
2370
+ }
2371
+ return {
2372
+ tx,
2373
+ events,
2374
+ schemaChanges
2375
+ };
2331
2376
  }
2332
2377
  retryCount++;
2333
2378
  } catch (error) {
@@ -2337,7 +2382,7 @@ var Dubhe = class {
2337
2382
  }
2338
2383
  }
2339
2384
  throw new Error(
2340
- `Max retries (${maxRetries}) reached while waiting for transaction ${digest}`
2385
+ `Reached maximum retries (${maxRetries}), failed to wait for transaction ${digest}`
2341
2386
  );
2342
2387
  }
2343
2388
  async getEvents({