@sentio/sdk 1.21.2 → 1.21.4

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.
@@ -203,6 +203,7 @@ function generateModule(moduleByteCode: MoveModuleBytecode, dependedModules: str
203
203
 
204
204
  function generateStructs(module: MoveModule, struct: MoveStruct) {
205
205
  const genericString = generateStructTypeParameters(struct)
206
+ const genericStringAny = generateStructTypeParameters(struct, true)
206
207
 
207
208
  const fields = struct.fields.map((field) => {
208
209
  return `${field.name}: ${generateType(field.type)}`
@@ -211,9 +212,10 @@ function generateStructs(module: MoveModule, struct: MoveStruct) {
211
212
  let eventPayload = ''
212
213
  if (isEvent(struct)) {
213
214
  eventPayload = `
214
- export interface ${struct.name}Instance${genericString} extends
215
- aptos.TypedEventInstance<${struct.name}${genericString}> {
216
- data_typed: ${struct.name}${genericString}
215
+ export interface ${struct.name}Instance extends
216
+ aptos.TypedEventInstance<${struct.name}${genericStringAny}> {
217
+ data_typed: ${struct.name}${genericStringAny}
218
+ type_arguments: [${struct.generic_type_params.map((_) => 'string').join(', ')}]
217
219
  }
218
220
  `
219
221
  }
@@ -227,26 +229,26 @@ function generateStructs(module: MoveModule, struct: MoveStruct) {
227
229
  `
228
230
  }
229
231
 
230
- function generateFunctionTypeParameters(func: MoveFunction) {
231
- let genericString = ''
232
- if (func.generic_type_params && func.generic_type_params.length > 0) {
233
- const params = func.generic_type_params
234
- .map((v, idx) => {
235
- return 'T' + idx
236
- })
237
- .join(',')
238
- genericString = `<${params}>`
239
- }
240
- return genericString
241
- }
242
-
243
- function generateStructTypeParameters(struct: MoveStruct) {
232
+ // function generateFunctionTypeParameters(func: MoveFunction) {
233
+ // let genericString = ''
234
+ // if (func.generic_type_params && func.generic_type_params.length > 0) {
235
+ // const params = func.generic_type_params
236
+ // .map((v, idx) => {
237
+ // return 'T' + idx
238
+ // })
239
+ // .join(',')
240
+ // genericString = `<${params}>`
241
+ // }
242
+ // return genericString
243
+ // }
244
+
245
+ function generateStructTypeParameters(struct: MoveStruct, useAny = false) {
244
246
  let genericString = ''
245
247
 
246
248
  if (struct.generic_type_params && struct.generic_type_params.length > 0) {
247
249
  const params = struct.generic_type_params
248
250
  .map((v, idx) => {
249
- return 'T' + idx
251
+ return useAny ? 'any' : 'T' + idx
250
252
  })
251
253
  .join(',')
252
254
  genericString = `<${params}>`
@@ -267,11 +269,12 @@ function generateCallArgsStructs(module: MoveModule, func: MoveFunction) {
267
269
 
268
270
  const camelFuncName = capitalizeFirstChar(camelize(func.name))
269
271
 
270
- const genericString = generateFunctionTypeParameters(func)
272
+ // const genericString = generateFunctionTypeParameters(func)
271
273
  return `
272
- export interface ${camelFuncName}Payload${genericString}
274
+ export interface ${camelFuncName}Payload
273
275
  extends aptos.TypedEntryFunctionPayload<[${fields.join(',')}]> {
274
- arguments_typed: [${fields.join(',')}]
276
+ arguments_typed: [${fields.join(',')}],
277
+ type_arguments: [${func.generic_type_params.map((_) => 'string').join(', ')}]
275
278
  }
276
279
  `
277
280
  }
@@ -281,11 +284,11 @@ function generateOnEntryFunctions(module: MoveModule, func: MoveFunction) {
281
284
  return ''
282
285
  }
283
286
 
284
- const genericString = generateFunctionTypeParameters(func)
287
+ // const genericString = generateFunctionTypeParameters(func)
285
288
 
286
289
  const camelFuncName = capitalizeFirstChar(camelize(func.name))
287
290
  const source = `
288
- onEntry${camelFuncName}${genericString}(func: (call: ${module.name}.${camelFuncName}Payload${genericString}, ctx: aptos.AptosContext) => void, filter?: aptos.CallFilter): ${module.name} {
291
+ onEntry${camelFuncName}(func: (call: ${module.name}.${camelFuncName}Payload, ctx: aptos.AptosContext) => void, filter?: aptos.CallFilter): ${module.name} {
289
292
  this.onEntryFunctionCall(func, {
290
293
  ...filter,
291
294
  function: '${module.name}::${func.name}'
@@ -306,10 +309,10 @@ function generateOnEvents(module: MoveModule, struct: MoveStruct): string {
306
309
  return ''
307
310
  }
308
311
 
309
- const genericString = generateStructTypeParameters(struct)
312
+ // const genericString = generateStructTypeParameters(struct)
310
313
 
311
314
  const source = `
312
- onEvent${struct.name}${genericString}(func: (event: ${module.name}.${struct.name}Instance${genericString}, ctx: aptos.AptosContext) => void): ${module.name} {
315
+ onEvent${struct.name}(func: (event: ${module.name}.${struct.name}Instance, ctx: aptos.AptosContext) => void): ${module.name} {
313
316
  this.onEvent(func, {
314
317
  type: '${module.name}::${struct.name}'
315
318
  })
@@ -18,9 +18,9 @@ describe('type gen', () => {
18
18
  })
19
19
 
20
20
  test('test depended types', async () => {
21
- const res = parseMoveType(
21
+ const typeString =
22
22
  '0x1::table_with_length::TableWithLength<T0, 0xd5f9f2b1c24faee8f07b790e570c75dfa1b7d8c1e9a60162fbd92ade03ea29e4::iterable_table::IterableValue<T0, T1>>'
23
- )
23
+ const res = parseMoveType(typeString)
24
24
 
25
25
  const deps = res.dependedTypes()
26
26
  assert(deps.length === 2)
@@ -28,6 +28,9 @@ describe('type gen', () => {
28
28
  deps[0] === '0xd5f9f2b1c24faee8f07b790e570c75dfa1b7d8c1e9a60162fbd92ade03ea29e4::iterable_table::IterableValue'
29
29
  )
30
30
  assert(deps[1] === '0x1::table_with_length::TableWithLength')
31
+
32
+ const computedTypeString = res.getSignature()
33
+ assert(computedTypeString === typeString)
31
34
  })
32
35
  // test('type type gen', async () => {
33
36
  //
@@ -60,7 +60,7 @@ function generateSimpleType(type: string): string {
60
60
  return parts.slice(1).join('.')
61
61
  }
62
62
 
63
- export function parseMoveType(type: string) {
63
+ export function parseMoveType(type: string): TypeDescriptor {
64
64
  // type = type.replace('&', '')
65
65
 
66
66
  type = type.replaceAll('&mut ', '&')