@mysten/sui 2.20.3 → 2.21.0

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.
Files changed (79) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/bcs/bcs.d.mts +6 -6
  3. package/dist/bcs/index.d.mts +20 -20
  4. package/dist/client/core.d.mts.map +1 -1
  5. package/dist/client/core.mjs +4 -1
  6. package/dist/client/core.mjs.map +1 -1
  7. package/dist/client/mvr.d.mts.map +1 -1
  8. package/dist/client/mvr.mjs +29 -7
  9. package/dist/client/mvr.mjs.map +1 -1
  10. package/dist/cryptography/signature.d.mts +6 -6
  11. package/dist/grpc/client.d.mts.map +1 -1
  12. package/dist/grpc/client.mjs +1 -1
  13. package/dist/grpc/client.mjs.map +1 -1
  14. package/dist/grpc/core.d.mts +13 -5
  15. package/dist/grpc/core.d.mts.map +1 -1
  16. package/dist/grpc/core.mjs +68 -46
  17. package/dist/grpc/core.mjs.map +1 -1
  18. package/dist/grpc/index.d.mts +2 -2
  19. package/dist/grpc/index.mjs +2 -2
  20. package/dist/grpc/proto/sui/forking/v1alpha/forking_service.client.d.mts +4 -4
  21. package/dist/grpc/proto/sui/rpc/v2/name_service.client.d.mts +4 -4
  22. package/dist/grpc/proto/sui/rpc/v2/state_service.client.d.mts +4 -4
  23. package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts +4 -4
  24. package/dist/jsonRpc/client.d.mts +160 -0
  25. package/dist/jsonRpc/client.d.mts.map +1 -1
  26. package/dist/jsonRpc/client.mjs +142 -0
  27. package/dist/jsonRpc/client.mjs.map +1 -1
  28. package/dist/jsonRpc/core.d.mts +80 -0
  29. package/dist/jsonRpc/core.d.mts.map +1 -1
  30. package/dist/jsonRpc/core.mjs +80 -0
  31. package/dist/jsonRpc/core.mjs.map +1 -1
  32. package/dist/jsonRpc/errors.d.mts +12 -0
  33. package/dist/jsonRpc/errors.d.mts.map +1 -1
  34. package/dist/jsonRpc/errors.mjs +12 -0
  35. package/dist/jsonRpc/errors.mjs.map +1 -1
  36. package/dist/jsonRpc/http-transport.d.mts +30 -0
  37. package/dist/jsonRpc/http-transport.d.mts.map +1 -1
  38. package/dist/jsonRpc/http-transport.mjs +16 -0
  39. package/dist/jsonRpc/http-transport.mjs.map +1 -1
  40. package/dist/jsonRpc/network.d.mts +4 -0
  41. package/dist/jsonRpc/network.d.mts.map +1 -1
  42. package/dist/jsonRpc/network.mjs +4 -0
  43. package/dist/jsonRpc/network.mjs.map +1 -1
  44. package/dist/jsonRpc/types/chain.d.mts +68 -0
  45. package/dist/jsonRpc/types/chain.d.mts.map +1 -1
  46. package/dist/jsonRpc/types/changes.d.mts +24 -0
  47. package/dist/jsonRpc/types/changes.d.mts.map +1 -1
  48. package/dist/jsonRpc/types/coins.d.mts +4 -0
  49. package/dist/jsonRpc/types/coins.d.mts.map +1 -1
  50. package/dist/jsonRpc/types/common.d.mts +4 -0
  51. package/dist/jsonRpc/types/common.d.mts.map +1 -1
  52. package/dist/jsonRpc/types/generated.d.mts +497 -16
  53. package/dist/jsonRpc/types/generated.d.mts.map +1 -1
  54. package/dist/jsonRpc/types/params.d.mts +289 -41
  55. package/dist/jsonRpc/types/params.d.mts.map +1 -1
  56. package/dist/transactions/Transaction.d.mts +9 -9
  57. package/dist/transactions/Transaction.d.mts.map +1 -1
  58. package/dist/version.mjs +1 -1
  59. package/dist/version.mjs.map +1 -1
  60. package/dist/zklogin/bcs.d.mts +14 -14
  61. package/dist/zklogin/bcs.d.mts.map +1 -1
  62. package/package.json +1 -1
  63. package/src/client/core.ts +1 -0
  64. package/src/client/mvr.ts +39 -6
  65. package/src/grpc/client.ts +10 -7
  66. package/src/grpc/core.ts +251 -168
  67. package/src/grpc/index.ts +5 -1
  68. package/src/jsonRpc/client.ts +160 -0
  69. package/src/jsonRpc/core.ts +80 -0
  70. package/src/jsonRpc/errors.ts +12 -0
  71. package/src/jsonRpc/http-transport.ts +30 -0
  72. package/src/jsonRpc/network.ts +4 -0
  73. package/src/jsonRpc/types/chain.ts +68 -0
  74. package/src/jsonRpc/types/changes.ts +24 -0
  75. package/src/jsonRpc/types/coins.ts +4 -0
  76. package/src/jsonRpc/types/common.ts +4 -0
  77. package/src/jsonRpc/types/generated.ts +497 -16
  78. package/src/jsonRpc/types/params.ts +289 -41
  79. package/src/version.ts +1 -1
