@typemove/sui 1.14.0-rc.1 → 2.0.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 (85) hide show
  1. package/Readme.md +19 -17
  2. package/package.json +3 -3
  3. package/dist/esm/builtin/0x1.d.ts +0 -1030
  4. package/dist/esm/builtin/0x1.d.ts.map +0 -1
  5. package/dist/esm/builtin/0x1.js +0 -7799
  6. package/dist/esm/builtin/0x1.js.map +0 -1
  7. package/dist/esm/builtin/0x2.d.ts +0 -4766
  8. package/dist/esm/builtin/0x2.d.ts.map +0 -1
  9. package/dist/esm/builtin/0x2.js +0 -23180
  10. package/dist/esm/builtin/0x2.js.map +0 -1
  11. package/dist/esm/builtin/0x3.d.ts +0 -1964
  12. package/dist/esm/builtin/0x3.d.ts.map +0 -1
  13. package/dist/esm/builtin/0x3.js +0 -7606
  14. package/dist/esm/builtin/0x3.js.map +0 -1
  15. package/dist/esm/builtin/index.d.ts +0 -4
  16. package/dist/esm/builtin/index.d.ts.map +0 -1
  17. package/dist/esm/builtin/index.js +0 -7
  18. package/dist/esm/builtin/index.js.map +0 -1
  19. package/dist/esm/codegen/codegen.d.ts +0 -20
  20. package/dist/esm/codegen/codegen.d.ts.map +0 -1
  21. package/dist/esm/codegen/codegen.js +0 -247
  22. package/dist/esm/codegen/codegen.js.map +0 -1
  23. package/dist/esm/codegen/index.d.ts +0 -2
  24. package/dist/esm/codegen/index.d.ts.map +0 -1
  25. package/dist/esm/codegen/index.js +0 -2
  26. package/dist/esm/codegen/index.js.map +0 -1
  27. package/dist/esm/codegen/run.d.ts +0 -3
  28. package/dist/esm/codegen/run.d.ts.map +0 -1
  29. package/dist/esm/codegen/run.js.map +0 -1
  30. package/dist/esm/index.d.ts +0 -5
  31. package/dist/esm/index.d.ts.map +0 -1
  32. package/dist/esm/index.js +0 -5
  33. package/dist/esm/index.js.map +0 -1
  34. package/dist/esm/models.d.ts +0 -21
  35. package/dist/esm/models.d.ts.map +0 -1
  36. package/dist/esm/models.js +0 -2
  37. package/dist/esm/models.js.map +0 -1
  38. package/dist/esm/move-coder.d.ts +0 -28
  39. package/dist/esm/move-coder.d.ts.map +0 -1
  40. package/dist/esm/move-coder.js +0 -311
  41. package/dist/esm/move-coder.js.map +0 -1
  42. package/dist/esm/move-coder.test.d.ts +0 -2
  43. package/dist/esm/move-coder.test.d.ts.map +0 -1
  44. package/dist/esm/move-coder.test.js.map +0 -1
  45. package/dist/esm/sui-chain-adapter.d.ts +0 -28
  46. package/dist/esm/sui-chain-adapter.d.ts.map +0 -1
  47. package/dist/esm/sui-chain-adapter.js +0 -109
  48. package/dist/esm/sui-chain-adapter.js.map +0 -1
  49. package/dist/esm/to-internal.d.ts +0 -6
  50. package/dist/esm/to-internal.d.ts.map +0 -1
  51. package/dist/esm/to-internal.js +0 -170
  52. package/dist/esm/to-internal.js.map +0 -1
  53. package/dist/esm/transaction.d.ts +0 -15
  54. package/dist/esm/transaction.d.ts.map +0 -1
  55. package/dist/esm/transaction.js +0 -83
  56. package/dist/esm/transaction.js.map +0 -1
  57. package/src/abis/0x1.json +0 -9096
  58. package/src/abis/0x2.json +0 -38512
  59. package/src/abis/0x3.json +0 -14755
  60. package/src/builtin/0x1.ts +0 -10657
  61. package/src/builtin/0x2.ts +0 -33567
  62. package/src/builtin/0x3.ts +0 -11437
  63. package/src/builtin/index.ts +0 -6
  64. package/src/codegen/codegen.ts +0 -292
  65. package/src/codegen/index.ts +0 -1
  66. package/src/codegen/run.ts +0 -57
  67. package/src/index.ts +0 -13
  68. package/src/models.ts +0 -32
  69. package/src/move-coder.ts +0 -364
  70. package/src/sui-chain-adapter.ts +0 -142
  71. package/src/tests/abis/testnet/0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5.json +0 -341
  72. package/src/tests/abis/testnet/0x6c4a21e3e7e6b6d51c4604021633e1d97e24e37a696f8c082cd48f37503e602a.json +0 -3375
  73. package/src/tests/abis/testnet/0x7f7a37c826c88bcfe9aecc042453395ddfa9df6f29cb7c97590bf86cf2b0a75e.json +0 -1535
  74. package/src/tests/abis/testnet/0xdee9.json +0 -10176
  75. package/src/tests/abis/testnet/0xebaa2ad3eacc230f309cd933958cc52684df0a41ae7ac214d186b80f830867d2.json +0 -12904
  76. package/src/tests/abis/testnet/enum.json +0 -6859
  77. package/src/tests/types/testnet/0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5.ts +0 -314
  78. package/src/tests/types/testnet/0x6c4a21e3e7e6b6d51c4604021633e1d97e24e37a696f8c082cd48f37503e602a.ts +0 -2819
  79. package/src/tests/types/testnet/0x7f7a37c826c88bcfe9aecc042453395ddfa9df6f29cb7c97590bf86cf2b0a75e.ts +0 -1594
  80. package/src/tests/types/testnet/0xdee9.ts +0 -7049
  81. package/src/tests/types/testnet/0xebaa2ad3eacc230f309cd933958cc52684df0a41ae7ac214d186b80f830867d2.ts +0 -10609
  82. package/src/tests/types/testnet/enum.ts +0 -6297
  83. package/src/tests/types/testnet/index.ts +0 -9
  84. package/src/to-internal.ts +0 -201
  85. package/src/transaction.ts +0 -127
