@sentio/sdk 2.5.0-rc.3 → 2.5.1-rc.1

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 (51) hide show
  1. package/lib/aptos/codegen/codegen.js +3 -3
  2. package/lib/aptos/codegen/codegen.js.map +1 -1
  3. package/lib/aptos/move-coder.js +2 -2
  4. package/lib/aptos/move-coder.js.map +1 -1
  5. package/lib/aptos/move-types.d.ts +5 -5
  6. package/lib/aptos/move-types.js +15 -15
  7. package/lib/aptos/move-types.js.map +1 -1
  8. package/lib/move/abstract-codegen.d.ts +12 -12
  9. package/lib/move/abstract-codegen.js +27 -27
  10. package/lib/move/abstract-codegen.js.map +1 -1
  11. package/lib/move/abstract-move-coder.d.ts +4 -4
  12. package/lib/move/abstract-move-coder.js +3 -3
  13. package/lib/move/abstract-move-coder.js.map +1 -1
  14. package/lib/move/account.d.ts +4 -7
  15. package/lib/move/account.js +2 -14
  16. package/lib/move/account.js.map +1 -1
  17. package/lib/move/internal-models.d.ts +34 -0
  18. package/lib/move/internal-models.js +7 -0
  19. package/lib/move/internal-models.js.map +1 -0
  20. package/lib/move/ts-type.js +1 -3
  21. package/lib/move/ts-type.js.map +1 -1
  22. package/lib/move/types.d.ts +1 -0
  23. package/lib/move/types.js +13 -25
  24. package/lib/move/types.js.map +1 -1
  25. package/lib/sui/codegen/codegen.js +5 -5
  26. package/lib/sui/codegen/codegen.js.map +1 -1
  27. package/lib/sui/move-coder.js +2 -2
  28. package/lib/sui/move-coder.js.map +1 -1
  29. package/lib/sui/move-types.d.ts +7 -7
  30. package/lib/sui/move-types.js +26 -25
  31. package/lib/sui/move-types.js.map +1 -1
  32. package/lib/sui/utils.d.ts +2 -2
  33. package/lib/sui/utils.js.map +1 -1
  34. package/package.json +9 -9
  35. package/src/aptos/codegen/codegen.ts +7 -7
  36. package/src/aptos/move-coder.ts +2 -3
  37. package/src/aptos/move-types.ts +20 -20
  38. package/src/move/abstract-codegen.ts +42 -40
  39. package/src/move/abstract-move-coder.ts +9 -9
  40. package/src/move/account.ts +6 -21
  41. package/src/move/internal-models.ts +40 -0
  42. package/src/move/ts-type.ts +1 -3
  43. package/src/move/types.ts +13 -33
  44. package/src/sui/codegen/codegen.ts +8 -8
  45. package/src/sui/move-coder.ts +2 -2
  46. package/src/sui/move-types.ts +32 -31
  47. package/src/sui/utils.ts +2 -2
  48. package/lib/move/neutral-models.d.ts +0 -34
  49. package/lib/move/neutral-models.js +0 -7
  50. package/lib/move/neutral-models.js.map +0 -1
  51. package/src/move/neutral-models.ts +0 -45
@@ -1,5 +1,5 @@
1
1
  import * as fs from 'fs';
2
- import { toNeutralModule } from '../move-types.js';
2
+ import { toInternalModule } from '../move-types.js';
3
3
  import { moduleQname, SPLITTER } from '../../move/index.js';
4
4
  import chalk from 'chalk';
5
5
  import { AptosNetwork } from '../network.js';
@@ -33,8 +33,8 @@ class AptosCodegen extends AbstractCodegen {
33
33
  const client = getRpcClient(network);
34
34
  return await client.getAccountModules(account);
35
35
  }