package/src/grpc/core.ts CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  import type { CoreClientOptions, SuiClientTypes } from '../client/index.js';
5
5
  import { CoreClient, formatMoveAbortMessage, SimulationError } from '../client/index.js';
6
+ import { raceSignal } from '../client/mvr.js';
6
7
  import type { SuiGrpcClient } from './client.js';
7
8
  import type { Owner } from './proto/sui/rpc/v2/owner.js';
8
9
  import { Owner_OwnerKind } from './proto/sui/rpc/v2/owner.js';
@@ -44,6 +45,7 @@ import {
44
45
  grpcTransactionToTransactionData,
45
46
  } from '../client/transaction-resolver.js';
46
47
  import { Value } from './proto/google/protobuf/struct.js';
48
+ import type { SimulateTransactionResponse } from './proto/sui/rpc/v2/transaction_execution_service.js';
47
49
  import { SimulateTransactionRequest_TransactionChecks } from './proto/sui/rpc/v2/transaction_execution_service.js';
48
50
 
49
51
  export interface GrpcCoreClientOptions extends CoreClientOptions {
@@ -80,12 +82,15 @@ export class GrpcCoreClient extends CoreClient {
80
82
  }
81
83
 
82
84
  for (const batch of batches) {
83
- const response = await this.#client.ledgerService.batchGetObjects({
84
- requests: batch.map((id) => ({ objectId: id })),
85
- readMask: {
86
- paths,
85
+ const response = await this.#client.ledgerService.batchGetObjects(
86
+ {
87
+ requests: batch.map((id) => ({ objectId: id })),
88
+ readMask: {
89
+ paths,
90
+ },
87
91
  },
88
- });
92
+ { abort: options.signal },
93
+ );
89
94
 