package/src/move-coder.ts DELETED
@@ -1,364 +0,0 @@
1
- import { TypedSimulateResults, TypedEventInstance, TypedFunctionPayload } from './models.js'
2
- import {
3
- AbstractMoveCoder,
4
- ANY_TYPE,
5
- DecodedStruct,
6
- accountTypeString,
7
- parseMoveType,
8
- SPLITTER,
9
- TypeDescriptor,
10
- InternalMoveModule
11
- } from '@typemove/move'
12
- import { SuiGrpcClient } from '@mysten/sui/grpc'
13
- import type { GrpcTypes } from '@mysten/sui/grpc'
14
- import {
15
- SuiChainAdapter,
16
- ModuleWithAddress,
17
- getGrpcClient,
18
- getGrpcFullnodeUrl,
19
- SuiEventInput,
20
- SuiMoveObjectInput
21
- } from './sui-chain-adapter.js'
22
- import { toInternalModule } from './to-internal.js'
23
- import { dynamic_field } from './builtin/0x2.js'
24
- import { BcsType, bcs } from '@mysten/sui/bcs'
25
-
26
- // import { Encoding } from '@mysten/bcs/types', this doesn't get exported correctly
27
- export type Encoding = 'base58' | 'base64' | 'hex'
28
-
29
- import { normalizeSuiObjectId, normalizeSuiAddress } from '@mysten/sui/utils'
30
-
31
- export class MoveCoder extends AbstractMoveCoder<ModuleWithAddress, SuiEventInput | SuiMoveObjectInput> {
32
- constructor(client: SuiGrpcClient) {
33
- super(new SuiChainAdapter(client))
34
- }
35
-
36
- load(entry: ModuleWithAddress, address: string): InternalMoveModule {
37
- address = accountTypeString(address)
38
- const { address: moduleAddress, module } = entry
39
- let m = this.moduleMapping.get(moduleAddress + '::' + module.name)
40
- const mDeclared = this.moduleMapping.get(address + '::' + module.name)
41
- if (m && mDeclared) {
42
- return m
43
- }
44
- this.accounts.add(moduleAddress)
45
- m = toInternalModule(module, moduleAddress)
46
- this.loadInternal(m, address)
47
- return m
48
- }
49
-
50
- protected async decode(data: any, type: TypeDescriptor): Promise<any> {
51
- // UID handled before the switch to avoid the existing fall-through chain
52
- // (case '0x2::url::Url' / '0x2::coin::Coin' bodies fire on non-string
53
- // inputs and corrupt UID output). gRPC's unified Object.json flattens UID
54
- // to a bare address string — re-wrap to `{ id: '0x<32-byte>' }` so
55
- // downstream `.id.id`-style accessors keep working. The BCS-shaped path
56
- // (`{ id: { bytes: Uint8Array(32) } }`) is delegated to super.decode,
57
- // which then hits the inner ID case.
58
- if (type.qname === '0x2::object::UID') {
59
- if (typeof data === 'string') {
60
- return { id: normalizeSuiObjectId(data) } as any
61
- }
62
- return super.decode(data, type)
63
- }
64
- switch (type.qname) {
65
- case '0x1::ascii::Char':
66
- if (data !== undefined && typeof data !== 'string') {
67
- // bcs
68
- const byte = (await super.decode(data, type)).byte as number
69
- return String.fromCharCode(byte)
70
- }
71
- case '0x1::ascii::String':
72
- if (data !== undefined && typeof data !== 'string') {
73
- // bcs verified
74
- const bytes = (await super.decode(data, type)).bytes as number[]
75
- return new TextDecoder().decode(new Uint8Array(bytes))
76
- }
77
- case '0x2::object::ID':
78
- if (data !== undefined && typeof data !== 'string') {
79
- // bcs verified
80
- const bytes = (await super.decode(data, type)).bytes as string
81
- return normalizeSuiObjectId(bytes)
82
- }
83
- case '0x2::url::Url':
84
- if (data !== undefined && typeof data !== 'string') {
85
- // bcs
86
- return (await super.decode(data, type)).url
87
- }
88
- case '0x2::coin::Coin':
89
- if (data !== undefined && typeof data !== 'string') {
90
- // bcs
91
- const bytes = (await super.decode(data, type)).id.id.bytes as number[]
92
- return new TextDecoder().decode(new Uint8Array(bytes))
93
- }
94
- return data
95
- case '0x2::balance::Balance':
96
- if (data.value) {
97
- // bcs verfied
98
- const balance = await super.decode(data, type)
99
- return balance.value
100
- }
101
- return BigInt(data)
102
- case '0x1::option::Option':
103
- if (data === null) {
104
- return data
105
- }
106
- if (data.vec) {
107
- // bcs verifed
108
- let vec = await super.decode(data, type)
109
- vec = vec.vec
110
- if (vec.length === 0) {
111
- return null
112
- }
113
- return vec[0]
114
- }
115
- return this.decode(data, type.typeArgs[0])
116
- case 'Address':
117
- const str = data as string
118
- return normalizeSuiAddress(str)
119
- case '0x1::string::String':
120
- if (typeof data !== 'string') {
121
- // bcs
122
- return new TextDecoder().decode(new Uint8Array(data.bytes))
123
- }
124
- default:
125
- return super.decode(data, type)
126
- }
127
- }
128
-
129
- decodeEvent<T>(event: SuiEventInput): Promise<TypedEventInstance<T> | undefined> {
130
- return this.decodedStruct(event)
131
- }
132
- filterAndDecodeEvents<T>(
133
- type: TypeDescriptor<T> | string,
134
- resources: SuiEventInput[]
135
- ): Promise<TypedEventInstance<T>[]> {
136
- if (typeof type === 'string') {
137
- type = parseMoveType(type)
138
- }
139
- return this.filterAndDecodeStruct(type, resources)
140
- }
141
-
142
- async getDynamicFields<T1, T2>(
143
- objects: SuiMoveObjectInput[],
144
- keyType: TypeDescriptor<T1> = ANY_TYPE,
145
- valueType: TypeDescriptor<T2> = ANY_TYPE
146
- ): Promise<dynamic_field.Field<T1, T2>[]> {
147
- const type = new TypeDescriptor<dynamic_field.Field<T1, T2>>('0x2::dynamic_field::Field')
148
- type.typeArgs = [keyType, valueType]
149
- const res = await this.filterAndDecodeObjects(type, objects)
150
- return res.map((o) => o.data_decoded)
151
- }
152
-
153
- filterAndDecodeObjects<T>(
154
- type: TypeDescriptor<T>,
155
- objects: SuiMoveObjectInput[]
156
- ): Promise<DecodedStruct<SuiMoveObjectInput, T>[]> {
157
- return this.filterAndDecodeStruct(type, objects)
158
- }
159
-
160
- // Decodes a parsed Move call payload against the loaded module ABI.
161
- // Inputs are gRPC `Input[]`: kind=PURE carries a Uint8Array of BCS bytes
162
- // that we decode using the corresponding parameter's Move type;
163
- // object inputs (IMMUTABLE_OR_OWNED / SHARED / receiving) are surfaced as
164
- // undefined since their on-chain values aren't part of the payload.
165
- async decodeFunctionPayload(payload: GrpcTypes.MoveCall, inputs: GrpcTypes.Input[]): Promise<any> {
166
- const functionType = [payload.package, payload.module, payload.function].join(SPLITTER)
167
- const func = await this.getMoveFunction(functionType)
168
- const params = this.adapter.getMeaningfulFunctionParams(func.params)
169
- const args: any[] = []
170
- for (const value of payload.arguments ?? []) {
171
- const av = value as any
172
- const idx: number | undefined = av?.input
173
- if (idx == null || idx < 0 || idx >= inputs.length) {
174
- args.push(undefined)
175
- continue
176
- }
177
- const arg = inputs[idx]
178
- if (arg?.pure) {
179
- const paramType: TypeDescriptor | undefined = params[args.length]
180
- try {
181
- const bytes = arg.pure instanceof Uint8Array ? arg.pure : new Uint8Array(arg.pure)
182
- const decoded: any = paramType ? await this.decodeBCS(paramType, bytes) : bytes
183
- args.push(decoded)
184
- } catch {
185
- args.push(undefined)
186
- }
187
- } else {
188
- // Object inputs (and unknown kinds) — value isn't carried in the payload.
189
- args.push(undefined)
190
- }
191
- }
192
-
193
- const argumentsTyped = await this.decodeArray(args, params, false)
194
- return {
195
- ...payload,
196
- arguments_decoded: argumentsTyped
197
- } as TypedFunctionPayload<any>
198
- }
199
-
200
- private bcsRegistered = new Set<string>()
201
- private bcsRegistry = new Map<string, BcsType<any>>()
202
-
203
- private async getBCSTypeWithArgs(type: TypeDescriptor, args: BcsType<any>[] = []): Promise<BcsType<any>> {
204
- const qname = type.qname
205
- const sig = type.getNormalizedSignature()
206
- const cached = this.bcsRegistry.get(sig)
207
- if (cached) {
208
- return cached
209
- }
210
- const lowerQname = qname.toLowerCase()
211
- switch (lowerQname) {
212
- case 'u8':
213
- case 'u16':
214
- case 'u32':
215
- case 'u64':
216
- case 'u128':
217
- case 'u256':
218
- case 'bool':
219
- return bcs[lowerQname]()
220
- case 'address':
221
- return bcs.Address
222
- case 'vector':
223
- return bcs.vector(args[0])
224
- default:
225
- if (!qname.includes('::')) {
226
- throw `Unimplemented builtin type ${qname}`
227
- }
228
- }
229
- let moveStruct
230
- try {
231
- moveStruct = await this.getMoveStruct(qname)
232
- } catch (e) {
233
- console.error('Invalid move address', qname)
234
- throw e
235
- }
236
- const structDef: Record<string, any> = {}
237
- for (const field of moveStruct.fields) {
238
- if (field.type.qname.startsWith('T') && args.length) {
239
- const index = +field.type.qname.slice(1)
240
- structDef[field.name] = args[index]
241
- } else if (field.type.typeArgs.length && args.length) {
242
- structDef[field.name] = await this.getBCSTypeWithArgs(field.type, args)
243
- } else {
244
- structDef[field.name] = await this.getBCSType(field.type)
245
- }
246
- }
247
- return bcs.struct(qname, structDef)
248
- }
249
-
250
- async getBCSType(type: TypeDescriptor): Promise<BcsType<any>> {
251
- const args = await Promise.all(type.typeArgs.map((x) => this.getBCSType(x)))
252
- const bcsType = await this.getBCSTypeWithArgs(type, args)
253
- this.bcsRegistry.set(type.getNormalizedSignature(), bcsType)
254
- return bcsType
255
- }
256
-
257
- async registerBCSTypes(type: TypeDescriptor): Promise<void> {
258
- const sig = type.getNormalizedSignature()
259
- if (this.bcsRegistered.has(sig)) {
260
- return
261
- }
262
- this.bcsRegistered.add(sig)
263
-
264
- const bcsType = await this.getBCSType(type)
265
- this.bcsRegistry.set(type.getNormalizedSignature(), bcsType)
266
- }
267
-
268
- async decodeBCS(type: TypeDescriptor, data: Uint8Array | string, encoding?: Encoding): Promise<any> {
269
- await this.registerBCSTypes(type)
270
- if (typeof data == 'string') {
271
- const buf = Buffer.from(data, encoding as any)
272
- data = new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength)
273
- }
274
- const bcsType = this.bcsRegistry.get(type.getNormalizedSignature())
275
- return bcsType?.parse(data)
276
- }
277
-
278
- // Replaces decodeDevInspectResult. gRPC simulateTransaction returns
279
- // `commandResults: CommandResult[]` where each CommandResult.returnValues is
280
- // `CommandOutput[]` of raw `{ bcs: Uint8Array }` — there is no per-return
281
- // type string the way devInspect carried one. The caller must therefore pass
282
- // the Move return-type signatures explicitly (codegen emits them next to
283
- // each generated view helper).
284
- async decodeSimulateResult<T extends any[]>(
285
- simulateRes: any,
286
- returnTypeSignatures: string[],
287
- typeArguments?: (string | TypeDescriptor)[]
288
- ): Promise<TypedSimulateResults<T>> {
289
- // Generic view helpers embed return signatures like "T0" / "vector<T1>"
290
- // at codegen time, but the caller supplies concrete type arguments only
291
- // at runtime. Substitute them in before BCS decoding — otherwise the BCS
292
- // type registry sees the bare type-parameter qname and rejects it as an
293
- // unimplemented builtin.
294
- const ctx = new Map<string, TypeDescriptor>()
295
- if (typeArguments && typeArguments.length > 0) {
296
- typeArguments.forEach((t, i) => {
297
- ctx.set('T' + i, typeof t === 'string' ? parseMoveType(t) : t)
298
- })
299
- }
300
-
301
- const returnValues: any[] = []
302
- const commandResults = simulateRes?.commandResults
303
- if (Array.isArray(commandResults)) {
304
- let typeIdx = 0
305
- for (const r of commandResults) {
306
- const rvs = r?.returnValues
307
- if (Array.isArray(rvs) && rvs.length > 0) {
308
- for (const rv of rvs) {
309
- const sig = returnTypeSignatures[typeIdx++]
310
- if (!sig) {
311
- returnValues.push(null)
312
- continue
313
- }
314
- let type = parseMoveType(sig)
315
- if (ctx.size > 0) {
316
- type = type.applyTypeArgs(ctx)
317
- }
318
- const bcsBytes = rv?.bcs instanceof Uint8Array ? rv.bcs : new Uint8Array(rv?.bcs ?? [])
319
- const bcsDecoded = await this.decodeBCS(type, bcsBytes)
320
- const decoded = await this.decodeType(bcsDecoded, type)
321
- returnValues.push(decoded)
322
- }
323
- } else {
324
- returnValues.push(null)
325
- }
326
- }
327
- }
328
- return { ...simulateRes, results_decoded: returnValues as any }
329
- }
330
- }
331
-
332
- const DEFAULT_ENDPOINT = getGrpcFullnodeUrl('mainnet')
333
- const CODER_MAP = new Map<string, MoveCoder>()
334
-
335
- export function defaultMoveCoder(endpoint: string = DEFAULT_ENDPOINT): MoveCoder {
336
- let coder = CODER_MAP.get(endpoint)
337
- if (!coder) {
338
- coder = new MoveCoder(getGrpcClient(endpoint))
339
- CODER_MAP.set(endpoint, coder)
340
- }
341
- return coder
342
- }
343
-
344
- const PROVIDER_CODER_MAP = new Map<SuiGrpcClient, MoveCoder>()
345
-
346
- let DEFAULT_CHAIN_ID: string | undefined
347
-
348
- export async function getMoveCoder(client: SuiGrpcClient): Promise<MoveCoder> {
349
- let coder = PROVIDER_CODER_MAP.get(client)
350
- if (!coder) {
351
- coder = new MoveCoder(client)
352
- const { chainIdentifier } = await client.core.getChainIdentifier()
353
- const defaultCoder = defaultMoveCoder()
354
- if (!DEFAULT_CHAIN_ID) {
355
- DEFAULT_CHAIN_ID = await defaultCoder.adapter.getChainId()
356
- }
357
- if (chainIdentifier === DEFAULT_CHAIN_ID) {
358
- coder = defaultCoder
359
- }
360
-
361
- PROVIDER_CODER_MAP.set(client, coder)
362
- }
363
- return coder
364
- }
@@ -1,142 +0,0 @@
1
- import { toInternalModule } from './to-internal.js'
2
- import {
3
- InternalMoveModule,
4
- InternalMoveStruct,
5
- ChainAdapter,
6
- moduleQname,
7
- SPLITTER,
8
- TypeDescriptor
9
- } from '@typemove/move'
10
-
11
- import type { GrpcTypes } from '@mysten/sui/grpc'
12
- import { SuiGrpcClient } from '@mysten/sui/grpc'
13
- import type { SuiClientTypes } from '@mysten/sui/client'
14
-
15
- // Decoder-input types now use @mysten/sui/client's unified SuiClientTypes —
16
- // the same shapes returned by SuiGrpcClient (and that the GraphQL/JSON-RPC
17
- // clients implement). Per the SDK's own warnings, the `.json` field's exact
18
- // field names may vary between transports for some payloads; downstream code
19
- // reading `getData` should treat it as opaque object data.
20
- export type SuiEventInput = SuiClientTypes.Event
21
- export type SuiMoveObjectInput = SuiClientTypes.Object<{ json: true }>
22
-
23
- // Adapter ModuleType is the proto Module plus the package address (which the
24
- // proto doesn't carry per-entry — only the wrapping Package has storageId).
25
- export interface ModuleWithAddress {
26
- address: string
27
- module: GrpcTypes.Module
28
- }
29
-
30
- export class SuiChainAdapter extends ChainAdapter<ModuleWithAddress, SuiEventInput | SuiMoveObjectInput> {
31
- client: SuiGrpcClient
32
-
33
- constructor(client: SuiGrpcClient) {
34
- super()
35
- this.client = client
36
- }
37
-
38
- async getChainId(): Promise<string> {
39
- const { chainIdentifier } = await this.client.core.getChainIdentifier()
40
- return chainIdentifier ?? ''
41
- }
42
-
43
- async fetchModule(account: string, module: string): Promise<ModuleWithAddress> {
44
- // gRPC has no single-module-fetch RPC; pull the whole package and filter.
45
- const modules = await this.fetchModules(account)
46
- const m = modules.find((x) => x.module.name === module)
47
- if (!m) {
48
- throw Error(`Module ${module} not found in package ${account}`)
49
- }
50
- return m
51
- }
52
-
53
- async fetchModules(account: string): Promise<ModuleWithAddress[]> {
54
- const { response } = await this.client.movePackageService.getPackage({ packageId: account })
55
- const pkg = response.package
56
- if (!pkg) {
57
- throw Error(`No package returned for ${account}`)
58
- }
59
- // gRPC returns the canonical long-form storage id (0x0000...0002); the rest
60
- // of typemove keys system packages by their short form (0x2). Preserve the
61
- // caller-supplied address so framework lookups and short-form import paths
62
- // (`@typemove/sui/builtin/0x2`) keep working.
63
- return (pkg.modules ?? []).map((module) => ({ address: account, module }))
64
- }
65
-
66
- getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {
67
- return params
68
- }
69
-
70
- toInternalModules(modules: ModuleWithAddress[]): InternalMoveModule[] {
71
- return modules.map(({ address, module }) => toInternalModule(module, address))
72
- }
73
-
74
- getAllEventStructs(modules: InternalMoveModule[]): Map<string, InternalMoveStruct> {
75
- const eventMap = new Map<string, InternalMoveStruct>()
76
- for (const module of modules) {
77
- const qname = moduleQname(module)
78
- for (const struct of module.structs) {
79
- const abilities = new Set(struct.abilities)
80
- if (abilities.has('Drop') && abilities.has('Copy')) {
81
- eventMap.set(qname + SPLITTER + struct.name, struct)
82
- }
83
- }
84
- }
85
- return eventMap
86
- }
87
-
88
- getType(base: SuiEventInput | SuiMoveObjectInput): string {
89
- // Unified SuiClientTypes: Event has `eventType`, Object has `type`.
90
- const v = base as any
91
- return v.eventType ?? v.type ?? ''
92
- }
93
-
94
- getData(val: SuiEventInput | SuiMoveObjectInput) {
95
- if (val === undefined) {
96
- throw Error('val is undefined')
97
- }
98
- // Pass through primitives (e.g. a UID flattened to a bare string) — the
99
- // decoder's per-type case handlers know how to interpret them.
100
- if (val === null || typeof val !== 'object') {
101
- return val as any
102
- }
103
- const v = val as any
104
- // Unified SuiClientTypes shapes: Event.json / Object<{json:true}>.json
105
- // carries the decoded Move struct content. Anything else (a nested
106
- // already-flat struct value passed in during recursion) is its own data.
107
- if (v.json != null) {
108
- return v.json as any
109
- }
110
- return val as any
111
- }
112
- }
113
-
114
- export function inferNetworkFromUrl(url: string): string {
115
- if (url.includes('mainnet')) return 'mainnet'
116
- if (url.includes('testnet')) return 'testnet'
117
- if (url.includes('devnet')) return 'devnet'
118
- if (url.includes('localnet') || url.includes('127.0.0.1') || url.includes('localhost')) return 'localnet'
119
- return 'custom'
120
- }
121
-
122
- // gRPC counterpart of @mysten/sui/jsonRpc's `getJsonRpcFullnodeUrl`. The SDK
123
- // doesn't ship one under /grpc — Sui's gRPC-Web endpoint is exposed on the
124
- // same host as JSON-RPC over standard HTTPS, so we mirror the JSON-RPC list
125
- // (sans the explicit :443 since the transport speaks HTTPS by default).
126
- export function getGrpcFullnodeUrl(network: 'mainnet' | 'testnet' | 'devnet' | 'localnet'): string {
127
- switch (network) {
128
- case 'mainnet':
129
- return 'https://fullnode.mainnet.sui.io'
130
- case 'testnet':
131
- return 'https://fullnode.testnet.sui.io'
132
- case 'devnet':
133
- return 'https://fullnode.devnet.sui.io'
134
- case 'localnet':
135
- return 'http://127.0.0.1:9000'
136
- }
137
- }
138
-
139
- export function getGrpcClient(endpoint: string): SuiGrpcClient {
140
- const network = inferNetworkFromUrl(endpoint) as any
141
- return new SuiGrpcClient({ network, baseUrl: endpoint })
142
- }