36
- toNeutral(modules) {
37
- return modules.flatMap((m) => (m.abi ? [toNeutralModule(m)] : []));
36
+ toInternalModules(modules) {
37
+ return modules.flatMap((m) => (m.abi ? [toInternalModule(m)] : []));
38
38
  }
39
39
  getMeaningfulFunctionParams(params) {
40
40
  return getMeaningfulFunctionParams(params);
@@ -1 +1 @@
1
- {"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../../src/aptos/codegen/codegen.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,EAAsB,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACtE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAkB,MAAM,qBAAqB,CAAA;AAC3E,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACvC,OAAO,EA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,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IACpE,CAAC;IAED,2BAA2B,CAAC,MAAwB;QAClD,OAAO,2BAA2B,CAAC,MAAM,CAAC,CAAA;IAC5C,CAAC;IAED,eAAe,CAAC,MAAyB;QACvC,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,CAAA;QACjC,MAAM,SAAS,GAAG,IAAI,GAAG,EAA6B,CAAA;QACtD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA6B,CAAA;QAErD,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE;YACnC,SAAS,CAAC,GAAG,CAAC,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;SACtD;QAED,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE;YACnC,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE;gBACjC,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,CAAA;gBACpB,IAAI,CAAC,CAAC,KAAK,KAAK,yBAAyB,EAAE;oBACzC,MAAM,KAAK,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;oBACjC,MAAM,WAAW,GAAG,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;oBACxC,IAAI,WAAW,EAAE;wBACf,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,CAAC,CAAA;qBACjC;iBACF;aACF;SACF;QAED,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF","sourcesContent":["import * as fs from 'fs'\nimport { MoveModuleBytecode, toNeutralModule } from '../move-types.js'\nimport { moduleQname, SPLITTER, TypeDescriptor } from '../../move/index.js'\nimport chalk from 'chalk'\nimport { AptosNetwork } from '../network.js'\nimport { AptosClient } from 'aptos-sdk'\nimport { getMeaningfulFunctionParams } from '../utils.js'\nimport { NeutralMoveModule, NeutralMoveStruct } from '../../move/neutral-models.js'\nimport { AbstractCodegen } from '../../move/abstract-codegen.js'\n\nexport async function codegen(abisDir: string, outDir = 'src/types/aptos') {\n if (!fs.existsSync(abisDir)) {\n return\n }\n console.log(chalk.green('Generated Types for Aptos'))\n const gen = new AptosCodegen()\n await gen.generate(abisDir, outDir)\n}\n\nfunction getRpcEndpoint(network: AptosNetwork): string {\n switch (network) {\n case AptosNetwork.TEST_NET:\n return 'https://testnet.aptoslabs.com/'\n }\n return 'https://mainnet.aptoslabs.com/'\n}\n\nfunction getRpcClient(network: AptosNetwork): AptosClient {\n return new AptosClient(getRpcEndpoint(network))\n}\n\nclass AptosCodegen extends AbstractCodegen<MoveModuleBytecode[], AptosNetwork> {\n ADDRESS_TYPE = 'Address'\n MAIN_NET = AptosNetwork.MAIN_NET\n TEST_NET = AptosNetwork.TEST_NET\n PREFIX = 'Aptos'\n\n async fetchModules(account: string, network: AptosNetwork): Promise<MoveModuleBytecode[]> {\n const client = getRpcClient(network)\n return await client.getAccountModules(account)\n }\n\n toNeutral(modules: MoveModuleBytecode[]): NeutralMoveModule[] {\n return modules.flatMap((m) => (m.abi ? [toNeutralModule(m)] : []))\n }\n\n getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {\n return getMeaningfulFunctionParams(params)\n }\n\n getEventStructs(module: NeutralMoveModule) {\n const qname = moduleQname(module)\n const structMap = new Map<string, NeutralMoveStruct>()\n const eventMap = new Map<string, NeutralMoveStruct>()\n\n for (const struct of module.structs) {\n structMap.set(qname + SPLITTER + struct.name, struct)\n }\n\n for (const struct of module.structs) {\n for (const field of struct.fields) {\n const t = field.type\n if (t.qname === '0x1::event::EventHandle') {\n const event = t.typeArgs[0].qname\n const eventStruct = structMap.get(event)\n if (eventStruct) {\n eventMap.set(event, eventStruct)\n }\n }\n }\n }\n\n return eventMap\n }\n}\n"]}
1
+ {"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../../src/aptos/codegen/codegen.ts"],"names":[],"mappings":"AAA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CAAC,CAAA;qBACjC;iBACF;aACF;SACF;QAED,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF","sourcesContent":["import * as fs from 'fs'\nimport { MoveModuleBytecode, toInternalModule } from '../move-types.js'\nimport { moduleQname, SPLITTER, TypeDescriptor } from '../../move/index.js'\nimport chalk from 'chalk'\nimport { AptosNetwork } from '../network.js'\nimport { AptosClient } from 'aptos-sdk'\nimport { getMeaningfulFunctionParams } from '../utils.js'\nimport { InternalMoveModule, InternalMoveStruct } from '../../move/internal-models.js'\nimport { AbstractCodegen } from '../../move/abstract-codegen.js'\n\nexport async function codegen(abisDir: string, outDir = 'src/types/aptos') {\n if (!fs.existsSync(abisDir)) {\n return\n }\n console.log(chalk.green('Generated Types for Aptos'))\n const gen = new AptosCodegen()\n await gen.generate(abisDir, outDir)\n}\n\nfunction getRpcEndpoint(network: AptosNetwork): string {\n switch (network) {\n case AptosNetwork.TEST_NET:\n return 'https://testnet.aptoslabs.com/'\n }\n return 'https://mainnet.aptoslabs.com/'\n}\n\nfunction getRpcClient(network: AptosNetwork): AptosClient {\n return new AptosClient(getRpcEndpoint(network))\n}\n\nclass AptosCodegen extends AbstractCodegen<MoveModuleBytecode[], AptosNetwork> {\n ADDRESS_TYPE = 'Address'\n MAIN_NET = AptosNetwork.MAIN_NET\n TEST_NET = AptosNetwork.TEST_NET\n PREFIX = 'Aptos'\n\n async fetchModules(account: string, network: AptosNetwork): Promise<MoveModuleBytecode[]> {\n const client = getRpcClient(network)\n return await client.getAccountModules(account)\n }\n\n toInternalModules(modules: MoveModuleBytecode[]): InternalMoveModule[] {\n return modules.flatMap((m) => (m.abi ? [toInternalModule(m)] : []))\n }\n\n getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {\n return getMeaningfulFunctionParams(params)\n }\n\n getEventStructs(module: InternalMoveModule) {\n const qname = moduleQname(module)\n const structMap = new Map<string, InternalMoveStruct>()\n const eventMap = new Map<string, InternalMoveStruct>()\n\n for (const struct of module.structs) {\n structMap.set(qname + SPLITTER + struct.name, struct)\n }\n\n for (const struct of module.structs) {\n for (const field of struct.fields) {\n const t = field.type\n if (t.qname === '0x1::event::EventHandle') {\n const event = t.typeArgs[0].qname\n const eventStruct = structMap.get(event)\n if (eventStruct) {\n eventMap.set(event, eventStruct)\n }\n }\n }\n }\n\n return eventMap\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { toNeutralModule, } from './move-types.js';
1
+ import { toInternalModule, } from './move-types.js';
2
2
  import { getMeaningfulFunctionParams } from './utils.js';
3
3
  import { AbstractMoveCoder } from '../move/abstract-move-coder.js';
4
4
  export class MoveCoder extends AbstractMoveCoder {
@@ -9,7 +9,7 @@ export class MoveCoder extends AbstractMoveCoder {
9
9
  if (this.contains(module.abi.address, module.abi.name)) {
10
10
  return;
11
11
  }
12
- this.loadNeutral(toNeutralModule(module));
12
+ this.loadInternal(toInternalModule(module));
13
13
  }
14
14
  decodeEvent(event) {
15
15
  return this.decodedInternal(event);
@@ -1 +1 @@
1
- {"version":3,"file":"move-coder.js","sourceRoot":"","sources":["../../src/aptos/move-coder.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,eAAe,GAEhB,MAAM,iBAAiB,CAAA;AAGxB,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAElE,MAAM,OAAO,SAAU,SAAQ,iBAAuC;IACpE,IAAI,CAAC,MAA0B;QAC7B,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;YACf,MAAM,KAAK,CAAC,oBAAoB,CAAC,CAAA;SAClC;QACD,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YACtD,OAAM;SACP;QACD,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAA;IAC3C,CAAC;IAED,WAAW,C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AC9B,OAAO,UAAU,CAAA;AACnB,CAAC","sourcesContent":["import {\n Event,\n MoveModule,\n MoveModuleBytecode,\n MoveResource,\n toNeutralModule,\n TransactionPayload_EntryFunctionPayload,\n} from './move-types.js'\n\nimport { TypedEventInstance, TypedMoveResource, TypedEntryFunctionPayload } from './models.js'\nimport { getMeaningfulFunctionParams } from './utils.js'\nimport { AbstractMoveCoder } from '../move/abstract-move-coder.js'\n\nexport class MoveCoder extends AbstractMoveCoder<Event | MoveResource> {\n load(module: MoveModuleBytecode) {\n if (!module.abi) {\n throw Error('Module without abi')\n }\n if (this.contains(module.abi.address, module.abi.name)) {\n return\n }\n this.loadNeutral(toNeutralModule(module))\n }\n\n decodeEvent<T>(event: Event): TypedEventInstance<T> | undefined {\n return this.decodedInternal<T>(event) as TypedEventInstance<T>\n }\n filterAndDecodeEvents<T>(typeQname: string, resources: Event[]): TypedEventInstance<T>[] {\n return this.filterAndDecodeInternal(typeQname, resources) as TypedEventInstance<T>[]\n }\n decodeResource<T>(res: MoveResource): TypedMoveResource<T> | undefined {\n return this.decodedInternal<T>(res)\n }\n filterAndDecodeResources<T>(typeQname: string, resources: MoveResource[]): TypedMoveResource<T>[] {\n return this.filterAndDecodeInternal(typeQname, resources)\n }\n\n decodeFunctionPayload(payload: TransactionPayload_EntryFunctionPayload): TransactionPayload_EntryFunctionPayload {\n const argumentsTyped: any[] = []\n\n try {\n const func = this.getMoveFunction(payload.function)\n const params = getMeaningfulFunctionParams(func.params)\n for (const [idx, arg] of payload.arguments.entries()) {\n // TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them\n const argType = params[idx]\n argumentsTyped.push(this.decode(arg, argType))\n }\n } catch (e) {\n console.error('Decoding error for ', JSON.stringify(payload), e)\n return payload\n }\n\n return {\n ...payload,\n arguments_decoded: argumentsTyped,\n } as TypedEntryFunctionPayload<any>\n }\n}\n\nexport const MOVE_CODER = new MoveCoder()\n\nexport function defaultMoveCoder(): MoveCoder {\n return MOVE_CODER\n}\n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AAC,MAAM,CAAC,CAAA;YACvD,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE;gBACpD,sGAAsG;gBACtG,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;gBAC3B,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAA;aAC/C;SACF;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;YAChE,OAAO,OAAO,CAAA;SACf;QAED,OAAO;YACL,GAAG,OAAO;YACV,iBAAiB,EAAE,cAAc;SACA,CAAA;IACrC,CAAC;CACF;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,SAAS,EAAE,CAAA;AAEzC,MAAM,UAAU,gBAAgB;IAC9B,OAAO,UAAU,CAAA;AACnB,CAAC","sourcesContent":["import {\n Event,\n MoveModuleBytecode,\n MoveResource,\n toInternalModule,\n TransactionPayload_EntryFunctionPayload,\n} from './move-types.js'\n\nimport { TypedEventInstance, TypedMoveResource, TypedEntryFunctionPayload } from './models.js'\nimport { getMeaningfulFunctionParams } from './utils.js'\nimport { AbstractMoveCoder } from '../move/abstract-move-coder.js'\n\nexport class MoveCoder extends AbstractMoveCoder<Event | MoveResource> {\n load(module: MoveModuleBytecode) {\n if (!module.abi) {\n throw Error('Module without abi')\n }\n if (this.contains(module.abi.address, module.abi.name)) {\n return\n }\n this.loadInternal(toInternalModule(module))\n }\n\n decodeEvent<T>(event: Event): TypedEventInstance<T> | undefined {\n return this.decodedInternal<T>(event) as TypedEventInstance<T>\n }\n filterAndDecodeEvents<T>(typeQname: string, resources: Event[]): TypedEventInstance<T>[] {\n return this.filterAndDecodeInternal(typeQname, resources) as TypedEventInstance<T>[]\n }\n decodeResource<T>(res: MoveResource): TypedMoveResource<T> | undefined {\n return this.decodedInternal<T>(res)\n }\n filterAndDecodeResources<T>(typeQname: string, resources: MoveResource[]): TypedMoveResource<T>[] {\n return this.filterAndDecodeInternal(typeQname, resources)\n }\n\n decodeFunctionPayload(payload: TransactionPayload_EntryFunctionPayload): TransactionPayload_EntryFunctionPayload {\n const argumentsTyped: any[] = []\n\n try {\n const func = this.getMoveFunction(payload.function)\n const params = getMeaningfulFunctionParams(func.params)\n for (const [idx, arg] of payload.arguments.entries()) {\n // TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them\n const argType = params[idx]\n argumentsTyped.push(this.decode(arg, argType))\n }\n } catch (e) {\n console.error('Decoding error for ', JSON.stringify(payload), e)\n return payload\n }\n\n return {\n ...payload,\n arguments_decoded: argumentsTyped,\n } as TypedEntryFunctionPayload<any>\n }\n}\n\nexport const MOVE_CODER = new MoveCoder()\n\nexport function defaultMoveCoder(): MoveCoder {\n return MOVE_CODER\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { Types } from 'aptos-sdk';
2
- import { NeutralMoveFunction, NeutralMoveModule, NeutralMoveStruct, NeutralMoveStructField } from '../move/neutral-models.js';
2
+ import { InternalMoveFunction, InternalMoveModule, InternalMoveStruct, InternalMoveStructField } from '../move/internal-models.js';
3
3
  export type Address = Types.Address;
4
4
  export type Event = Types.Event;
5
5
  export type MoveFunction = Types.MoveFunction;
@@ -10,7 +10,7 @@ export type MoveStructField = Types.MoveStructField;
10
10
  export type MoveModuleBytecode = Types.MoveModuleBytecode;
11
11
  export type TransactionPayload_EntryFunctionPayload = Types.TransactionPayload_EntryFunctionPayload;
12
12
  export type Transaction_UserTransaction = Types.Transaction_UserTransaction;
13
- export declare function toNeutralModule(module: MoveModuleBytecode): NeutralMoveModule;
14
- export declare function toNeutralFunction(func: MoveFunction): NeutralMoveFunction;
15
- export declare function toNeutralStruct(struct: MoveStruct): NeutralMoveStruct;
16
- export declare function toNeutralField(module: MoveStructField): NeutralMoveStructField;
13
+ export declare function toInternalModule(module: MoveModuleBytecode): InternalMoveModule;
14
+ export declare function toInternalFunction(func: MoveFunction): InternalMoveFunction;
15
+ export declare function toInternalStruct(struct: MoveStruct): InternalMoveStruct;
16
+ export declare function toInternalField(module: MoveStructField): InternalMoveStructField;
@@ -1,50 +1,50 @@
1
1
  import { Types } from 'aptos-sdk';
2
- import { NeutralMoveFunctionVisibility, } from '../move/neutral-models.js';
2
+ import { InternalMoveFunctionVisibility, } from '../move/internal-models.js';
3
3
  import { parseMoveType } from '../move/index.js';
4
- export function toNeutralModule(module) {
4
+ export function toInternalModule(module) {
5
5
  if (!module.abi) {
6
6
  throw Error('module with no ABI found');
7
7
  }
8
8
  const abi = module.abi;
9
9
  return {
10
10
  address: abi.address,
11
- exposed_functions: abi.exposed_functions.map(toNeutralFunction),
11
+ exposedFunctions: abi.exposed_functions.map(toInternalFunction),
12
12
  name: abi.name,
13
- structs: abi.structs.map(toNeutralStruct),
13
+ structs: abi.structs.map(toInternalStruct),
14
14
  };
15
15
  }
16
- export function toNeutralFunction(func) {
16
+ export function toInternalFunction(func) {
17
17
  let visibility;
18
18
  switch (func.visibility) {
19
19
  case Types.MoveFunctionVisibility.PRIVATE:
20
- visibility = NeutralMoveFunctionVisibility.PRIVATE;
20
+ visibility = InternalMoveFunctionVisibility.PRIVATE;
21
21
  break;
22
22
  case Types.MoveFunctionVisibility.PUBLIC:
23
- visibility = NeutralMoveFunctionVisibility.PUBLIC;
23
+ visibility = InternalMoveFunctionVisibility.PUBLIC;
24
24
  break;
25
25
  case Types.MoveFunctionVisibility.FRIEND:
26
- visibility = NeutralMoveFunctionVisibility.FRIEND;
26
+ visibility = InternalMoveFunctionVisibility.FRIEND;
27
27
  break;
28
28
  }
29
29
  return {
30
- generic_type_params: func.generic_type_params,
31
- is_entry: func.is_entry,
30
+ typeParams: func.generic_type_params,
31
+ isEntry: func.is_entry,
32
32
  name: func.name,
33
33
  params: func.params.map(parseMoveType),
34
34
  return: func.return.map(parseMoveType),
35
35
  visibility: visibility,
36
36
  };
37
37
  }
38
- export function toNeutralStruct(struct) {
38
+ export function toInternalStruct(struct) {
39
39
  return {
40
40
  abilities: struct.abilities,
41
- fields: struct.fields.map(toNeutralField),
42
- generic_type_params: struct.generic_type_params,
43
- is_native: struct.is_native,
41
+ fields: struct.fields.map(toInternalField),
42
+ typeParams: struct.generic_type_params,
43
+ isNative: struct.is_native,
44
44
  name: struct.name,
45
45
  };
46
46
  }
47
- export function toNeutralField(module) {
47
+ export function toInternalField(module) {
48
48
  return {
49
49
  name: module.name,
50
50
  type: parseMoveType(module.type),
@@ -1 +1 @@
1
- {"version":3,"file":"move-types.js","sourceRoot":"","sources":["../../src/aptos/move-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AACjC,OAAO,EAEL,6BAA6B,GAI9B,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAahD,MAAM,UAAU,eAAe,CAAC,MAA0B;IACxD,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;QACf,MAAM,KAAK,CAAC,0BAA0B,CAAC,CAAA;KACxC;IACD,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAA;IACtB,OAAO;QACL,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,iBAAiB,EAAE,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,iBAAiB,CAAC;QAC/D,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;KAC1C,CAAA;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAkB;IAClD,IAAI,UAAU,CAAA;IACd,QAAQ,IAAI,CAAC,UAAU,EAAE;QACvB,KAAK,KAAK,CAAC,sBAAsB,CAAC,OAAO;YACvC,UAAU,GAAG,6BAA6B,CAAC,OAAO,CAAA;YAClD,MAAK;QACP,KAAK,KAAK,CAAC,sBAAsB,CAAC,MAAM;YACtC,UAAU,GAAG,6BAA6B,CAAC,MAAM,CAAA;YACjD,MAAK;QACP,KAAK,KAAK,CAAC,sBAAsB,CAAC,MAAM;YACtC,UAAU,GAAG,6BAA6B,CAAC,MAAM,CAAA;YACjD,MAAK;KACR;IACD,OAAO;QACL,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;QAC7C,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC;QACtC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC;QACtC,UAAU,EAAE,UAAU;KACvB,CAAA;AACH,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,MAAkB;IAChD,OAAO;QACL,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC;QACzC,mBAAmB,EAAE,MAAM,CAAC,mBAAmB;QAC/C,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,IAAI,EAAE,MAAM,CAAC,IAAI;KAClB,CAAA;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,MAAuB;IACpD,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC;KACjC,CAAA;AACH,CAAC","sourcesContent":["import { Types } from 'aptos-sdk'\nimport {\n NeutralMoveFunction,\n NeutralMoveFunctionVisibility,\n NeutralMoveModule,\n NeutralMoveStruct,\n NeutralMoveStructField,\n} from '../move/neutral-models.js'\nimport { parseMoveType } from '../move/index.js'\n\nexport type Address = Types.Address\nexport type Event = Types.Event\nexport type MoveFunction = Types.MoveFunction\nexport type MoveModule = Types.MoveModule\nexport type MoveResource = Types.MoveResource\nexport type MoveStruct = Types.MoveStruct\nexport type MoveStructField = Types.MoveStructField\nexport type MoveModuleBytecode = Types.MoveModuleBytecode\nexport type TransactionPayload_EntryFunctionPayload = Types.TransactionPayload_EntryFunctionPayload\nexport type Transaction_UserTransaction = Types.Transaction_UserTransaction\n\nexport function toNeutralModule(module: MoveModuleBytecode): NeutralMoveModule {\n if (!module.abi) {\n throw Error('module with no ABI found')\n }\n const abi = module.abi\n return {\n address: abi.address,\n exposed_functions: abi.exposed_functions.map(toNeutralFunction),\n name: abi.name,\n structs: abi.structs.map(toNeutralStruct),\n }\n}\n\nexport function toNeutralFunction(func: MoveFunction): NeutralMoveFunction {\n let visibility\n switch (func.visibility) {\n case Types.MoveFunctionVisibility.PRIVATE:\n visibility = NeutralMoveFunctionVisibility.PRIVATE\n break\n case Types.MoveFunctionVisibility.PUBLIC:\n visibility = NeutralMoveFunctionVisibility.PUBLIC\n break\n case Types.MoveFunctionVisibility.FRIEND:\n visibility = NeutralMoveFunctionVisibility.FRIEND\n break\n }\n return {\n generic_type_params: func.generic_type_params,\n is_entry: func.is_entry,\n name: func.name,\n params: func.params.map(parseMoveType),\n return: func.return.map(parseMoveType),\n visibility: visibility,\n }\n}\n\nexport function toNeutralStruct(struct: MoveStruct): NeutralMoveStruct {\n return {\n abilities: struct.abilities,\n fields: struct.fields.map(toNeutralField),\n generic_type_params: struct.generic_type_params,\n is_native: struct.is_native,\n name: struct.name,\n }\n}\n\nexport function toNeutralField(module: MoveStructField): NeutralMoveStructField {\n return {\n name: module.name,\n type: parseMoveType(module.type),\n }\n}\n"]}
1
+ {"version":3,"file":"move-types.js","sourceRoot":"","sources":["../../src/aptos/move-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AACjC,OAAO,EAEL,8BAA8B,GAI/B,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAahD,MAAM,UAAU,gBAAgB,CAAC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G,CAAC,eAAe,CAAC;QAC1C,UAAU,EAAE,MAAM,CAAC,mBAAmB;QACtC,QAAQ,EAAE,MAAM,CAAC,SAAS;QAC1B,IAAI,EAAE,MAAM,CAAC,IAAI;KAClB,CAAA;AACH,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,MAAuB;IACrD,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC;KACjC,CAAA;AACH,CAAC","sourcesContent":["import { Types } from 'aptos-sdk'\nimport {\n InternalMoveFunction,\n InternalMoveFunctionVisibility,\n InternalMoveModule,\n InternalMoveStruct,\n InternalMoveStructField,\n} from '../move/internal-models.js'\nimport { parseMoveType } from '../move/index.js'\n\nexport type Address = Types.Address\nexport type Event = Types.Event\nexport type MoveFunction = Types.MoveFunction\nexport type MoveModule = Types.MoveModule\nexport type MoveResource = Types.MoveResource\nexport type MoveStruct = Types.MoveStruct\nexport type MoveStructField = Types.MoveStructField\nexport type MoveModuleBytecode = Types.MoveModuleBytecode\nexport type TransactionPayload_EntryFunctionPayload = Types.TransactionPayload_EntryFunctionPayload\nexport type Transaction_UserTransaction = Types.Transaction_UserTransaction\n\nexport function toInternalModule(module: MoveModuleBytecode): InternalMoveModule {\n if (!module.abi) {\n throw Error('module with no ABI found')\n }\n const abi = module.abi\n return {\n address: abi.address,\n exposedFunctions: abi.exposed_functions.map(toInternalFunction),\n name: abi.name,\n structs: abi.structs.map(toInternalStruct),\n }\n}\n\nexport function toInternalFunction(func: MoveFunction): InternalMoveFunction {\n let visibility\n switch (func.visibility) {\n case Types.MoveFunctionVisibility.PRIVATE:\n visibility = InternalMoveFunctionVisibility.PRIVATE\n break\n case Types.MoveFunctionVisibility.PUBLIC:\n visibility = InternalMoveFunctionVisibility.PUBLIC\n break\n case Types.MoveFunctionVisibility.FRIEND:\n visibility = InternalMoveFunctionVisibility.FRIEND\n break\n }\n return {\n typeParams: func.generic_type_params,\n isEntry: func.is_entry,\n name: func.name,\n params: func.params.map(parseMoveType),\n return: func.return.map(parseMoveType),\n visibility: visibility,\n }\n}\n\nexport function toInternalStruct(struct: MoveStruct): InternalMoveStruct {\n return {\n abilities: struct.abilities,\n fields: struct.fields.map(toInternalField),\n typeParams: struct.generic_type_params,\n isNative: struct.is_native,\n name: struct.name,\n }\n}\n\nexport function toInternalField(module: MoveStructField): InternalMoveStructField {\n return {\n name: module.name,\n type: parseMoveType(module.type),\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { NeutralMoveFunction, NeutralMoveModule, NeutralMoveStruct } from './neutral-models.js';
1
+ import { InternalMoveFunction, InternalMoveModule, InternalMoveStruct } from './internal-models.js';
2
2
  import { AccountRegister } from './account.js';
3
3
  import { TypeDescriptor } from './types.js';
4
4
  interface OutputFile {
@@ -17,28 +17,28 @@ export declare abstract class AbstractCodegen<ModuleTypes, NetworkType> {
17
17
  PREFIX: string;
18
18
  STRUCT_FIELD_NAME: string;
19
19
  abstract fetchModules(account: string, network: NetworkType): Promise<ModuleTypes>;
20
- abstract toNeutral(modules: ModuleTypes): NeutralMoveModule[];
21
- abstract getEventStructs(module: NeutralMoveModule): Map<string, NeutralMoveStruct>;
20
+ abstract toInternalModules(modules: ModuleTypes): InternalMoveModule[];
21
+ abstract getEventStructs(module: InternalMoveModule): Map<string, InternalMoveStruct>;
22
22
  abstract getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[];
23
23
  readModulesFile(fullPath: string): any;
24
24
  generate(srcDir: string, outputDir: string): Promise<void>;
25
25
  generateForNetwork(srcDir: string, outputDir: string, network: NetworkType): Promise<void>;
26
26
  generateNetworkOption(network: NetworkType): "TEST_NET" | "MAIN_NET";
27
- generateModule(module: NeutralMoveModule, network: NetworkType): string;
28
- generateStructs(module: NeutralMoveModule, struct: NeutralMoveStruct, events: Set<string>): string;
29
- generateFunctionTypeParameters(func: NeutralMoveFunction): string;
30
- generateStructTypeParameters(struct: NeutralMoveStruct, useAny?: boolean): string;
31
- generateCallArgsStructs(module: NeutralMoveModule, func: NeutralMoveFunction): string | undefined;
32
- generateOnEntryFunctions(module: NeutralMoveModule, func: NeutralMoveFunction): string;
33
- generateOnEvents(module: NeutralMoveModule, struct: NeutralMoveStruct): string;
27
+ generateModule(module: InternalMoveModule, network: NetworkType): string;
28
+ generateStructs(module: InternalMoveModule, struct: InternalMoveStruct, events: Set<string>): string;
29
+ generateFunctionTypeParameters(func: InternalMoveFunction): string;
30
+ generateStructTypeParameters(struct: InternalMoveStruct, useAny?: boolean): string;
31
+ generateCallArgsStructs(module: InternalMoveModule, func: InternalMoveFunction): string | undefined;
32
+ generateOnEntryFunctions(module: InternalMoveModule, func: InternalMoveFunction): string;
33
+ generateOnEvents(module: InternalMoveModule, struct: InternalMoveStruct): string;
34
34
  }
35
35
  export declare class AccountCodegen<ModuleType, NetworkType> {
36
- modules: NeutralMoveModule[];
36
+ modules: InternalMoveModule[];
37
37
  config: Config<NetworkType>;
38
38
  abi: ModuleType;
39
39
  loader: AccountRegister;
40
40
  moduleGen: AbstractCodegen<ModuleType, NetworkType>;
41
- constructor(moduleGen: AbstractCodegen<ModuleType, NetworkType>, loader: AccountRegister, abi: ModuleType, modules: NeutralMoveModule[], config: Config<NetworkType>);
41
+ constructor(moduleGen: AbstractCodegen<ModuleType, NetworkType>, loader: AccountRegister, abi: ModuleType, modules: InternalMoveModule[], config: Config<NetworkType>);
42
42
  generate(): OutputFile[];
43
43
  }
44
44
  export {};
@@ -42,7 +42,7 @@ export class AbstractCodegen {
42
42
  }
43
43
  const fullPath = path.resolve(srcDir, file);
44
44
  const abi = this.readModulesFile(fullPath);
45
- const modules = this.toNeutral(abi);
45
+ const modules = this.toInternalModules(abi);
46
46
  for (const module of modules) {
47
47
  loader.register(module, path.basename(file, '.json'));
48
48
  }
@@ -58,7 +58,7 @@ export class AbstractCodegen {
58
58
  console.log(`download dependent module for account ${account} at ${network}`);
59
59
  try {
60
60
  const rawModules = await this.fetchModules(account, network);
61
- const modules = this.toNeutral(rawModules);
61
+ const modules = this.toInternalModules(rawModules);
62
62
  fs.writeFileSync(path.resolve(srcDir, account + '.json'), JSON.stringify(rawModules, null, '\t'));
63
63
  for (const module of modules) {
64
64
  loader.register(module, account);
@@ -100,7 +100,7 @@ export class AbstractCodegen {
100
100
  return 'MAIN_NET';
101
101
  }
102
102
  generateModule(module, network) {
103
- const functions = module.exposed_functions
103
+ const functions = module.exposedFunctions
104
104
  .map((f) => this.generateOnEntryFunctions(module, f))
105
105
  .filter((s) => s !== '');
106
106
  const eventStructs = this.getEventStructs(module);
@@ -109,7 +109,7 @@ export class AbstractCodegen {
109
109
  .map((e) => this.generateOnEvents(module, e))
110
110
  .filter((s) => s !== '');
111
111
  const structs = module.structs.map((s) => this.generateStructs(module, s, eventTypes));
112
- const callArgs = module.exposed_functions.map((f) => this.generateCallArgsStructs(module, f));
112
+ const callArgs = module.exposedFunctions.map((f) => this.generateCallArgsStructs(module, f));
113
113
  const moduleName = normalizeToJSName(module.name);
114
114
  let processor = '';
115
115
  if (functions.length > 0 || events.length > 0) {
@@ -120,15 +120,15 @@ export class AbstractCodegen {
120
120
  }
121
121
  static DEFAULT_OPTIONS: ${this.PREFIX}BindOptions = {
122
122
  address: "${module.address}",
123
- network: ${this.PREFIX}Network.${this.generateNetworkOption(network)}
123
+ network: ${this.PREFIX}Network.${this.generateNetworkOption(network)}
124
124
  }
125
125
 
126
126
  static bind(options: Partial<${this.PREFIX}BindOptions> = {}): ${moduleName} {
127
127
  return new ${moduleName}({ ...${moduleName}.DEFAULT_OPTIONS, ...options })
128
128
  }
129
-
129
+
130
130
  ${functions.join('\n')}
131
-
131
+
132
132
  ${events.join('\n')}
133
133
  }
134
134
  `;
@@ -138,7 +138,7 @@ export class AbstractCodegen {
138
138
 
139
139
  export namespace ${moduleName} {
140
140
  ${structs.join('\n')}
141
-
141
+
142
142
  ${callArgs.join('\n')}
143
143
  }
144
144
  `;
@@ -154,26 +154,26 @@ export class AbstractCodegen {
154
154
  let eventPayload = '';
155
155
  if (events.has(moduleQname(module) + SPLITTER + struct.name)) {
156
156
  eventPayload = `
157
- export interface ${structName}Instance extends
157
+ export interface ${structName}Instance extends
158
158
  TypedEventInstance<${structName}${genericStringAny}> {
159
159
  ${this.STRUCT_FIELD_NAME}_decoded: ${structName}${genericStringAny}
160
- type_arguments: [${struct.generic_type_params.map((_) => 'string').join(', ')}]
160
+ type_arguments: [${struct.typeParams.map((_) => 'string').join(', ')}]
161
161
  }
162
162
  `;
163
163
  }
164
164
  return `
165
165
  export class ${structName}${genericString} {
166
166
  static TYPE_QNAME = '${module.address}::${module.name}::${struct.name}'
167
- ${fields.join('\n')}
167
+ ${fields.join('\n')}
168
168
  }
169
-
169
+
170
170
  ${eventPayload}
171
171
  `;
172
172
  }
173
173
  generateFunctionTypeParameters(func) {
174
174
  let genericString = '';
175
- if (func.generic_type_params && func.generic_type_params.length > 0) {
176
- const params = func.generic_type_params
175
+ if (func.typeParams && func.typeParams.length > 0) {
176
+ const params = func.typeParams
177
177
  .map((v, idx) => {
178
178
  return `T${idx}=any`;
179
179
  })
@@ -184,8 +184,8 @@ export class AbstractCodegen {
184
184
  }
185
185
  generateStructTypeParameters(struct, useAny = false) {
186
186
  let genericString = '';
187
- if (struct.generic_type_params && struct.generic_type_params.length > 0) {
188
- const params = struct.generic_type_params
187
+ if (struct.typeParams && struct.typeParams.length > 0) {
188
+ const params = struct.typeParams
189
189
  .map((v, idx) => {
190
190
  return useAny ? 'any' : 'T' + idx;
191
191
  })
@@ -195,7 +195,7 @@ export class AbstractCodegen {
195
195
  return genericString;
196
196
  }
197
197
  generateCallArgsStructs(module, func) {
198
- if (!func.is_entry) {
198
+ if (!func.isEntry) {
199
199
  return;
200
200
  }
201
201
  const fields = this.getMeaningfulFunctionParams(func.params).map((param) => {
@@ -207,12 +207,12 @@ export class AbstractCodegen {
207
207
  export interface ${camelFuncName}Payload${genericString}
208
208
  extends TypedEntryFunctionPayload<[${fields.join(',')}]> {
209
209
  arguments_decoded: [${fields.join(',')}],
210
- type_arguments: [${func.generic_type_params.map((_) => 'string').join(', ')}]
210
+ type_arguments: [${func.typeParams.map((_) => 'string').join(', ')}]
211
211
  }
212
212
  `;
213
213
  }
214
214
  generateOnEntryFunctions(module, func) {
215
- if (!func.is_entry) {
215
+ if (!func.isEntry) {
216
216
  return '';
217
217
  }
218
218
  // const genericString = generateFunctionTypeParameters(func)
@@ -276,8 +276,8 @@ export class AccountCodegen {
276
276
  }
277
277
  const imports = `
278
278
  import { CallFilter } from "@sentio/sdk/move"
279
- import {
280
- MoveCoder, defaultMoveCoder, ${this.moduleGen.PREFIX}BindOptions, ${this.moduleGen.PREFIX}BaseProcessor,
279
+ import {
280
+ MoveCoder, defaultMoveCoder, ${this.moduleGen.PREFIX}BindOptions, ${this.moduleGen.PREFIX}BaseProcessor,
281
281
  TypedEventInstance, ${this.moduleGen.PREFIX}Network, TypedEntryFunctionPayload,
282
282
  ${this.moduleGen.PREFIX}Context } from "@sentio/sdk/${this.moduleGen.PREFIX.toLowerCase()}"
283
283
  import { MoveFetchConfig } from "@sentio/protos"
@@ -304,15 +304,15 @@ export class AccountCodegen {
304
304
  /* Autogenerated file. Do not edit manually. */
305
305
  /* tslint:disable */
306
306
  /* eslint-disable */
307
-
307
+
308
308
  /* Generated modules for account ${address} */
309
-
309
+
310
310
  ${imports}
311
-
311
+
312
312
  ${moduleImports.join('\n')}
313
-
313
+
314
314
  ${this.modules.map((m) => this.moduleGen.generateModule(m, this.config.network)).join('\n')}
315
-
315
+
316
316
  const MODULES = JSON.parse('${JSON.stringify(this.abi)}')
317
317
 
318
318
  export function loadAllTypes(coder: MoveCoder) {
@@ -321,7 +321,7 @@ export class AccountCodegen {
321
321
  coder.load(m as any)
322
322
  }
323
323
  }
324
-
324
+
325
325
  loadAllTypes(defaultMoveCoder())
326
326
  `; // source
327
327
  return [
@@ -1 +1 @@
1
- {"version":3,"file":"abstract-codegen.js","sourceRoot":"","sources":["../../src/move/abstract-cod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AI,CAAC,IAAI,CAAC;;kCAE7D,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC;;;QAGlD,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;;;;;;KAOtE,CAAA,CAAC,SAAS;QAEX,OAAO;YACL;gBACE,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,GAAG,KAAK;gBACtC,WAAW,EAAE,MAAM;aACpB;SACF,CAAA;IACH,CAAC;CACF;AAED,SAAS,mBAAmB,CAAC,KAAa;IACxC,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,KAAK,CAAA;KACb;IACD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;AAC9E,CAAC","sourcesContent":["import { NeutralMoveFunction, NeutralMoveModule, NeutralMoveStruct } from './neutral-models.js'\nimport path from 'path'\nimport fs from 'fs'\nimport { AccountModulesImportInfo, AccountRegister } from './account.js'\nimport chalk from 'chalk'\nimport { format } from 'prettier'\nimport { isFrameworkAccount, moduleQname, normalizeToJSName, SPLITTER } from './utils.js'\nimport { generateTypeForDescriptor } from './ts-type.js'\nimport { camelCase } from 'lodash-es'\nimport { TypeDescriptor } from './types.js'\n\ninterface OutputFile {\n fileName: string\n fileContent: string\n}\n\ninterface Config<NetworkType> {\n fileName: string\n outputDir: string\n network: NetworkType\n}\n\nexport abstract class AbstractCodegen<ModuleTypes, NetworkType> {\n TEST_NET: NetworkType\n MAIN_NET: NetworkType\n ADDRESS_TYPE: string\n PREFIX: string\n STRUCT_FIELD_NAME: string = 'data'\n\n abstract fetchModules(account: string, network: NetworkType): Promise<ModuleTypes>\n abstract toNeutral(modules: ModuleTypes): NeutralMoveModule[]\n abstract getEventStructs(module: NeutralMoveModule): Map<string, NeutralMoveStruct>\n\n abstract getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[]\n\n readModulesFile(fullPath: string) {\n return JSON.parse(fs.readFileSync(fullPath, 'utf-8'))\n }\n\n async generate(srcDir: string, outputDir: string) {\n await this.generateForNetwork(srcDir, outputDir, this.MAIN_NET)\n await this.generateForNetwork(path.join(srcDir, 'testnet'), path.join(outputDir, 'testnet'), this.TEST_NET)\n }\n\n async generateForNetwork(srcDir: string, outputDir: string, network: NetworkType) {\n if (!fs.existsSync(srcDir)) {\n return\n }\n if (network === this.TEST_NET) {\n console.log('Found testnet directory, generate code for testnet modules')\n }\n const files = fs.readdirSync(srcDir)\n outputDir = path.resolve(outputDir)\n const outputs: OutputFile[] = []\n\n fs.mkdirSync(outputDir, { recursive: true })\n\n const loader = new AccountRegister()\n\n // when generating user code, don't need to generate framework account\n loader.accountImports.set('0x1', new AccountModulesImportInfo('0x1', '0x1'))\n loader.accountImports.set('0x2', new AccountModulesImportInfo('0x2', '0x2'))\n loader.accountImports.set('0x3', new AccountModulesImportInfo('0x3', '0x3'))\n // const client = getRpcClient(network)\n\n for (const file of files) {\n if (!file.endsWith('.json')) {\n continue\n }\n const fullPath = path.resolve(srcDir, file)\n const abi = this.readModulesFile(fullPath)\n const modules = this.toNeutral(abi)\n\n for (const module of modules) {\n loader.register(module, path.basename(file, '.json'))\n }\n const codeGen = new AccountCodegen(this, loader, abi, modules, {\n fileName: path.basename(file, '.json'),\n outputDir: outputDir,\n network,\n })\n\n outputs.push(...codeGen.generate())\n }\n\n while (loader.pendingAccounts.size > 0) {\n for (const account of loader.pendingAccounts) {\n console.log(`download dependent module for account ${account} at ${network}`)\n\n try {\n const rawModules = await this.fetchModules(account, network)\n const modules = this.toNeutral(rawModules)\n\n fs.writeFileSync(path.resolve(srcDir, account + '.json'), JSON.stringify(rawModules, null, '\\t'))\n\n for (const module of modules) {\n loader.register(module, account)\n }\n const codeGen = new AccountCodegen(this, loader, rawModules, modules, {\n fileName: account,\n outputDir: outputDir,\n network,\n })\n\n outputs.push(...codeGen.generate())\n } catch (e) {\n console.error(\n chalk.red(\n 'Error downloading account module, check if you choose the right network,or download account modules manually into your director'\n )\n )\n console.error(e)\n process.exit(1)\n }\n }\n }\n\n for (const output of outputs) {\n const content = format(output.fileContent, { parser: 'typescript' })\n fs.writeFileSync(path.join(outputDir, output.fileName), content)\n }\n\n const rootFile = path.join(outputDir, 'index.ts')\n fs.writeFileSync(\n rootFile,\n `/* Autogenerated file. Do not edit manually. */\n/* tslint:disable */\n/* eslint-disable */\n`\n )\n for (const output of outputs) {\n const parsed = path.parse(output.fileName)\n const content = `export * as _${parsed.name} from './${parsed.name}.js'\\n`\n fs.appendFileSync(rootFile, content)\n }\n }\n\n generateNetworkOption(network: NetworkType) {\n switch (network) {\n case this.TEST_NET:\n return 'TEST_NET'\n }\n return 'MAIN_NET'\n }\n\n generateModule(module: NeutralMoveModule, network: NetworkType) {\n const functions = module.exposed_functions\n .map((f) => this.generateOnEntryFunctions(module, f))\n .filter((s) => s !== '')\n\n const eventStructs = this.getEventStructs(module)\n const eventTypes = new Set(eventStructs.keys())\n const events = Array.from(eventStructs.values())\n .map((e) => this.generateOnEvents(module, e))\n .filter((s) => s !== '')\n const structs = module.structs.map((s) => this.generateStructs(module, s, eventTypes))\n const callArgs = module.exposed_functions.map((f) => this.generateCallArgsStructs(module, f))\n\n const moduleName = normalizeToJSName(module.name)\n let processor = ''\n if (functions.length > 0 || events.length > 0) {\n processor = `export class ${moduleName} extends ${this.PREFIX}BaseProcessor {\n\n constructor(options: ${this.PREFIX}BindOptions) {\n super(\"${module.name}\", options)\n }\n static DEFAULT_OPTIONS: ${this.PREFIX}BindOptions = {\n address: \"${module.address}\",\n network: ${this.PREFIX}Network.${this.generateNetworkOption(network)} \n }\n\n static bind(options: Partial<${this.PREFIX}BindOptions> = {}): ${moduleName} {\n return new ${moduleName}({ ...${moduleName}.DEFAULT_OPTIONS, ...options })\n }\n \n ${functions.join('\\n')}\n \n ${events.join('\\n')}\n }\n `\n }\n\n return `\n ${processor}\n\n export namespace ${moduleName} {\n ${structs.join('\\n')}\n \n ${callArgs.join('\\n')}\n }\n `\n }\n\n generateStructs(module: NeutralMoveModule, struct: NeutralMoveStruct, events: Set<string>) {\n const genericString = this.generateStructTypeParameters(struct)\n const genericStringAny = this.generateStructTypeParameters(struct, true)\n\n const structName = normalizeToJSName(struct.name)\n\n const fields = struct.fields.map((field) => {\n const type = generateTypeForDescriptor(field.type, module.address, this.ADDRESS_TYPE)\n return `${field.name}: ${type}`\n })\n\n let eventPayload = ''\n if (events.has(moduleQname(module) + SPLITTER + struct.name)) {\n eventPayload = `\n export interface ${structName}Instance extends \n TypedEventInstance<${structName}${genericStringAny}> {\n ${this.STRUCT_FIELD_NAME}_decoded: ${structName}${genericStringAny}\n type_arguments: [${struct.generic_type_params.map((_) => 'string').join(', ')}]\n }\n `\n }\n\n return `\n export class ${structName}${genericString} {\n static TYPE_QNAME = '${module.address}::${module.name}::${struct.name}'\n ${fields.join('\\n')} \n }\n \n ${eventPayload}\n `\n }\n\n generateFunctionTypeParameters(func: NeutralMoveFunction) {\n let genericString = ''\n if (func.generic_type_params && func.generic_type_params.length > 0) {\n const params = func.generic_type_params\n .map((v, idx) => {\n return `T${idx}=any`\n })\n .join(',')\n genericString = `<${params}>`\n }\n return genericString\n }\n\n generateStructTypeParameters(struct: NeutralMoveStruct, useAny = false) {\n let genericString = ''\n\n if (struct.generic_type_params && struct.generic_type_params.length > 0) {\n const params = struct.generic_type_params\n .map((v, idx) => {\n return useAny ? 'any' : 'T' + idx\n })\n .join(',')\n genericString = `<${params}>`\n }\n return genericString\n }\n\n generateCallArgsStructs(module: NeutralMoveModule, func: NeutralMoveFunction) {\n if (!func.is_entry) {\n return\n }\n\n const fields = this.getMeaningfulFunctionParams(func.params).map((param) => {\n return generateTypeForDescriptor(param, module.address, this.ADDRESS_TYPE)\n })\n\n const camelFuncName = capitalizeFirstChar(camelCase(func.name))\n\n const genericString = this.generateFunctionTypeParameters(func)\n return `\n export interface ${camelFuncName}Payload${genericString}\n extends TypedEntryFunctionPayload<[${fields.join(',')}]> {\n arguments_decoded: [${fields.join(',')}],\n type_arguments: [${func.generic_type_params.map((_) => 'string').join(', ')}]\n }\n `\n }\n\n generateOnEntryFunctions(module: NeutralMoveModule, func: NeutralMoveFunction) {\n if (!func.is_entry) {\n return ''\n }\n\n // const genericString = generateFunctionTypeParameters(func)\n const moduleName = normalizeToJSName(module.name)\n\n const camelFuncName = capitalizeFirstChar(camelCase(func.name))\n const source = `\n onEntry${camelFuncName}(func: (call: ${moduleName}.${camelFuncName}Payload, ctx: ${this.PREFIX}Context) => void, filter?: CallFilter, fetchConfig?: MoveFetchConfig): ${moduleName} {\n this.onEntryFunctionCall(func, {\n ...filter,\n function: '${module.name}::${func.name}'\n },\n fetchConfig)\n return this\n }`\n\n return source\n }\n\n generateOnEvents(module: NeutralMoveModule, struct: NeutralMoveStruct): string {\n // for struct that has drop + store\n // if (!isEvent(struct, module)) {\n // return ''\n // }\n\n // const genericString = generateStructTypeParameters(struct)\n\n const moduleName = normalizeToJSName(module.name)\n const source = `\n onEvent${struct.name}(func: (event: ${moduleName}.${normalizeToJSName(struct.name)}Instance, ctx: ${\n this.PREFIX\n }Context) => void, fetchConfig?: MoveFetchConfig): ${moduleName} {\n this.onMoveEvent(func, {\n type: '${module.name}::${struct.name}'\n },\n fetchConfig)\n return this\n }\n `\n return source\n }\n}\n\nexport class AccountCodegen<ModuleType, NetworkType> {\n modules: NeutralMoveModule[]\n config: Config<NetworkType>\n abi: ModuleType\n loader: AccountRegister\n moduleGen: AbstractCodegen<ModuleType, NetworkType>\n\n constructor(\n moduleGen: AbstractCodegen<ModuleType, NetworkType>,\n loader: AccountRegister,\n abi: ModuleType,\n modules: NeutralMoveModule[],\n config: Config<NetworkType>\n ) {\n // const json = fs.readFileSync(config.srcFile, 'utf-8')\n this.moduleGen = moduleGen\n this.abi = abi\n this.modules = modules\n this.config = config\n this.loader = loader\n }\n\n generate(): OutputFile[] {\n if (!this.modules) {\n return []\n }\n // const baseName = path.basename(this.config.fileName, '.json')\n\n let address: string | undefined\n for (const module of this.modules) {\n address = module.address\n }\n if (!address) {\n return []\n }\n\n const imports = `\n import { CallFilter } from \"@sentio/sdk/move\"\n import { \n MoveCoder, defaultMoveCoder, ${this.moduleGen.PREFIX}BindOptions, ${this.moduleGen.PREFIX}BaseProcessor, \n TypedEventInstance, ${this.moduleGen.PREFIX}Network, TypedEntryFunctionPayload,\n ${this.moduleGen.PREFIX}Context } from \"@sentio/sdk/${this.moduleGen.PREFIX.toLowerCase()}\"\n import { MoveFetchConfig } from \"@sentio/protos\"\n import { ${this.moduleGen.ADDRESS_TYPE} } from \"@sentio/sdk/${this.moduleGen.PREFIX.toLowerCase()}\"\n `\n\n const dependedAccounts: string[] = []\n\n const moduleImports: string[] = []\n\n const info = this.loader.accountImports.get(address)\n\n if (info) {\n for (const [account] of info.imports.entries()) {\n // Remap to user's filename if possible, TODO codepath not well tested\n const tsAccountModule = './' + (this.loader.accountImports.get(account)?.moduleName || account)\n if (isFrameworkAccount(account) && !isFrameworkAccount(address)) {\n // Decide where to find runtime library\n moduleImports.push(`import { _${account} } from \"@sentio/sdk/${this.moduleGen.PREFIX.toLowerCase()}/builtin\"`)\n } else {\n moduleImports.push(`import * as _${account} from \"${tsAccountModule}.js\"`)\n }\n\n dependedAccounts.push(account)\n }\n }\n\n const source = `\n /* Autogenerated file. Do not edit manually. */\n /* tslint:disable */\n /* eslint-disable */\n \n /* Generated modules for account ${address} */\n \n ${imports}\n \n ${moduleImports.join('\\n')}\n \n ${this.modules.map((m) => this.moduleGen.generateModule(m, this.config.network)).join('\\n')}\n \n const MODULES = JSON.parse('${JSON.stringify(this.abi)}')\n\n export function loadAllTypes(coder: MoveCoder) {\n ${dependedAccounts.map((a) => `_${a}.loadAllTypes(coder)`).join('\\n')}\n for (const m of Object.values(MODULES)) {\n coder.load(m as any)\n }\n }\n \n loadAllTypes(defaultMoveCoder())\n ` // source\n\n return [\n {\n fileName: this.config.fileName + '.ts',\n fileContent: source,\n },\n ]\n }\n}\n\nfunction capitalizeFirstChar(input: string): string {\n if (!input) {\n return input\n }\n return input[0].toUpperCase() + (input.length > 1 ? input.substring(1) : '')\n}\n"]}
1
+ {"version":3,"file":"abstract-codegen.js","sourceRoot":"","sources":["../../src/move/abstract-codegen.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,wBAAwB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AACxE,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACzF,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAcrC,MAAM,OAAgB,eAAe;IACnC,QAAQ,CAAa;IACrB,QAAQ,CAAa;IACrB,YAAY,CAAQ;IACpB,MAAM,CAAQ;IACd,iBAAiB,GAAW,MAAM,CAAA;IAUlC,eAAe,CAAC,QAAgB;QAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAA;IACvD,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,MAAc,EAAE,SAAiB;QAC9C,MAAM,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;QAC/D,MAAM,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,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;SACF;QAED,MAAM,MAAM,GAAG;;;;;uCAKoB,OAAO;;MAExC,OAAO;;MAEP,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;;MAExB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;kCAE7D,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC;;;QAGlD,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;;;;;;KAOtE,CAAA,CAAC,SAAS;QAEX,OAAO;YACL;gBACE,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,GAAG,KAAK;gBACtC,WAAW,EAAE,MAAM;aACpB;SACF,CAAA;IACH,CAAC;CACF;AAED,SAAS,mBAAmB,CAAC,KAAa;IACxC,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,KAAK,CAAA;KACb;IACD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;AAC9E,CAAC","sourcesContent":["import { InternalMoveFunction, InternalMoveModule, InternalMoveStruct } from './internal-models.js'\nimport path from 'path'\nimport fs from 'fs'\nimport { AccountModulesImportInfo, AccountRegister } from './account.js'\nimport chalk from 'chalk'\nimport { format } from 'prettier'\nimport { isFrameworkAccount, moduleQname, normalizeToJSName, SPLITTER } from './utils.js'\nimport { generateTypeForDescriptor } from './ts-type.js'\nimport { camelCase } from 'lodash-es'\nimport { TypeDescriptor } from './types.js'\n\ninterface OutputFile {\n fileName: string\n fileContent: string\n}\n\ninterface Config<NetworkType> {\n fileName: string\n outputDir: string\n network: NetworkType\n}\n\nexport abstract class AbstractCodegen<ModuleTypes, NetworkType> {\n TEST_NET: NetworkType\n MAIN_NET: NetworkType\n ADDRESS_TYPE: string\n PREFIX: string\n STRUCT_FIELD_NAME: string = 'data'\n\n abstract fetchModules(account: string, network: NetworkType): Promise<ModuleTypes>\n abstract toInternalModules(modules: ModuleTypes): InternalMoveModule[]\n // Get the structs that represent Events\n abstract getEventStructs(module: InternalMoveModule): Map<string, InternalMoveStruct>\n // Get the parameters that actually have arguments in runtime\n // Aptos first signer and Sui's last TxContext are no use\n abstract getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[]\n\n readModulesFile(fullPath: string) {\n return JSON.parse(fs.readFileSync(fullPath, 'utf-8'))\n }\n\n async generate(srcDir: string, outputDir: string) {\n await this.generateForNetwork(srcDir, outputDir, this.MAIN_NET)\n await this.generateForNetwork(path.join(srcDir, 'testnet'), path.join(outputDir, 'testnet'), this.TEST_NET)\n }\n\n async generateForNetwork(srcDir: string, outputDir: string, network: NetworkType) {\n if (!fs.existsSync(srcDir)) {\n return\n }\n if (network === this.TEST_NET) {\n console.log('Found testnet directory, generate code for testnet modules')\n }\n const files = fs.readdirSync(srcDir)\n outputDir = path.resolve(outputDir)\n const outputs: OutputFile[] = []\n\n fs.mkdirSync(outputDir, { recursive: true })\n\n const loader = new AccountRegister()\n\n // when generating user code, don't need to generate framework account\n loader.accountImports.set('0x1', new AccountModulesImportInfo('0x1', '0x1'))\n loader.accountImports.set('0x2', new AccountModulesImportInfo('0x2', '0x2'))\n loader.accountImports.set('0x3', new AccountModulesImportInfo('0x3', '0x3'))\n // const client = getRpcClient(network)\n\n for (const file of files) {\n if (!file.endsWith('.json')) {\n continue\n }\n const fullPath = path.resolve(srcDir, file)\n const abi = this.readModulesFile(fullPath)\n const modules = this.toInternalModules(abi)\n\n for (const module of modules) {\n loader.register(module, path.basename(file, '.json'))\n }\n const codeGen = new AccountCodegen(this, loader, abi, modules, {\n fileName: path.basename(file, '.json'),\n outputDir: outputDir,\n network,\n })\n\n outputs.push(...codeGen.generate())\n }\n\n while (loader.pendingAccounts.size > 0) {\n for (const account of loader.pendingAccounts) {\n console.log(`download dependent module for account ${account} at ${network}`)\n\n try {\n const rawModules = await this.fetchModules(account, network)\n const modules = this.toInternalModules(rawModules)\n\n fs.writeFileSync(path.resolve(srcDir, account + '.json'), JSON.stringify(rawModules, null, '\\t'))\n\n for (const module of modules) {\n loader.register(module, account)\n }\n const codeGen = new AccountCodegen(this, loader, rawModules, modules, {\n fileName: account,\n outputDir: outputDir,\n network,\n })\n\n outputs.push(...codeGen.generate())\n } catch (e) {\n console.error(\n chalk.red(\n 'Error downloading account module, check if you choose the right network,or download account modules manually into your director'\n )\n )\n console.error(e)\n process.exit(1)\n }\n }\n }\n\n for (const output of outputs) {\n const content = format(output.fileContent, { parser: 'typescript' })\n fs.writeFileSync(path.join(outputDir, output.fileName), content)\n }\n\n const rootFile = path.join(outputDir, 'index.ts')\n fs.writeFileSync(\n rootFile,\n `/* Autogenerated file. Do not edit manually. */\n/* tslint:disable */\n/* eslint-disable */\n`\n )\n for (const output of outputs) {\n const parsed = path.parse(output.fileName)\n const content = `export * as _${parsed.name} from './${parsed.name}.js'\\n`\n fs.appendFileSync(rootFile, content)\n }\n }\n\n generateNetworkOption(network: NetworkType) {\n switch (network) {\n case this.TEST_NET:\n return 'TEST_NET'\n }\n return 'MAIN_NET'\n }\n\n generateModule(module: InternalMoveModule, network: NetworkType) {\n const functions = module.exposedFunctions\n .map((f) => this.generateOnEntryFunctions(module, f))\n .filter((s) => s !== '')\n\n const eventStructs = this.getEventStructs(module)\n const eventTypes = new Set(eventStructs.keys())\n const events = Array.from(eventStructs.values())\n .map((e) => this.generateOnEvents(module, e))\n .filter((s) => s !== '')\n const structs = module.structs.map((s) => this.generateStructs(module, s, eventTypes))\n const callArgs = module.exposedFunctions.map((f) => this.generateCallArgsStructs(module, f))\n\n const moduleName = normalizeToJSName(module.name)\n let processor = ''\n if (functions.length > 0 || events.length > 0) {\n processor = `export class ${moduleName} extends ${this.PREFIX}BaseProcessor {\n\n constructor(options: ${this.PREFIX}BindOptions) {\n super(\"${module.name}\", options)\n }\n static DEFAULT_OPTIONS: ${this.PREFIX}BindOptions = {\n address: \"${module.address}\",\n network: ${this.PREFIX}Network.${this.generateNetworkOption(network)}\n }\n\n static bind(options: Partial<${this.PREFIX}BindOptions> = {}): ${moduleName} {\n return new ${moduleName}({ ...${moduleName}.DEFAULT_OPTIONS, ...options })\n }\n\n ${functions.join('\\n')}\n\n ${events.join('\\n')}\n }\n `\n }\n\n return `\n ${processor}\n\n export namespace ${moduleName} {\n ${structs.join('\\n')}\n\n ${callArgs.join('\\n')}\n }\n `\n }\n\n generateStructs(module: InternalMoveModule, struct: InternalMoveStruct, events: Set<string>) {\n const genericString = this.generateStructTypeParameters(struct)\n const genericStringAny = this.generateStructTypeParameters(struct, true)\n\n const structName = normalizeToJSName(struct.name)\n\n const fields = struct.fields.map((field) => {\n const type = generateTypeForDescriptor(field.type, module.address, this.ADDRESS_TYPE)\n return `${field.name}: ${type}`\n })\n\n let eventPayload = ''\n if (events.has(moduleQname(module) + SPLITTER + struct.name)) {\n eventPayload = `\n export interface ${structName}Instance extends\n TypedEventInstance<${structName}${genericStringAny}> {\n ${this.STRUCT_FIELD_NAME}_decoded: ${structName}${genericStringAny}\n type_arguments: [${struct.typeParams.map((_) => 'string').join(', ')}]\n }\n `\n }\n\n return `\n export class ${structName}${genericString} {\n static TYPE_QNAME = '${module.address}::${module.name}::${struct.name}'\n ${fields.join('\\n')}\n }\n\n ${eventPayload}\n `\n }\n\n generateFunctionTypeParameters(func: InternalMoveFunction) {\n let genericString = ''\n if (func.typeParams && func.typeParams.length > 0) {\n const params = func.typeParams\n .map((v, idx) => {\n return `T${idx}=any`\n })\n .join(',')\n genericString = `<${params}>`\n }\n return genericString\n }\n\n generateStructTypeParameters(struct: InternalMoveStruct, useAny = false) {\n let genericString = ''\n\n if (struct.typeParams && struct.typeParams.length > 0) {\n const params = struct.typeParams\n .map((v, idx) => {\n return useAny ? 'any' : 'T' + idx\n })\n .join(',')\n genericString = `<${params}>`\n }\n return genericString\n }\n\n generateCallArgsStructs(module: InternalMoveModule, func: InternalMoveFunction) {\n if (!func.isEntry) {\n return\n }\n\n const fields = this.getMeaningfulFunctionParams(func.params).map((param) => {\n return generateTypeForDescriptor(param, module.address, this.ADDRESS_TYPE)\n })\n\n const camelFuncName = capitalizeFirstChar(camelCase(func.name))\n\n const genericString = this.generateFunctionTypeParameters(func)\n return `\n export interface ${camelFuncName}Payload${genericString}\n extends TypedEntryFunctionPayload<[${fields.join(',')}]> {\n arguments_decoded: [${fields.join(',')}],\n type_arguments: [${func.typeParams.map((_) => 'string').join(', ')}]\n }\n `\n }\n\n generateOnEntryFunctions(module: InternalMoveModule, func: InternalMoveFunction) {\n if (!func.isEntry) {\n return ''\n }\n\n // const genericString = generateFunctionTypeParameters(func)\n const moduleName = normalizeToJSName(module.name)\n\n const camelFuncName = capitalizeFirstChar(camelCase(func.name))\n const source = `\n onEntry${camelFuncName}(func: (call: ${moduleName}.${camelFuncName}Payload, ctx: ${this.PREFIX}Context) => void, filter?: CallFilter, fetchConfig?: MoveFetchConfig): ${moduleName} {\n this.onEntryFunctionCall(func, {\n ...filter,\n function: '${module.name}::${func.name}'\n },\n fetchConfig)\n return this\n }`\n\n return source\n }\n\n generateOnEvents(module: InternalMoveModule, struct: InternalMoveStruct): string {\n // for struct that has drop + store\n // if (!isEvent(struct, module)) {\n // return ''\n // }\n\n // const genericString = generateStructTypeParameters(struct)\n\n const moduleName = normalizeToJSName(module.name)\n const source = `\n onEvent${struct.name}(func: (event: ${moduleName}.${normalizeToJSName(struct.name)}Instance, ctx: ${\n this.PREFIX\n }Context) => void, fetchConfig?: MoveFetchConfig): ${moduleName} {\n this.onMoveEvent(func, {\n type: '${module.name}::${struct.name}'\n },\n fetchConfig)\n return this\n }\n `\n return source\n }\n}\n\nexport class AccountCodegen<ModuleType, NetworkType> {\n modules: InternalMoveModule[]\n config: Config<NetworkType>\n abi: ModuleType\n loader: AccountRegister\n moduleGen: AbstractCodegen<ModuleType, NetworkType>\n\n constructor(\n moduleGen: AbstractCodegen<ModuleType, NetworkType>,\n loader: AccountRegister,\n abi: ModuleType,\n modules: InternalMoveModule[],\n config: Config<NetworkType>\n ) {\n // const json = fs.readFileSync(config.srcFile, 'utf-8')\n this.moduleGen = moduleGen\n this.abi = abi\n this.modules = modules\n this.config = config\n this.loader = loader\n }\n\n generate(): OutputFile[] {\n if (!this.modules) {\n return []\n }\n // const baseName = path.basename(this.config.fileName, '.json')\n\n let address: string | undefined\n for (const module of this.modules) {\n address = module.address\n }\n if (!address) {\n return []\n }\n\n const imports = `\n import { CallFilter } from \"@sentio/sdk/move\"\n import {\n MoveCoder, defaultMoveCoder, ${this.moduleGen.PREFIX}BindOptions, ${this.moduleGen.PREFIX}BaseProcessor,\n TypedEventInstance, ${this.moduleGen.PREFIX}Network, TypedEntryFunctionPayload,\n ${this.moduleGen.PREFIX}Context } from \"@sentio/sdk/${this.moduleGen.PREFIX.toLowerCase()}\"\n import { MoveFetchConfig } from \"@sentio/protos\"\n import { ${this.moduleGen.ADDRESS_TYPE} } from \"@sentio/sdk/${this.moduleGen.PREFIX.toLowerCase()}\"\n `\n\n const dependedAccounts: string[] = []\n\n const moduleImports: string[] = []\n\n const info = this.loader.accountImports.get(address)\n\n if (info) {\n for (const [account] of info.imports.entries()) {\n // Remap to user's filename if possible, TODO codepath not well tested\n const tsAccountModule = './' + (this.loader.accountImports.get(account)?.moduleName || account)\n if (isFrameworkAccount(account) && !isFrameworkAccount(address)) {\n // Decide where to find runtime library\n moduleImports.push(`import { _${account} } from \"@sentio/sdk/${this.moduleGen.PREFIX.toLowerCase()}/builtin\"`)\n } else {\n moduleImports.push(`import * as _${account} from \"${tsAccountModule}.js\"`)\n }\n\n dependedAccounts.push(account)\n }\n }\n\n const source = `\n /* Autogenerated file. Do not edit manually. */\n /* tslint:disable */\n /* eslint-disable */\n\n /* Generated modules for account ${address} */\n\n ${imports}\n\n ${moduleImports.join('\\n')}\n\n ${this.modules.map((m) => this.moduleGen.generateModule(m, this.config.network)).join('\\n')}\n\n const MODULES = JSON.parse('${JSON.stringify(this.abi)}')\n\n export function loadAllTypes(coder: MoveCoder) {\n ${dependedAccounts.map((a) => `_${a}.loadAllTypes(coder)`).join('\\n')}\n for (const m of Object.values(MODULES)) {\n coder.load(m as any)\n }\n }\n\n loadAllTypes(defaultMoveCoder())\n ` // source\n\n return [\n {\n fileName: this.config.fileName + '.ts',\n fileContent: source,\n },\n ]\n }\n}\n\nfunction capitalizeFirstChar(input: string): string {\n if (!input) {\n return input\n }\n return input[0].toUpperCase() + (input.length > 1 ? input.substring(1) : '')\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { TypeDescriptor } from './types.js';
2
- import { NeutralMoveFunction, NeutralMoveModule, NeutralMoveStruct } from './neutral-models.js';
2
+ import { InternalMoveFunction, InternalMoveModule, InternalMoveStruct } from './internal-models.js';
3
3
  type StructWithTag<Base> = Base & {
4
4
  type: string;
5
5
  data: any;
@@ -13,10 +13,10 @@ export declare abstract class AbstractMoveCoder<StructType> {
13
13
  private typeMapping;
14
14
  private funcMapping;
15
15
  contains(account: string, name: string): boolean;
16
- loadNeutral(module: NeutralMoveModule): void;
16
+ loadInternal(module: InternalMoveModule): void;
17
17
  protected dataToBigInt(data: any): bigint;
18
- protected getMoveStruct(type: string): NeutralMoveStruct;
19
- protected getMoveFunction(type: string): NeutralMoveFunction;
18
+ protected getMoveStruct(type: string): InternalMoveStruct;
19
+ protected getMoveFunction(type: string): InternalMoveFunction;
20
20
  protected decode(data: any, type: TypeDescriptor): any;
21
21
  protected filterAndDecodeInternal<T>(typeQname: string, structs: StructWithTag<StructType>[]): DecodedStructWithTag<StructType, T>[];
22
22
  protected decodedInternal<T>(typeStruct: StructWithTag<StructType>): DecodedStructWithTag<StructType, T> | undefined;
@@ -8,7 +8,7 @@ export class AbstractMoveCoder {
8
8
  contains(account, name) {
9
9
  return this.moduleMapping.has(account + '::' + name);
10
10
  }
11
- loadNeutral(module) {
11
+ loadInternal(module) {
12
12
  if (this.contains(module.address, module.name)) {
13
13
  return;
14
14
  }
@@ -18,8 +18,8 @@ export class AbstractMoveCoder {
18
18
  const key = [module.address, module.name, struct.name].join(SPLITTER);
19
19
  this.typeMapping.set(key, struct);
20
20
  }
21
- for (const func of module.exposed_functions) {
22
- if (!func.is_entry) {
21
+ for (const func of module.exposedFunctions) {
22
+ if (!func.isEntry) {
23
23
  continue;
24
24
  }
25
25
  const key = [module.address, module.name, func.name].join(SPLITTER);