90
95
  results.push(
91
96
  ...response.response.objects.map((object): SuiClientTypes.Object<Include> | Error => {
@@ -160,17 +165,20 @@ export class GrpcCoreClient extends CoreClient {
160
165
  paths.push('display');
161
166
  }
162
167
 
163
- const response = await this.#client.stateService.listOwnedObjects({
164
- owner: options.owner,
165
- objectType: options.type
166
- ? (await this.mvr.resolveType({ type: options.type })).type
167
- : undefined,
168
- pageToken: options.cursor ? fromBase64(options.cursor) : undefined,
169
- pageSize: options.limit,
170
- readMask: {
171
- paths,
168
+ const response = await this.#client.stateService.listOwnedObjects(
169
+ {
170
+ owner: options.owner,
171
+ objectType: options.type
172
+ ? (await this.mvr.resolveType({ type: options.type, signal: options.signal })).type
173
+ : undefined,
174
+ pageToken: options.cursor ? fromBase64(options.cursor) : undefined,
175
+ pageSize: options.limit,
176
+ readMask: {
177
+ paths,
178
+ },
172
179
  },
173
- });
180
+ { abort: options.signal },
181
+ );
174
182
 
175
183
  const objects = response.response.objects.map(
176
184
  (object): SuiClientTypes.Object<Include> => ({
@@ -207,15 +215,18 @@ export class GrpcCoreClient extends CoreClient {
207
215
  const paths = ['owner', 'object_type', 'digest', 'version', 'object_id', 'balance'];
208
216
  const coinType = options.coinType ?? SUI_TYPE_ARG;
209
217
 
210
- const response = await this.#client.stateService.listOwnedObjects({
211
- owner: options.owner,
212
- objectType: `0x2::coin::Coin<${(await this.mvr.resolveType({ type: coinType })).type}>`,
213
- pageToken: options.cursor ? fromBase64(options.cursor) : undefined,
214
- pageSize: options.limit,
215
- readMask: {
216
- paths,
218
+ const response = await this.#client.stateService.listOwnedObjects(
219
+ {
220
+ owner: options.owner,
221
+ objectType: `0x2::coin::Coin<${(await this.mvr.resolveType({ type: coinType, signal: options.signal })).type}>`,
222
+ pageToken: options.cursor ? fromBase64(options.cursor) : undefined,
223
+ pageSize: options.limit,
224
+ readMask: {
225
+ paths,
226
+ },
217
227
  },
218
- });
228
+ { abort: options.signal },
229
+ );
219
230
 
220
231
  return {
221
232
  objects: response.response.objects.map(
@@ -237,10 +248,13 @@ export class GrpcCoreClient extends CoreClient {
237
248
  options: SuiClientTypes.GetBalanceOptions,
238
249
  ): Promise<SuiClientTypes.GetBalanceResponse> {
239
250
  const coinType = options.coinType ?? SUI_TYPE_ARG;
240
- const result = await this.#client.stateService.getBalance({
241
- owner: options.owner,
242
- coinType: (await this.mvr.resolveType({ type: coinType })).type,
243
- });
251
+ const result = await this.#client.stateService.getBalance(
252
+ {
253
+ owner: options.owner,
254
+ coinType: (await this.mvr.resolveType({ type: coinType, signal: options.signal })).type,
255
+ },
256
+ { abort: options.signal },
257
+ );
244
258
 
245
259
  return {
246
260
  balance: {
@@ -255,14 +269,23 @@ export class GrpcCoreClient extends CoreClient {
255
269
  async getCoinMetadata(
256
270
  options: SuiClientTypes.GetCoinMetadataOptions,
257
271
  ): Promise<SuiClientTypes.GetCoinMetadataResponse> {
258
- const coinType = (await this.mvr.resolveType({ type: options.coinType })).type;
272
+ const coinType = (
273
+ await this.mvr.resolveType({ type: options.coinType, signal: options.signal })
274
+ ).type;
259
275
 
260
276
  let response;
261
277
  try {
262
- ({ response } = await this.#client.stateService.getCoinInfo({
263
- coinType,
264
- }));
265
- } catch {
278
+ ({ response } = await this.#client.stateService.getCoinInfo(
279
+ {
280
+ coinType,
281
+ },
282
+ { abort: options.signal },
283
+ ));
284
+ } catch (error) {
285
+ // Don't swallow cancellation — only treat the coin as missing on real errors.
286
+ if (options.signal?.aborted) {
287
+ throw error;
288
+ }
266
289
  return { coinMetadata: null };
267
290
  }
268
291
 
@@ -285,11 +308,14 @@ export class GrpcCoreClient extends CoreClient {
285
308
  async listBalances(
286
309
  options: SuiClientTypes.ListBalancesOptions,
287
310
  ): Promise<SuiClientTypes.ListBalancesResponse> {
288
- const result = await this.#client.stateService.listBalances({
289
- owner: options.owner,
290
- pageToken: options.cursor ? fromBase64(options.cursor) : undefined,
291
- pageSize: options.limit,
292
- });
311
+ const result = await this.#client.stateService.listBalances(
312
+ {
313
+ owner: options.owner,
314
+ pageToken: options.cursor ? fromBase64(options.cursor) : undefined,
315
+ pageSize: options.limit,
316
+ },
317
+ { abort: options.signal },
318
+ );
293
319
 
294
320
  return {
295
321
  hasNextPage: !!result.response.nextPageToken,
@@ -331,18 +357,21 @@ export class GrpcCoreClient extends CoreClient {
331
357
  paths.push('effects.changed_objects.object_id');
332
358
  }
333
359
 
334
- const { response } = await this.#client.ledgerService.getTransaction({
335
- digest: options.digest,
336
- readMask: {
337
- paths,
360
+ const { response } = await this.#client.ledgerService.getTransaction(
361
+ {
362
+ digest: options.digest,
363
+ readMask: {
364
+ paths,
365
+ },
338
366
  },
339
- });
367
+ { abort: options.signal },
368
+ );
340
369
 
341
370
  if (!response.transaction) {
342
371
  throw new Error(`Transaction ${options.digest} not found`);
343
372
  }
344
373
 
345
- return parseTransaction(response.transaction, options.include);
374
+ return parseGrpcTransactionResponse(response.transaction, { include: options.include });
346
375
  }
347
376
  async executeTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(
348
377
  options: SuiClientTypes.ExecuteTransactionOptions<Include>,
@@ -373,26 +402,29 @@ export class GrpcCoreClient extends CoreClient {
373
402
  paths.push('effects.changed_objects.object_id');
374
403
  }
375
404
 
376
- const { response } = await this.#client.transactionExecutionService.executeTransaction({
377
- transaction: {
378
- bcs: {
379
- value: options.transaction,
380
- },
381
- },
382
- signatures: options.signatures.map((signature) => ({
383
- bcs: {
384
- value: fromBase64(signature),
405
+ const { response } = await this.#client.transactionExecutionService.executeTransaction(
406
+ {
407
+ transaction: {
408
+ bcs: {
409
+ value: options.transaction,
410
+ },
385
411
  },
386
- signature: {
387
- oneofKind: undefined,
412
+ signatures: options.signatures.map((signature) => ({
413
+ bcs: {
414
+ value: fromBase64(signature),
415
+ },
416
+ signature: {
417
+ oneofKind: undefined,
418
+ },
419
+ })),
420
+ readMask: {
421
+ paths,
388
422
  },
389
- })),
390
- readMask: {
391
- paths,
392
423
  },
393
- });
424
+ { abort: options.signal },
425
+ );
394
426
 
395
- return parseTransaction(response.transaction!, options.include);
427
+ return parseGrpcTransactionResponse(response.transaction!, { include: options.include });
396
428
  }
397
429
  async simulateTransaction<Include extends SuiClientTypes.SimulateTransactionInclude = {}>(
398
430
  options: SuiClientTypes.SimulateTransactionOptions<Include>,
@@ -436,72 +468,56 @@ export class GrpcCoreClient extends CoreClient {
436
468
  await options.transaction.prepareForSerialization({ client: this });
437
469
  }
438
470
 
439
- const { response } = await this.#client.transactionExecutionService.simulateTransaction({
440
- transaction:
441
- options.transaction instanceof Uint8Array
442
- ? {
443
- bcs: {
444
- value: options.transaction,
445
- },
446
- }
447
- : transactionToGrpcTransaction(options.transaction),
448
- readMask: {
449
- paths,
471
+ const { response } = await this.#client.transactionExecutionService.simulateTransaction(
472
+ {
473
+ transaction:
474
+ options.transaction instanceof Uint8Array
475
+ ? {
476
+ bcs: {
477
+ value: options.transaction,
478
+ },
479
+ }
480
+ : transactionToGrpcTransaction(options.transaction),
481
+ readMask: {
482
+ paths,
483
+ },
484
+ doGasSelection: false,
485
+ checks:
486
+ options.checksEnabled === false
487
+ ? SimulateTransactionRequest_TransactionChecks.DISABLED
488
+ : SimulateTransactionRequest_TransactionChecks.ENABLED,
450
489
  },
451
- doGasSelection: false,
452
- checks:
453
- options.checksEnabled === false
454
- ? SimulateTransactionRequest_TransactionChecks.DISABLED
455
- : SimulateTransactionRequest_TransactionChecks.ENABLED,
456
- });
490
+ { abort: options.signal },
491
+ );
457
492
 
