@sentio/sdk 1.26.3 → 1.26.4
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/aptos-codegen/codegen.js +52 -14
- package/lib/aptos-codegen/codegen.js.map +1 -1
- package/lib/builtin/aptos/0x1.d.ts +89 -84
- package/lib/builtin/aptos/0x1.js +257 -251
- package/lib/builtin/aptos/0x1.js.map +1 -1
- package/lib/builtin/aptos/0x3.d.ts +8 -8
- package/lib/builtin/aptos/0x3.js +35 -35
- package/lib/builtin/aptos/0x3.js.map +1 -1
- package/lib/core/exporter.d.ts +4 -9
- package/lib/core/exporter.js +8 -8
- package/lib/core/exporter.js.map +1 -1
- package/lib/gen/processor/protos/processor.d.ts +2 -9
- package/lib/gen/processor/protos/processor.js +15 -54
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/service.js +2 -3
- package/lib/service.js.map +1 -1
- package/lib/tests/erc20.js +1 -5
- package/lib/tests/erc20.js.map +1 -1
- package/lib/tests/types/aptos/souffle.d.ts +2 -2
- package/lib/tests/types/aptos/souffle.js +12 -12
- package/lib/tests/types/aptos/souffle.js.map +1 -1
- package/package.json +1 -1
- package/src/aptos-codegen/codegen.ts +63 -16
- package/src/builtin/aptos/0x1.ts +301 -283
- package/src/builtin/aptos/0x3.ts +47 -47
- package/src/core/exporter.ts +9 -14
- package/src/gen/processor/protos/processor.ts +15 -59
- package/src/service.ts +2 -3
- package/src/tests/erc20.ts +1 -5
- package/src/tests/types/aptos/souffle.ts +12 -12
@@ -2,8 +2,8 @@ import fs from 'fs'
|
|
2
2
|
import path from 'path'
|
3
3
|
import prettier from 'prettier'
|
4
4
|
import { MoveFunction, MoveModule, MoveModuleBytecode, MoveStruct } from 'aptos-sdk/src/generated'
|
5
|
-
import { AccountModulesImportInfo, AccountRegister, generateType } from './typegen'
|
6
|
-
import { isFrameworkAccount } from '../aptos/utils'
|
5
|
+
import { AccountModulesImportInfo, AccountRegister, generateType, parseMoveType } from './typegen'
|
6
|
+
import { isFrameworkAccount, moduleQname, SPLITTER } from '../aptos/utils'
|
7
7
|
import chalk from 'chalk'
|
8
8
|
import { AptosNetwork, getChainName, getRpcClient } from '../aptos/network'
|
9
9
|
|
@@ -176,12 +176,12 @@ export class AccountCodegen {
|
|
176
176
|
|
177
177
|
${this.modules.map((m) => generateModule(m, this.config.network)).join('\n')}
|
178
178
|
|
179
|
-
function loadAllTypes(
|
180
|
-
${dependedAccounts.map((m) => `${m}.loadTypes(
|
179
|
+
function loadAllTypes(_r: aptos.TypeRegistry) {
|
180
|
+
${dependedAccounts.map((m) => `${m}.loadTypes(_r)`).join('\n')}
|
181
181
|
|
182
182
|
${this.modules
|
183
183
|
.map((m) => {
|
184
|
-
return `
|
184
|
+
return `_r.load(${m.abi?.name}.ABI)`
|
185
185
|
})
|
186
186
|
.join('\n')}
|
187
187
|
}
|
@@ -211,8 +211,13 @@ function generateModule(moduleByteCode: MoveModuleBytecode, network: AptosNetwor
|
|
211
211
|
const module = moduleByteCode.abi
|
212
212
|
|
213
213
|
const functions = module.exposed_functions.map((f) => generateOnEntryFunctions(module, f)).filter((s) => s !== '')
|
214
|
-
|
215
|
-
const
|
214
|
+
|
215
|
+
const eventStructs = getEventStructs(module)
|
216
|
+
const eventTypes = new Set(eventStructs.keys())
|
217
|
+
const events = Array.from(eventStructs.values())
|
218
|
+
.map((e) => generateOnEvents(module, e))
|
219
|
+
.filter((s) => s !== '')
|
220
|
+
const structs = module.structs.map((s) => generateStructs(module, s, eventTypes))
|
216
221
|
const callArgs = module.exposed_functions.map((f) => generateCallArgsStructs(module, f))
|
217
222
|
|
218
223
|
let processor = ''
|
@@ -250,15 +255,15 @@ function generateModule(moduleByteCode: MoveModuleBytecode, network: AptosNetwor
|
|
250
255
|
|
251
256
|
${callArgs.join('\n')}
|
252
257
|
|
253
|
-
export function loadTypes(
|
254
|
-
loadAllTypes(
|
258
|
+
export function loadTypes(_r: aptos.TypeRegistry) {
|
259
|
+
loadAllTypes(_r)
|
255
260
|
}
|
256
261
|
export const ABI: MoveModule = JSON.parse('${JSON.stringify(module)}')
|
257
262
|
}
|
258
263
|
`
|
259
264
|
}
|
260
265
|
|
261
|
-
function generateStructs(module: MoveModule, struct: MoveStruct) {
|
266
|
+
function generateStructs(module: MoveModule, struct: MoveStruct, events: Set<string>) {
|
262
267
|
const genericString = generateStructTypeParameters(struct)
|
263
268
|
const genericStringAny = generateStructTypeParameters(struct, true)
|
264
269
|
|
@@ -267,7 +272,7 @@ function generateStructs(module: MoveModule, struct: MoveStruct) {
|
|
267
272
|
})
|
268
273
|
|
269
274
|
let eventPayload = ''
|
270
|
-
if (
|
275
|
+
if (events.has(moduleQname(module) + SPLITTER + struct.name)) {
|
271
276
|
eventPayload = `
|
272
277
|
export interface ${struct.name}Instance extends
|
273
278
|
aptos.TypedEventInstance<${struct.name}${genericStringAny}> {
|
@@ -357,15 +362,57 @@ function generateOnEntryFunctions(module: MoveModule, func: MoveFunction) {
|
|
357
362
|
return source
|
358
363
|
}
|
359
364
|
|
360
|
-
function
|
361
|
-
|
365
|
+
function getEventStructs(module: MoveModule) {
|
366
|
+
const qname = moduleQname(module)
|
367
|
+
const structMap = new Map<string, MoveStruct>()
|
368
|
+
const eventMap = new Map<string, MoveStruct>()
|
369
|
+
|
370
|
+
for (const struct of module.structs) {
|
371
|
+
structMap.set(qname + SPLITTER + struct.name, struct)
|
372
|
+
}
|
373
|
+
|
374
|
+
for (const struct of module.structs) {
|
375
|
+
for (const field of struct.fields) {
|
376
|
+
const t = parseMoveType(field.type)
|
377
|
+
if (t.qname === '0x1::event::EventHandle') {
|
378
|
+
const event = t.typeArgs[0].qname
|
379
|
+
const eventStruct = structMap.get(event)
|
380
|
+
if (eventStruct) {
|
381
|
+
eventMap.set(event, eventStruct)
|
382
|
+
}
|
383
|
+
}
|
384
|
+
}
|
385
|
+
}
|
386
|
+
|
387
|
+
return eventMap
|
388
|
+
}
|
389
|
+
|
390
|
+
function isEvent(struct: MoveStruct, module: MoveModule) {
|
391
|
+
const hasAbility = struct.abilities.includes('drop') && struct.abilities.includes('store')
|
392
|
+
|
393
|
+
if (!hasAbility) {
|
394
|
+
return false
|
395
|
+
}
|
396
|
+
if (struct.name.endsWith('Event')) {
|
397
|
+
return true
|
398
|
+
}
|
399
|
+
|
400
|
+
// for (const struct of module.structs) {
|
401
|
+
// for (const field of struct.fields) {
|
402
|
+
// if (field.type.startsWith('0x1::event::EventHandle')
|
403
|
+
// }
|
404
|
+
// }
|
405
|
+
|
406
|
+
return false
|
407
|
+
|
408
|
+
//&&
|
362
409
|
}
|
363
410
|
|
364
411
|
function generateOnEvents(module: MoveModule, struct: MoveStruct): string {
|
365
412
|
// for struct that has drop + store
|
366
|
-
if (!isEvent(struct)) {
|
367
|
-
|
368
|
-
}
|
413
|
+
// if (!isEvent(struct, module)) {
|
414
|
+
// return ''
|
415
|
+
// }
|
369
416
|
|
370
417
|
// const genericString = generateStructTypeParameters(struct)
|
371
418
|
|