@mysten/sui 2.5.1 → 2.7.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.
- package/CHANGELOG.md +29 -0
- package/dist/bcs/bcs.d.mts +6 -6
- package/dist/client/core-resolver.mjs +6 -3
- package/dist/client/core-resolver.mjs.map +1 -1
- package/dist/client/core.d.mts +8 -8
- package/dist/client/core.d.mts.map +1 -1
- package/dist/client/core.mjs +11 -5
- package/dist/client/core.mjs.map +1 -1
- package/dist/client/types.d.mts +73 -18
- package/dist/client/types.d.mts.map +1 -1
- package/dist/cryptography/signature.d.mts +6 -6
- package/dist/graphql/client.d.mts +16 -1
- package/dist/graphql/client.d.mts.map +1 -1
- package/dist/graphql/client.mjs +50 -2
- package/dist/graphql/client.mjs.map +1 -1
- package/dist/graphql/core.d.mts +5 -5
- package/dist/graphql/core.d.mts.map +1 -1
- package/dist/graphql/core.mjs +28 -49
- package/dist/graphql/core.mjs.map +1 -1
- package/dist/graphql/generated/queries.d.mts.map +1 -1
- package/dist/graphql/generated/queries.mjs +25 -7
- package/dist/graphql/generated/queries.mjs.map +1 -1
- package/dist/graphql/generated/tada-env.d.mts +706 -98
- package/dist/grpc/client.d.mts +16 -1
- package/dist/grpc/client.d.mts.map +1 -1
- package/dist/grpc/client.mjs +42 -2
- package/dist/grpc/client.mjs.map +1 -1
- package/dist/grpc/core.d.mts +5 -5
- package/dist/grpc/core.d.mts.map +1 -1
- package/dist/grpc/core.mjs +18 -35
- package/dist/grpc/core.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/object.d.mts +38 -1
- package/dist/grpc/proto/sui/rpc/v2/object.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/object.mjs +26 -1
- package/dist/grpc/proto/sui/rpc/v2/object.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/state_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/transaction.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.d.mts +8 -0
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.mjs +23 -12
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.mjs.map +1 -1
- package/dist/grpc/proto/types.d.mts +2 -2
- package/dist/grpc/proto/types.mjs +2 -1
- package/dist/jsonRpc/core.d.mts +6 -6
- package/dist/jsonRpc/core.d.mts.map +1 -1
- package/dist/jsonRpc/core.mjs +14 -5
- package/dist/jsonRpc/core.mjs.map +1 -1
- package/dist/transactions/Transaction.d.mts +6 -6
- package/dist/transactions/Transaction.d.mts.map +1 -1
- package/dist/transactions/executor/caching.mjs.map +1 -1
- package/dist/transactions/executor/parallel.d.mts +1 -1
- package/dist/transactions/executor/parallel.d.mts.map +1 -1
- package/dist/transactions/executor/parallel.mjs.map +1 -1
- package/dist/transactions/executor/serial.d.mts +1 -1
- package/dist/transactions/executor/serial.d.mts.map +1 -1
- package/dist/transactions/executor/serial.mjs.map +1 -1
- package/dist/version.mjs +1 -1
- package/dist/version.mjs.map +1 -1
- package/dist/zklogin/bcs.d.mts +14 -14
- package/package.json +1 -1
- package/src/client/core-resolver.ts +9 -8
- package/src/client/core.ts +28 -18
- package/src/client/types.ts +73 -18
- package/src/graphql/client.ts +96 -4
- package/src/graphql/core.ts +43 -88
- package/src/graphql/generated/queries.ts +271 -44
- package/src/graphql/generated/schema.graphql +328 -25
- package/src/graphql/generated/tada-env.ts +779 -58
- package/src/graphql/queries/getDynamicFields.graphql +8 -1
- package/src/graphql/queries/objects.graphql +10 -0
- package/src/graphql/queries/transactions.graphql +1 -3
- package/src/graphql/queries/verifyZkLoginSignature.graphql +0 -1
- package/src/grpc/client.ts +62 -4
- package/src/grpc/core.ts +42 -39
- package/src/grpc/proto/sui/rpc/v2/object.ts +44 -0
- package/src/grpc/proto/sui/rpc/v2/transaction_execution_service.ts +16 -0
- package/src/jsonRpc/core.ts +18 -7
- package/src/transactions/executor/caching.ts +2 -2
- package/src/transactions/executor/parallel.ts +1 -1
- package/src/transactions/executor/serial.ts +1 -1
- package/src/version.ts +1 -1
package/src/client/types.ts
CHANGED
|
@@ -58,24 +58,54 @@ export namespace SuiClientTypes {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
export interface ObjectInclude {
|
|
61
|
+
/**
|
|
62
|
+
* Include the BCS-encoded Move struct content of the object.
|
|
63
|
+
*
|
|
64
|
+
* Returns the raw bytes of the object's Move struct fields — pass directly to
|
|
65
|
+
* generated BCS types (e.g., `MyStruct.parse(object.content)`).
|
|
66
|
+
*/
|
|
61
67
|
content?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Include the digest of the transaction that last mutated this object.
|
|
70
|
+
*/
|
|
62
71
|
previousTransaction?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Include the full BCS-encoded object envelope. Rarely needed — most metadata
|
|
74
|
+
* (owner, version, type) is already available as fields on the object response.
|
|
75
|
+
*
|
|
76
|
+
* Parse with `bcs.Object.parse(object.objectBcs)` from `@mysten/sui/bcs`.
|
|
77
|
+
* Do not pass to a Move struct parser — use `content` for that instead.
|
|
78
|
+
*/
|
|
63
79
|
objectBcs?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Include the JSON representation of the object's Move struct content.
|
|
82
|
+
*
|
|
83
|
+
* **Warning:** The exact shape and field names of this data may vary between different
|
|
84
|
+
* API implementations (JSON-RPC vs gRPC or GraphQL). For consistent data across APIs,
|
|
85
|
+
* use the `content` field and parse the BCS data directly.
|
|
86
|
+
*/
|
|
64
87
|
json?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Include the Display v2 rendered output for the object.
|
|
90
|
+
*
|
|
91
|
+
* Returns a map of display field names to their rendered string values.
|
|
92
|
+
* Returns `null` if the object's type does not have an associated Display template.
|
|
93
|
+
*/
|
|
94
|
+
display?: boolean;
|
|
65
95
|
}
|
|
66
96
|
|
|
67
97
|
export interface GetObjectsOptions<
|
|
68
98
|
Include extends ObjectInclude = {},
|
|
69
99
|
> extends CoreClientMethodOptions {
|
|
70
100
|
objectIds: string[];
|
|
71
|
-
include?: Include;
|
|
101
|
+
include?: Include & ObjectInclude;
|
|
72
102
|
}
|
|
73
103
|
|
|
74
104
|
export interface GetObjectOptions<
|
|
75
105
|
Include extends ObjectInclude = {},
|
|
76
106
|
> extends CoreClientMethodOptions {
|
|
77
107
|
objectId: string;
|
|
78
|
-
include?: Include;
|
|
108
|
+
include?: Include & ObjectInclude;
|
|
79
109
|
}
|
|
80
110
|
|
|
81
111
|
export interface ListOwnedObjectsOptions<
|
|
@@ -85,7 +115,7 @@ export namespace SuiClientTypes {
|
|
|
85
115
|
limit?: number;
|
|
86
116
|
cursor?: string | null;
|
|
87
117
|
type?: string;
|
|
88
|
-
include?: Include;
|
|
118
|
+
include?: Include & ObjectInclude;
|
|
89
119
|
}
|
|
90
120
|
|
|
91
121
|
export interface ListCoinsOptions extends CoreClientMethodOptions {
|
|
@@ -133,8 +163,10 @@ export namespace SuiClientTypes {
|
|
|
133
163
|
digest: string;
|
|
134
164
|
owner: ObjectOwner;
|
|
135
165
|
type: string;
|
|
166
|
+
/** BCS-encoded Move struct content — pass to generated BCS type parsers. */
|
|
136
167
|
content: Include extends { content: true } ? Uint8Array<ArrayBuffer> : undefined;
|
|
137
168
|
previousTransaction: Include extends { previousTransaction: true } ? string | null : undefined;
|
|
169
|
+
/** Full BCS-encoded object envelope — parse with `bcs.Object` not a struct parser. */
|
|
138
170
|
objectBcs: Include extends { objectBcs: true } ? Uint8Array<ArrayBuffer> : undefined;
|
|
139
171
|
/**
|
|
140
172
|
* The JSON representation of the object's Move struct content.
|
|
@@ -144,6 +176,15 @@ export namespace SuiClientTypes {
|
|
|
144
176
|
* the `content` field and parse the BCS data directly.
|
|
145
177
|
*/
|
|
146
178
|
json: Include extends { json: true } ? Record<string, unknown> | null : undefined;
|
|
179
|
+
/** Display rendered output. `null` if the type has no Display template. */
|
|
180
|
+
display: Include extends { display: true } ? Display | null : undefined;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export interface Display {
|
|
184
|
+
/** Successfully rendered display field values, keyed by field name. */
|
|
185
|
+
output: Record<string, string> | null;
|
|
186
|
+
/** Per-field rendering errors, keyed by field name. `null` if all fields succeeded. */
|
|
187
|
+
errors: Record<string, string> | null;
|
|
147
188
|
}
|
|
148
189
|
|
|
149
190
|
export interface Coin {
|
|
@@ -162,6 +203,13 @@ export namespace SuiClientTypes {
|
|
|
162
203
|
valueType: string;
|
|
163
204
|
} & ({ $kind: 'DynamicField'; childId?: never } | { $kind: 'DynamicObject'; childId: string });
|
|
164
205
|
|
|
206
|
+
export type DynamicField = DynamicFieldEntry & {
|
|
207
|
+
value: DynamicFieldValue;
|
|
208
|
+
version: string;
|
|
209
|
+
digest: string;
|
|
210
|
+
previousTransaction: string | null;
|
|
211
|
+
};
|
|
212
|
+
|
|
165
213
|
export interface ListDynamicFieldsResponse {
|
|
166
214
|
hasNextPage: boolean;
|
|
167
215
|
cursor: string | null;
|
|
@@ -169,15 +217,7 @@ export namespace SuiClientTypes {
|
|
|
169
217
|
}
|
|
170
218
|
|
|
171
219
|
export interface GetDynamicFieldResponse {
|
|
172
|
-
dynamicField:
|
|
173
|
-
name: DynamicFieldName;
|
|
174
|
-
value: DynamicFieldValue;
|
|
175
|
-
fieldId: string;
|
|
176
|
-
version: string;
|
|
177
|
-
digest: string;
|
|
178
|
-
type: string;
|
|
179
|
-
previousTransaction: string | null;
|
|
180
|
-
};
|
|
220
|
+
dynamicField: DynamicField;
|
|
181
221
|
}
|
|
182
222
|
|
|
183
223
|
export interface GetDynamicObjectFieldOptions<
|
|
@@ -185,7 +225,7 @@ export namespace SuiClientTypes {
|
|
|
185
225
|
> extends CoreClientMethodOptions {
|
|
186
226
|
parentId: string;
|
|
187
227
|
name: DynamicFieldName;
|
|
188
|
-
include?: Include;
|
|
228
|
+
include?: Include & ObjectInclude;
|
|
189
229
|
}
|
|
190
230
|
|
|
191
231
|
export interface GetDynamicObjectFieldResponse<out Include extends ObjectInclude = {}> {
|
|
@@ -313,15 +353,22 @@ export namespace SuiClientTypes {
|
|
|
313
353
|
};
|
|
314
354
|
|
|
315
355
|
export interface TransactionInclude {
|
|
356
|
+
/** Include balance changes caused by the transaction. */
|
|
316
357
|
balanceChanges?: boolean;
|
|
358
|
+
/** Include parsed transaction effects (gas used, changed objects, status, etc.). */
|
|
317
359
|
effects?: boolean;
|
|
360
|
+
/** Include events emitted by the transaction. */
|
|
318
361
|
events?: boolean;
|
|
362
|
+
/** Include a map of object IDs to their types for all changed objects. */
|
|
319
363
|
objectTypes?: boolean;
|
|
364
|
+
/** Include the parsed transaction data (sender, gas config, inputs, commands). */
|
|
320
365
|
transaction?: boolean;
|
|
366
|
+
/** Include the raw BCS-encoded transaction bytes. */
|
|
321
367
|
bcs?: boolean;
|
|
322
368
|
}
|
|
323
369
|
|
|
324
370
|
export interface SimulateTransactionInclude extends TransactionInclude {
|
|
371
|
+
/** Include return values and mutated references from each command (simulation only). */
|
|
325
372
|
commandResults?: boolean;
|
|
326
373
|
}
|
|
327
374
|
|
|
@@ -346,7 +393,7 @@ export namespace SuiClientTypes {
|
|
|
346
393
|
Include extends TransactionInclude = {},
|
|
347
394
|
> extends CoreClientMethodOptions {
|
|
348
395
|
digest: string;
|
|
349
|
-
include?: Include;
|
|
396
|
+
include?: Include & TransactionInclude;
|
|
350
397
|
}
|
|
351
398
|
|
|
352
399
|
export type WaitForTransactionOptions<Include extends TransactionInclude = {}> =
|
|
@@ -364,7 +411,7 @@ export namespace SuiClientTypes {
|
|
|
364
411
|
Include extends TransactionInclude = {},
|
|
365
412
|
> extends CoreClientMethodOptions {
|
|
366
413
|
result: TransactionResult<any>;
|
|
367
|
-
include?: Include;
|
|
414
|
+
include?: Include & TransactionInclude;
|
|
368
415
|
timeout?: number;
|
|
369
416
|
digest?: never;
|
|
370
417
|
}
|
|
@@ -374,7 +421,7 @@ export namespace SuiClientTypes {
|
|
|
374
421
|
> extends CoreClientMethodOptions {
|
|
375
422
|
transaction: Uint8Array;
|
|
376
423
|
signatures: string[];
|
|
377
|
-
include?: Include;
|
|
424
|
+
include?: Include & TransactionInclude;
|
|
378
425
|
}
|
|
379
426
|
|
|
380
427
|
export interface SignAndExecuteTransactionOptions<
|
|
@@ -383,14 +430,14 @@ export namespace SuiClientTypes {
|
|
|
383
430
|
transaction: Uint8Array | TransactionInstance;
|
|
384
431
|
signer: Signer;
|
|
385
432
|
additionalSignatures?: string[];
|
|
386
|
-
include?: Include;
|
|
433
|
+
include?: Include & TransactionInclude;
|
|
387
434
|
}
|
|
388
435
|
|
|
389
436
|
export interface SimulateTransactionOptions<
|
|
390
437
|
Include extends SimulateTransactionInclude = {},
|
|
391
438
|
> extends CoreClientMethodOptions {
|
|
392
439
|
transaction: Uint8Array | TransactionInstance;
|
|
393
|
-
include?: Include;
|
|
440
|
+
include?: Include & SimulateTransactionInclude;
|
|
394
441
|
}
|
|
395
442
|
|
|
396
443
|
export interface GetReferenceGasPriceOptions extends CoreClientMethodOptions {}
|
|
@@ -816,6 +863,14 @@ export namespace SuiClientTypes {
|
|
|
816
863
|
sender: string;
|
|
817
864
|
eventType: string;
|
|
818
865
|
bcs: Uint8Array;
|
|
866
|
+
/**
|
|
867
|
+
* The JSON representation of the event's Move struct data.
|
|
868
|
+
*
|
|
869
|
+
* **Warning:** The exact shape and field names of this data may vary between different
|
|
870
|
+
* API implementations (JSON-RPC vs gRPC or GraphQL). For consistent data across APIs use
|
|
871
|
+
* the `bcs` field and parse the BCS data directly.
|
|
872
|
+
*/
|
|
873
|
+
json: Record<string, unknown> | null;
|
|
819
874
|
}
|
|
820
875
|
|
|
821
876
|
export interface MoveAbort {
|
package/src/graphql/client.ts
CHANGED
|
@@ -9,6 +9,10 @@ import { BaseClient } from '../client/index.js';
|
|
|
9
9
|
import type { SuiClientTypes } from '../client/index.js';
|
|
10
10
|
import { GraphQLCoreClient } from './core.js';
|
|
11
11
|
import type { TypedDocumentString } from './generated/queries.js';
|
|
12
|
+
import { GetDynamicFieldsDocument } from './generated/queries.js';
|
|
13
|
+
import { fromBase64 } from '@mysten/utils';
|
|
14
|
+
import { normalizeStructTag } from '../utils/sui-types.js';
|
|
15
|
+
import { deriveDynamicFieldID } from '../utils/dynamic-fields.js';
|
|
12
16
|
import type { TransactionPlugin } from '../transactions/index.js';
|
|
13
17
|
|
|
14
18
|
export type GraphQLDocument<
|
|
@@ -66,6 +70,21 @@ export function isSuiGraphQLClient(client: unknown): client is SuiGraphQLClient
|
|
|
66
70
|
);
|
|
67
71
|
}
|
|
68
72
|
|
|
73
|
+
export interface DynamicFieldInclude {
|
|
74
|
+
value?: boolean;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export type DynamicFieldEntryWithValue<Include extends DynamicFieldInclude = {}> =
|
|
78
|
+
SuiClientTypes.DynamicFieldEntry & {
|
|
79
|
+
value: Include extends { value: true } ? SuiClientTypes.DynamicFieldValue : undefined;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export interface ListDynamicFieldsWithValueResponse<Include extends DynamicFieldInclude = {}> {
|
|
83
|
+
hasNextPage: boolean;
|
|
84
|
+
cursor: string | null;
|
|
85
|
+
dynamicFields: DynamicFieldEntryWithValue<Include>[];
|
|
86
|
+
}
|
|
87
|
+
|
|
69
88
|
export class SuiGraphQLClient<Queries extends Record<string, GraphQLDocument> = {}>
|
|
70
89
|
extends BaseClient
|
|
71
90
|
implements SuiClientTypes.TransportMethods
|
|
@@ -220,10 +239,83 @@ export class SuiGraphQLClient<Queries extends Record<string, GraphQLDocument> =
|
|
|
220
239
|
return this.core.getReferenceGasPrice();
|
|
221
240
|
}
|
|
222
241
|
|
|
223
|
-
listDynamicFields(
|
|
224
|
-
input: SuiClientTypes.ListDynamicFieldsOptions,
|
|
225
|
-
): Promise<
|
|
226
|
-
|
|
242
|
+
async listDynamicFields<Include extends DynamicFieldInclude = {}>(
|
|
243
|
+
input: SuiClientTypes.ListDynamicFieldsOptions & { include?: Include & DynamicFieldInclude },
|
|
244
|
+
): Promise<ListDynamicFieldsWithValueResponse<Include>> {
|
|
245
|
+
const includeValue = input.include?.value ?? false;
|
|
246
|
+
|
|
247
|
+
const { data, errors } = await this.query({
|
|
248
|
+
query: GetDynamicFieldsDocument,
|
|
249
|
+
variables: {
|
|
250
|
+
parentId: input.parentId,
|
|
251
|
+
first: input.limit,
|
|
252
|
+
cursor: input.cursor,
|
|
253
|
+
includeValue,
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
if (errors?.length) {
|
|
258
|
+
throw errors.length === 1
|
|
259
|
+
? new Error(errors[0].message)
|
|
260
|
+
: new AggregateError(errors.map((e) => new Error(e.message)));
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const result = data?.address?.dynamicFields;
|
|
264
|
+
if (!result) {
|
|
265
|
+
throw new Error('Missing response data');
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return {
|
|
269
|
+
dynamicFields: result.nodes.map((dynamicField): DynamicFieldEntryWithValue<Include> => {
|
|
270
|
+
const valueType =
|
|
271
|
+
dynamicField.value?.__typename === 'MoveObject'
|
|
272
|
+
? dynamicField.value.contents?.type?.repr!
|
|
273
|
+
: dynamicField.value?.type?.repr!;
|
|
274
|
+
const isDynamicObject = dynamicField.value?.__typename === 'MoveObject';
|
|
275
|
+
const derivedNameType = isDynamicObject
|
|
276
|
+
? `0x2::dynamic_object_field::Wrapper<${dynamicField.name?.type?.repr}>`
|
|
277
|
+
: dynamicField.name?.type?.repr!;
|
|
278
|
+
|
|
279
|
+
let value: SuiClientTypes.DynamicFieldValue | undefined;
|
|
280
|
+
if (includeValue) {
|
|
281
|
+
let valueBcs: Uint8Array;
|
|
282
|
+
if (dynamicField.value?.__typename === 'MoveValue') {
|
|
283
|
+
valueBcs = fromBase64(dynamicField.value.bcs ?? '');
|
|
284
|
+
} else if (dynamicField.value?.__typename === 'MoveObject') {
|
|
285
|
+
valueBcs = fromBase64(dynamicField.value.contents?.bcs ?? '');
|
|
286
|
+
} else {
|
|
287
|
+
valueBcs = new Uint8Array();
|
|
288
|
+
}
|
|
289
|
+
value = { type: valueType, bcs: valueBcs };
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return {
|
|
293
|
+
$kind: isDynamicObject ? 'DynamicObject' : 'DynamicField',
|
|
294
|
+
fieldId: deriveDynamicFieldID(
|
|
295
|
+
input.parentId,
|
|
296
|
+
derivedNameType,
|
|
297
|
+
fromBase64(dynamicField.name?.bcs!),
|
|
298
|
+
),
|
|
299
|
+
type: normalizeStructTag(
|
|
300
|
+
isDynamicObject
|
|
301
|
+
? `0x2::dynamic_field::Field<0x2::dynamic_object_field::Wrapper<${dynamicField.name?.type?.repr}>,0x2::object::ID>`
|
|
302
|
+
: `0x2::dynamic_field::Field<${dynamicField.name?.type?.repr},${valueType}>`,
|
|
303
|
+
),
|
|
304
|
+
name: {
|
|
305
|
+
type: dynamicField.name?.type?.repr!,
|
|
306
|
+
bcs: fromBase64(dynamicField.name?.bcs!),
|
|
307
|
+
},
|
|
308
|
+
valueType,
|
|
309
|
+
childId:
|
|
310
|
+
isDynamicObject && dynamicField.value?.__typename === 'MoveObject'
|
|
311
|
+
? dynamicField.value.address
|
|
312
|
+
: undefined,
|
|
313
|
+
value: (includeValue ? value : undefined) as DynamicFieldEntryWithValue<Include>['value'],
|
|
314
|
+
} as DynamicFieldEntryWithValue<Include>;
|
|
315
|
+
}),
|
|
316
|
+
cursor: result.pageInfo.endCursor ?? null,
|
|
317
|
+
hasNextPage: result.pageInfo.hasNextPage,
|
|
318
|
+
};
|
|
227
319
|
}
|
|
228
320
|
|
|
229
321
|
getDynamicField(
|
package/src/graphql/core.ts
CHANGED
|
@@ -23,7 +23,6 @@ import {
|
|
|
23
23
|
GetCoinMetadataDocument,
|
|
24
24
|
GetCoinsDocument,
|
|
25
25
|
GetCurrentSystemStateDocument,
|
|
26
|
-
GetDynamicFieldsDocument,
|
|
27
26
|
GetMoveFunctionDocument,
|
|
28
27
|
GetOwnedObjectsDocument,
|
|
29
28
|
GetReferenceGasPriceDocument,
|
|
@@ -36,8 +35,7 @@ import {
|
|
|
36
35
|
} from './generated/queries.js';
|
|
37
36
|
import { ObjectError, SimulationError } from '../client/errors.js';
|
|
38
37
|
import { chunk, fromBase64, toBase64 } from '@mysten/utils';
|
|
39
|
-
import {
|
|
40
|
-
import { deriveDynamicFieldID } from '../utils/dynamic-fields.js';
|
|
38
|
+
import { normalizeSuiAddress } from '../utils/sui-types.js';
|
|
41
39
|
import { formatMoveAbortMessage, parseTransactionEffectsBcs } from '../client/utils.js';
|
|
42
40
|
import type { OpenMoveTypeSignatureBody, OpenMoveTypeSignature } from './types.js';
|
|
43
41
|
import {
|
|
@@ -86,7 +84,7 @@ export class GraphQLCoreClient extends CoreClient {
|
|
|
86
84
|
return extractedData as NonNullable<Data>;
|
|
87
85
|
}
|
|
88
86
|
|
|
89
|
-
async getObjects<Include extends SuiClientTypes.ObjectInclude =
|
|
87
|
+
async getObjects<Include extends SuiClientTypes.ObjectInclude = {}>(
|
|
90
88
|
options: SuiClientTypes.GetObjectsOptions<Include>,
|
|
91
89
|
): Promise<SuiClientTypes.GetObjectsResponse<Include>> {
|
|
92
90
|
const batches = chunk(options.objectIds, 50);
|
|
@@ -102,6 +100,7 @@ export class GraphQLCoreClient extends CoreClient {
|
|
|
102
100
|
includePreviousTransaction: options.include?.previousTransaction ?? false,
|
|
103
101
|
includeObjectBcs: options.include?.objectBcs ?? false,
|
|
104
102
|
includeJson: options.include?.json ?? false,
|
|
103
|
+
includeDisplay: options.include?.display ?? false,
|
|
105
104
|
},
|
|
106
105
|
},
|
|
107
106
|
(result) => result.multiGetObjects,
|
|
@@ -141,6 +140,11 @@ export class GraphQLCoreClient extends CoreClient {
|
|
|
141
140
|
: null
|
|
142
141
|
: undefined;
|
|
143
142
|
|
|
143
|
+
const displayData = mapDisplay(
|
|
144
|
+
options.include?.display,
|
|
145
|
+
obj.asMoveObject?.contents?.display,
|
|
146
|
+
);
|
|
147
|
+
|
|
144
148
|
return {
|
|
145
149
|
objectId: obj.address,
|
|
146
150
|
version: obj.version?.toString()!,
|
|
@@ -152,6 +156,7 @@ export class GraphQLCoreClient extends CoreClient {
|
|
|
152
156
|
undefined) as SuiClientTypes.Object<Include>['previousTransaction'],
|
|
153
157
|
objectBcs: objectBcs as SuiClientTypes.Object<Include>['objectBcs'],
|
|
154
158
|
json: jsonContent as SuiClientTypes.Object<Include>['json'],
|
|
159
|
+
display: displayData as SuiClientTypes.Object<Include>['display'],
|
|
155
160
|
};
|
|
156
161
|
}),
|
|
157
162
|
);
|
|
@@ -161,7 +166,7 @@ export class GraphQLCoreClient extends CoreClient {
|
|
|
161
166
|
objects: results,
|
|
162
167
|
};
|
|
163
168
|
}
|
|
164
|
-
async listOwnedObjects<Include extends SuiClientTypes.ObjectInclude =
|
|
169
|
+
async listOwnedObjects<Include extends SuiClientTypes.ObjectInclude = {}>(
|
|
165
170
|
options: SuiClientTypes.ListOwnedObjectsOptions<Include>,
|
|
166
171
|
): Promise<SuiClientTypes.ListOwnedObjectsResponse<Include>> {
|
|
167
172
|
const objects = await this.#graphqlQuery(
|
|
@@ -178,6 +183,7 @@ export class GraphQLCoreClient extends CoreClient {
|
|
|
178
183
|
includePreviousTransaction: options.include?.previousTransaction ?? false,
|
|
179
184
|
includeObjectBcs: options.include?.objectBcs ?? false,
|
|
180
185
|
includeJson: options.include?.json ?? false,
|
|
186
|
+
includeDisplay: options.include?.display ?? false,
|
|
181
187
|
},
|
|
182
188
|
},
|
|
183
189
|
(result) => result.address?.objects,
|
|
@@ -204,6 +210,10 @@ export class GraphQLCoreClient extends CoreClient {
|
|
|
204
210
|
? (obj.contents.json as Record<string, unknown>)
|
|
205
211
|
: null
|
|
206
212
|
: undefined) as SuiClientTypes.Object<Include>['json'],
|
|
213
|
+
display: mapDisplay(
|
|
214
|
+
options.include?.display,
|
|
215
|
+
obj.contents?.display,
|
|
216
|
+
) as SuiClientTypes.Object<Include>['display'],
|
|
207
217
|
}),
|
|
208
218
|
),
|
|
209
219
|
hasNextPage: objects.pageInfo.hasNextPage,
|
|
@@ -326,7 +336,7 @@ export class GraphQLCoreClient extends CoreClient {
|
|
|
326
336
|
}),
|
|
327
337
|
};
|
|
328
338
|
}
|
|
329
|
-
async getTransaction<Include extends SuiClientTypes.TransactionInclude =
|
|
339
|
+
async getTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(
|
|
330
340
|
options: SuiClientTypes.GetTransactionOptions<Include>,
|
|
331
341
|
): Promise<SuiClientTypes.TransactionResult<Include>> {
|
|
332
342
|
const result = await this.#graphqlQuery(
|
|
@@ -347,7 +357,7 @@ export class GraphQLCoreClient extends CoreClient {
|
|
|
347
357
|
|
|
348
358
|
return parseTransaction(result, options.include);
|
|
349
359
|
}
|
|
350
|
-
async executeTransaction<Include extends SuiClientTypes.TransactionInclude =
|
|
360
|
+
async executeTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(
|
|
351
361
|
options: SuiClientTypes.ExecuteTransactionOptions<Include>,
|
|
352
362
|
): Promise<SuiClientTypes.TransactionResult<Include>> {
|
|
353
363
|
const result = await this.#graphqlQuery(
|
|
@@ -367,16 +377,9 @@ export class GraphQLCoreClient extends CoreClient {
|
|
|
367
377
|
(result) => result.executeTransaction,
|
|
368
378
|
);
|
|
369
379
|
|
|
370
|
-
if (result.errors) {
|
|
371
|
-
if (result.errors.length === 1) {
|
|
372
|
-
throw new Error(result.errors[0]);
|
|
373
|
-
}
|
|
374
|
-
throw new AggregateError(result.errors.map((error) => new Error(error)));
|
|
375
|
-
}
|
|
376
|
-
|
|
377
380
|
return parseTransaction(result.effects?.transaction!, options.include);
|
|
378
381
|
}
|
|
379
|
-
async simulateTransaction<Include extends SuiClientTypes.SimulateTransactionInclude =
|
|
382
|
+
async simulateTransaction<Include extends SuiClientTypes.SimulateTransactionInclude = {}>(
|
|
380
383
|
options: SuiClientTypes.SimulateTransactionOptions<Include>,
|
|
381
384
|
): Promise<SuiClientTypes.SimulateTransactionResult<Include>> {
|
|
382
385
|
if (!(options.transaction instanceof Uint8Array)) {
|
|
@@ -407,10 +410,6 @@ export class GraphQLCoreClient extends CoreClient {
|
|
|
407
410
|
(result) => result.simulateTransaction,
|
|
408
411
|
);
|
|
409
412
|
|
|
410
|
-
if (result.error && !result.effects?.transaction) {
|
|
411
|
-
throw new SimulationError(result.error);
|
|
412
|
-
}
|
|
413
|
-
|
|
414
413
|
const transactionResult = parseTransaction(result.effects?.transaction!, options.include);
|
|
415
414
|
|
|
416
415
|
const commandResults =
|
|
@@ -558,55 +557,7 @@ export class GraphQLCoreClient extends CoreClient {
|
|
|
558
557
|
async listDynamicFields(
|
|
559
558
|
options: SuiClientTypes.ListDynamicFieldsOptions,
|
|
560
559
|
): Promise<SuiClientTypes.ListDynamicFieldsResponse> {
|
|
561
|
-
|
|
562
|
-
{
|
|
563
|
-
query: GetDynamicFieldsDocument,
|
|
564
|
-
variables: {
|
|
565
|
-
parentId: options.parentId,
|
|
566
|
-
first: options.limit,
|
|
567
|
-
cursor: options.cursor,
|
|
568
|
-
},
|
|
569
|
-
},
|
|
570
|
-
(result) => result.address?.dynamicFields,
|
|
571
|
-
);
|
|
572
|
-
|
|
573
|
-
return {
|
|
574
|
-
dynamicFields: result.nodes.map((dynamicField): SuiClientTypes.DynamicFieldEntry => {
|
|
575
|
-
const valueType =
|
|
576
|
-
dynamicField.value?.__typename === 'MoveObject'
|
|
577
|
-
? dynamicField.value.contents?.type?.repr!
|
|
578
|
-
: dynamicField.value?.type?.repr!;
|
|
579
|
-
const isDynamicObject = dynamicField.value?.__typename === 'MoveObject';
|
|
580
|
-
const derivedNameType = isDynamicObject
|
|
581
|
-
? `0x2::dynamic_object_field::Wrapper<${dynamicField.name?.type?.repr}>`
|
|
582
|
-
: dynamicField.name?.type?.repr!;
|
|
583
|
-
|
|
584
|
-
return {
|
|
585
|
-
$kind: isDynamicObject ? 'DynamicObject' : 'DynamicField',
|
|
586
|
-
fieldId: deriveDynamicFieldID(
|
|
587
|
-
options.parentId,
|
|
588
|
-
derivedNameType,
|
|
589
|
-
fromBase64(dynamicField.name?.bcs!),
|
|
590
|
-
),
|
|
591
|
-
type: normalizeStructTag(
|
|
592
|
-
isDynamicObject
|
|
593
|
-
? `0x2::dynamic_field::Field<0x2::dynamic_object_field::Wrapper<${dynamicField.name?.type?.repr}>,0x2::object::ID>`
|
|
594
|
-
: `0x2::dynamic_field::Field<${dynamicField.name?.type?.repr},${valueType}>`,
|
|
595
|
-
),
|
|
596
|
-
name: {
|
|
597
|
-
type: dynamicField.name?.type?.repr!,
|
|
598
|
-
bcs: fromBase64(dynamicField.name?.bcs!),
|
|
599
|
-
},
|
|
600
|
-
valueType,
|
|
601
|
-
childId:
|
|
602
|
-
isDynamicObject && dynamicField.value?.__typename === 'MoveObject'
|
|
603
|
-
? dynamicField.value.address
|
|
604
|
-
: undefined,
|
|
605
|
-
} as SuiClientTypes.DynamicFieldEntry;
|
|
606
|
-
}),
|
|
607
|
-
cursor: result.pageInfo.endCursor ?? null,
|
|
608
|
-
hasNextPage: result.pageInfo.hasNextPage,
|
|
609
|
-
};
|
|
560
|
+
return this.#graphqlClient.listDynamicFields(options);
|
|
610
561
|
}
|
|
611
562
|
|
|
612
563
|
async verifyZkLoginSignature(
|
|
@@ -617,22 +568,19 @@ export class GraphQLCoreClient extends CoreClient {
|
|
|
617
568
|
? ZkLoginIntentScope.TransactionData
|
|
618
569
|
: ZkLoginIntentScope.PersonalMessage;
|
|
619
570
|
|
|
620
|
-
const
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
author: options.address,
|
|
628
|
-
},
|
|
571
|
+
const { data } = await this.#graphqlClient.query({
|
|
572
|
+
query: VerifyZkLoginSignatureDocument,
|
|
573
|
+
variables: {
|
|
574
|
+
bytes: options.bytes,
|
|
575
|
+
signature: options.signature,
|
|
576
|
+
intentScope,
|
|
577
|
+
author: options.address,
|
|
629
578
|
},
|
|
630
|
-
|
|
631
|
-
);
|
|
579
|
+
});
|
|
632
580
|
|
|
633
581
|
return {
|
|
634
|
-
success:
|
|
635
|
-
errors:
|
|
582
|
+
success: data?.verifyZkLoginSignature?.success ?? false,
|
|
583
|
+
errors: [],
|
|
636
584
|
};
|
|
637
585
|
}
|
|
638
586
|
|
|
@@ -765,12 +713,6 @@ export class GraphQLCoreClient extends CoreClient {
|
|
|
765
713
|
|
|
766
714
|
handleGraphQLErrors(errors);
|
|
767
715
|
|
|
768
|
-
if (data?.simulateTransaction?.error) {
|
|
769
|
-
throw new SimulationError(
|
|
770
|
-
`Transaction resolution failed: ${data.simulateTransaction.error}`,
|
|
771
|
-
);
|
|
772
|
-
}
|
|
773
|
-
|
|
774
716
|
const transactionEffects = data?.simulateTransaction?.effects?.transaction?.effects;
|
|
775
717
|
if (!options.onlyTransactionKind && transactionEffects?.status === ExecutionStatus.Failure) {
|
|
776
718
|
const executionError = parseGraphQLExecutionError(transactionEffects.executionError);
|
|
@@ -815,6 +757,18 @@ export type GraphQLResponseErrors = Array<{
|
|
|
815
757
|
path?: (string | number)[];
|
|
816
758
|
}>;
|
|
817
759
|
|
|
760
|
+
function mapDisplay(
|
|
761
|
+
include: boolean | undefined,
|
|
762
|
+
display: { output?: unknown | null; errors?: unknown | null } | null | undefined,
|
|
763
|
+
): SuiClientTypes.Display | null | undefined {
|
|
764
|
+
if (!include) return undefined;
|
|
765
|
+
if (!display) return null;
|
|
766
|
+
return {
|
|
767
|
+
output: (display.output as Record<string, string> | null) ?? null,
|
|
768
|
+
errors: (display.errors as Record<string, string> | null) ?? null,
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
|
|
818
772
|
function handleGraphQLErrors(errors: GraphQLResponseErrors | undefined): void {
|
|
819
773
|
if (!errors || errors.length === 0) return;
|
|
820
774
|
|
|
@@ -860,7 +814,7 @@ function mapOwner(owner: Object_Owner_FieldsFragment): SuiClientTypes.ObjectOwne
|
|
|
860
814
|
}
|
|
861
815
|
}
|
|
862
816
|
|
|
863
|
-
function parseTransaction<Include extends SuiClientTypes.TransactionInclude =
|
|
817
|
+
function parseTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(
|
|
864
818
|
transaction: Transaction_FieldsFragment,
|
|
865
819
|
include?: Include,
|
|
866
820
|
): SuiClientTypes.TransactionResult<Include> {
|
|
@@ -961,6 +915,7 @@ function parseTransaction<Include extends SuiClientTypes.TransactionInclude = ob
|
|
|
961
915
|
sender: event.sender?.address!,
|
|
962
916
|
eventType,
|
|
963
917
|
bcs: event.contents?.bcs ? fromBase64(event.contents.bcs) : new Uint8Array(),
|
|
918
|
+
json: (event.contents?.json as Record<string, unknown>) ?? null,
|
|
964
919
|
};
|
|
965
920
|
}) ?? [])
|
|
966
921
|
: undefined) as SuiClientTypes.Transaction<Include>['events'],
|