458
- const transactionResult = parseTransaction(response.transaction!, options.include);
459
-
460
- // Add command results if requested
461
- const commandResults =
462
- options.include?.commandResults && response.commandOutputs
463
- ? response.commandOutputs.map((output) => ({
464
- returnValues: (output.returnValues ?? []).map((rv) => ({
465
- bcs: rv.value?.value ?? null,
466
- })),
467
- mutatedReferences: (output.mutatedByRef ?? []).map((mr) => ({
468
- bcs: mr.value?.value ?? null,
469
- })),
470
- }))
471
- : undefined;
472
-
473
- if (transactionResult.$kind === 'Transaction') {
474
- return {
475
- $kind: 'Transaction',
476
- Transaction: transactionResult.Transaction,
477
- commandResults:
478
- commandResults as SuiClientTypes.SimulateTransactionResult<Include>['commandResults'],
479
- };
480
- } else {
481
- return {
482
- $kind: 'FailedTransaction',
483
- FailedTransaction: transactionResult.FailedTransaction,
484
- commandResults:
485
- commandResults as SuiClientTypes.SimulateTransactionResult<Include>['commandResults'],
486
- };
487
- }
493
+ return parseGrpcSimulateTransactionResponse(response, { include: options.include });
488
494
  }
489
- async getReferenceGasPrice(): Promise<SuiClientTypes.GetReferenceGasPriceResponse> {
490
- const response = await this.#client.ledgerService.getEpoch({
491
- readMask: {
492
- paths: ['reference_gas_price'],
495
+ async getReferenceGasPrice(
496
+ options?: SuiClientTypes.GetReferenceGasPriceOptions,
497
+ ): Promise<SuiClientTypes.GetReferenceGasPriceResponse> {
498
+ const response = await this.#client.ledgerService.getEpoch(
499
+ {
500
+ readMask: {
501
+ paths: ['reference_gas_price'],
502
+ },
493
503
  },
494
- });
504
+ { abort: options?.signal },
505
+ );
495
506
 
496
507
  return {
497
508
  referenceGasPrice: response.response.epoch?.referenceGasPrice?.toString() ?? '',
498
509
  };
499
510
  }
500
511
 
501
- async getProtocolConfig(): Promise<SuiClientTypes.GetProtocolConfigResponse> {
502
- const response = await this.#client.ledgerService.getEpoch({
503
- readMask: { paths: ['protocol_config'] },
504
- });
512
+ async getProtocolConfig(
513
+ options?: SuiClientTypes.GetProtocolConfigOptions,
514
+ ): Promise<SuiClientTypes.GetProtocolConfigResponse> {
515
+ const response = await this.#client.ledgerService.getEpoch(
516
+ {
517
+ readMask: { paths: ['protocol_config'] },
518
+ },
519
+ { abort: options?.signal },
520
+ );
505
521
 
506
522
  const protocolConfig = response.response.epoch?.protocolConfig;
507
523
  if (!protocolConfig) {
@@ -525,26 +541,31 @@ export class GrpcCoreClient extends CoreClient {
525
541
  };
526
542
  }
527
543
 
528
- async getCurrentSystemState(): Promise<SuiClientTypes.GetCurrentSystemStateResponse> {
529
- const response = await this.#client.ledgerService.getEpoch({
530
- readMask: {
531
- paths: [
532
- 'system_state.version',
533
- 'system_state.epoch',
534
- 'system_state.protocol_version',
535
- 'system_state.reference_gas_price',
536
- 'system_state.epoch_start_timestamp_ms',
537
- 'system_state.safe_mode',
538
- 'system_state.safe_mode_storage_rewards',
539
- 'system_state.safe_mode_computation_rewards',
540
- 'system_state.safe_mode_storage_rebates',
541
- 'system_state.safe_mode_non_refundable_storage_fee',
542
- 'system_state.parameters',
543
- 'system_state.storage_fund',
544
- 'system_state.stake_subsidy',
545
- ],
544
+ async getCurrentSystemState(
545
+ options?: SuiClientTypes.GetCurrentSystemStateOptions,
546
+ ): Promise<SuiClientTypes.GetCurrentSystemStateResponse> {
547
+ const response = await this.#client.ledgerService.getEpoch(
548
+ {
549
+ readMask: {
550
+ paths: [
551
+ 'system_state.version',
552
+ 'system_state.epoch',
553
+ 'system_state.protocol_version',
554
+ 'system_state.reference_gas_price',
555
+ 'system_state.epoch_start_timestamp_ms',
556
+ 'system_state.safe_mode',
557
+ 'system_state.safe_mode_storage_rewards',
558
+ 'system_state.safe_mode_computation_rewards',
559
+ 'system_state.safe_mode_storage_rebates',
560
+ 'system_state.safe_mode_non_refundable_storage_fee',
561
+ 'system_state.parameters',
562
+ 'system_state.storage_fund',
563
+ 'system_state.stake_subsidy',
564
+ ],
565
+ },
546
566
  },
547
- });
567
+ { abort: options?.signal },
568
+ );
548
569
 
549
570
  const epoch = response.response.epoch;
550
571
  const systemState = epoch?.systemState;
@@ -624,22 +645,25 @@ export class GrpcCoreClient extends CoreClient {
624
645
  ? bcs.byteVector().serialize(messageBytes).toBytes()
625
646
  : messageBytes;
626
647
 
627
- const { response } = await this.#client.signatureVerificationService.verifySignature({
628
- message: {
629
- name: options.intentScope,
630
- value: messageValue,
631
- },
632
- signature: {
633
- bcs: {
634
- value: fromBase64(options.signature),
648
+ const { response } = await this.#client.signatureVerificationService.verifySignature(
649
+ {
650
+ message: {
651
+ name: options.intentScope,
652
+ value: messageValue,
635
653
  },
636
654
  signature: {
637
- oneofKind: undefined,
655
+ bcs: {
656
+ value: fromBase64(options.signature),
657
+ },
658
+ signature: {
659
+ oneofKind: undefined,
660
+ },
638
661
  },
662
+ address: options.address,
663
+ jwks: [],
639
664
  },
640
- address: options.address,
641
- jwks: [],
642
- });
665
+ { abort: options.signal },
666
+ );
643
667
 
644
668
  return {
645
669
  success: response.isValid ?? false,
@@ -652,9 +676,12 @@ export class GrpcCoreClient extends CoreClient {
652
676
  ): Promise<SuiClientTypes.DefaultNameServiceNameResponse> {
653
677
  const name =
654
678
  (
655
- await this.#client.nameService.reverseLookupName({
656
- address: options.address,
657
- })
679
+ await this.#client.nameService.reverseLookupName(
680
+ {
681
+ address: options.address,
682
+ },
683
+ { abort: options.signal },
684
+ )
658
685
  ).response.record?.name ?? null;
659
686
  return {
660
687
  data: {
@@ -666,13 +693,17 @@ export class GrpcCoreClient extends CoreClient {
666
693
  async getMoveFunction(
667
694
  options: SuiClientTypes.GetMoveFunctionOptions,
668
695
  ): Promise<SuiClientTypes.GetMoveFunctionResponse> {
669
- const resolvedPackageId = (await this.mvr.resolvePackage({ package: options.packageId }))
670
- .package;
671
- const { response } = await this.#client.movePackageService.getFunction({
672
- packageId: resolvedPackageId,
673
- moduleName: options.moduleName,
674
- name: options.name,
675
- });
696
+ const resolvedPackageId = (
697
+ await this.mvr.resolvePackage({ package: options.packageId, signal: options.signal })
698
+ ).package;
699
+ const { response } = await this.#client.movePackageService.getFunction(
700
+ {
701
+ packageId: resolvedPackageId,
702
+ moduleName: options.moduleName,
703
+ name: options.name,
704
+ },
705
+ { abort: options.signal },
706
+ );
676
707
 
677
708
  let visibility: 'public' | 'private' | 'friend' | 'unknown' = 'unknown';
678
709
 
@@ -722,17 +753,24 @@ export class GrpcCoreClient extends CoreClient {
722
753
  }
723
754
 
724
755
  async getChainIdentifier(
725
- _options?: SuiClientTypes.GetChainIdentifierOptions,
756
+ options?: SuiClientTypes.GetChainIdentifierOptions,
726
757
  ): Promise<SuiClientTypes.GetChainIdentifierResponse> {
727
- return this.cache.read(['chainIdentifier'], async () => {
728
- const { response } = await this.#client.ledgerService.getServiceInfo({});
729
- if (!response.chainId) {
730
- throw new Error('Chain identifier not found in service info');
731
- }
732
- return {
733
- chainIdentifier: response.chainId,
734
- };
735
- });
758
+ // The result is cached and shared across callers, so the underlying request must
759
+ // not carry any single caller's signal. Isolate cancellation per-caller instead.
760
+ return raceSignal(
761
+ Promise.resolve(
762
+ this.cache.read(['chainIdentifier'], async () => {
763
+ const { response } = await this.#client.ledgerService.getServiceInfo({});
764
+ if (!response.chainId) {
765
+ throw new Error('Chain identifier not found in service info');
766
+ }
767
+ return {
768
+ chainIdentifier: response.chainId,
769
+ };
770
+ }),
771
+ ),
772
+ options?.signal,
773
+ );
736
774
  }
737
775
 
738
776
  resolveTransactionPlugin() {
@@ -1209,10 +1247,15 @@ export function parseTransactionEffects({
1209
1247
  };
1210
1248
  }
1211
1249
 
1212
- function parseTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(
1250
+ export function parseGrpcTransactionResponse<
1251
+ Include extends SuiClientTypes.TransactionInclude = {},
1252
+ >(
1213
1253
  transaction: ExecutedTransaction,
1214
- include?: Include,
1254
+ options?: {
1255
+ include?: Include & SuiClientTypes.TransactionInclude;
1256
+ },
1215
1257
  ): SuiClientTypes.TransactionResult<Include> {
1258
+ const include = options?.include;
1216
1259
  const objectTypes: Record<string, string> = {};
1217
1260
  if (include?.objectTypes) {
1218
1261
  transaction.effects?.changedObjects?.forEach((change) => {
@@ -1303,6 +1346,46 @@ function parseTransaction<Include extends SuiClientTypes.TransactionInclude = {}
1303
1346
  };
1304
1347
  }
1305
1348
 
1349
+ export function parseGrpcSimulateTransactionResponse<
1350
+ Include extends SuiClientTypes.SimulateTransactionInclude = {},
1351
+ >(
1352
+ response: SimulateTransactionResponse,
1353
+ options?: {
1354
+ include?: Include & SuiClientTypes.SimulateTransactionInclude;
1355
+ },
1356
+ ): SuiClientTypes.SimulateTransactionResult<Include> {
1357
+ const include = options?.include;
1358
+ const transactionResult = parseGrpcTransactionResponse(response.transaction!, { include });
1359
+
1360
+ const commandResults =
1361
+ include?.commandResults && response.commandOutputs
1362
+ ? response.commandOutputs.map((output) => ({
1363
+ returnValues: (output.returnValues ?? []).map((rv) => ({
1364
+ bcs: rv.value?.value ?? null,
1365
+ })),
1366
+ mutatedReferences: (output.mutatedByRef ?? []).map((mr) => ({
1367
+ bcs: mr.value?.value ?? null,
1368
+ })),
1369
+ }))
1370
+ : undefined;
1371
+
1372
+ if (transactionResult.$kind === 'Transaction') {
1373
+ return {
1374
+ $kind: 'Transaction',
1375
+ Transaction: transactionResult.Transaction,
1376
+ commandResults:
1377
+ commandResults as SuiClientTypes.SimulateTransactionResult<Include>['commandResults'],
1378
+ };
1379
+ }
1380
+
1381
+ return {
1382
+ $kind: 'FailedTransaction',
1383
+ FailedTransaction: transactionResult.FailedTransaction,
1384
+ commandResults:
1385
+ commandResults as SuiClientTypes.SimulateTransactionResult<Include>['commandResults'],
1386
+ };
1387
+ }
1388
+
1306
1389
  function parseNormalizedSuiMoveType(type: OpenSignature): SuiClientTypes.OpenSignature {
1307
1390
  let reference: 'mutable' | 'immutable' | null = null;
1308
1391
 
package/src/grpc/index.ts CHANGED
@@ -2,7 +2,11 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  export { SuiGrpcClient, isSuiGrpcClient } from './client.js';
5
- export { GrpcCoreClient } from './core.js';
5
+ export {
6
+ GrpcCoreClient,
7
+ parseGrpcSimulateTransactionResponse,
8
+ parseGrpcTransactionResponse,
9
+ } from './core.js';
6
10
  export type { SuiGrpcClientOptions } from './client.js';
7
11
  export type { GrpcCoreClientOptions } from './core.js';
8
12