@sentio/sdk 1.28.0 → 1.29.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 (102) hide show
  1. package/lib/aptos/api.d.ts +2 -0
  2. package/lib/aptos/api.js +14 -0
  3. package/lib/aptos/api.js.map +1 -0
  4. package/lib/aptos/aptos-processor.d.ts +5 -4
  5. package/lib/aptos/aptos-processor.js +8 -9
  6. package/lib/aptos/aptos-processor.js.map +1 -1
  7. package/lib/aptos/context.d.ts +3 -2
  8. package/lib/aptos/context.js +3 -3
  9. package/lib/aptos/context.js.map +1 -1
  10. package/lib/aptos/index.d.ts +3 -2
  11. package/lib/aptos/index.js +18 -3
  12. package/lib/aptos/index.js.map +1 -1
  13. package/lib/aptos/models.d.ts +23 -0
  14. package/lib/aptos/models.js +3 -0
  15. package/lib/aptos/models.js.map +1 -0
  16. package/lib/aptos/type-registry.d.ts +21 -0
  17. package/lib/aptos/type-registry.js +156 -0
  18. package/lib/aptos/type-registry.js.map +1 -0
  19. package/lib/aptos/types.d.ts +1 -33
  20. package/lib/aptos/types.js +49 -142
  21. package/lib/aptos/types.js.map +1 -1
  22. package/lib/aptos/types.test.js.map +1 -1
  23. package/lib/aptos/utils.d.ts +0 -2
  24. package/lib/aptos/utils.js +1 -8
  25. package/lib/aptos/utils.js.map +1 -1
  26. package/lib/aptos-codegen/codegen.js +2 -1
  27. package/lib/aptos-codegen/codegen.js.map +1 -1
  28. package/lib/aptos-codegen/typegen.d.ts +0 -1
  29. package/lib/aptos-codegen/typegen.js +3 -61
  30. package/lib/aptos-codegen/typegen.js.map +1 -1
  31. package/lib/cli/upload.js +2 -1
  32. package/lib/cli/upload.js.map +1 -1
  33. package/lib/core/base-context.d.ts +12 -0
  34. package/lib/core/base-context.js +25 -0
  35. package/lib/core/base-context.js.map +1 -0
  36. package/lib/core/base-processor.d.ts +1 -2
  37. package/lib/core/base-processor.js.map +1 -1
  38. package/lib/core/context.d.ts +2 -11
  39. package/lib/core/context.js +5 -24
  40. package/lib/core/context.js.map +1 -1
  41. package/lib/core/event-tracker.d.ts +1 -1
  42. package/lib/core/event-tracker.js +2 -2
  43. package/lib/core/event-tracker.js.map +1 -1
  44. package/lib/core/exporter.d.ts +1 -1
  45. package/lib/core/exporter.js.map +1 -1
  46. package/lib/core/generic-processor.test.js.map +1 -1
  47. package/lib/core/logger.d.ts +1 -1
  48. package/lib/core/logger.js.map +1 -1
  49. package/lib/core/meter.d.ts +3 -1
  50. package/lib/core/meter.js +12 -0
  51. package/lib/core/meter.js.map +1 -1
  52. package/lib/endpoints.d.ts +6 -0
  53. package/lib/endpoints.js +11 -0
  54. package/lib/endpoints.js.map +1 -0
  55. package/lib/processor-runner.js +6 -0
  56. package/lib/processor-runner.js.map +1 -1
  57. package/lib/processor-state.d.ts +2 -6
  58. package/lib/processor-state.js +0 -2
  59. package/lib/processor-state.js.map +1 -1
  60. package/lib/provider.js +5 -5
  61. package/lib/provider.js.map +1 -1
  62. package/lib/testing/test-processor-server.d.ts +4 -1
  63. package/lib/testing/test-processor-server.js +15 -7
  64. package/lib/testing/test-processor-server.js.map +1 -1
  65. package/lib/utils/conversion.d.ts +2 -1
  66. package/lib/utils/conversion.js +3 -3
  67. package/lib/utils/conversion.js.map +1 -1
  68. package/lib/utils/dex-price.test.js.map +1 -1
  69. package/lib/utils/erc20.test.js.map +1 -1
  70. package/lib/utils/price.d.ts +9 -1
  71. package/lib/utils/price.js +49 -1
  72. package/lib/utils/price.js.map +1 -1
  73. package/lib/utils/token.d.ts +1 -1
  74. package/lib/utils/token.js +2 -2
  75. package/lib/utils/token.js.map +1 -1
  76. package/package.json +5 -2
  77. package/src/aptos/api.ts +11 -0
  78. package/src/aptos/aptos-processor.ts +7 -10
  79. package/src/aptos/context.ts +3 -3
  80. package/src/aptos/index.ts +3 -2
  81. package/src/aptos/models.ts +34 -0
  82. package/src/aptos/type-registry.ts +187 -0
  83. package/src/aptos/types.ts +53 -199
  84. package/src/aptos/utils.ts +0 -9
  85. package/src/aptos-codegen/codegen.ts +2 -1
  86. package/src/aptos-codegen/typegen.ts +1 -67
  87. package/src/cli/upload.ts +2 -1
  88. package/src/core/base-context.ts +28 -0
  89. package/src/core/base-processor.ts +1 -2
  90. package/src/core/context.ts +2 -26
  91. package/src/core/event-tracker.ts +2 -2
  92. package/src/core/exporter.ts +1 -1
  93. package/src/core/logger.ts +1 -1
  94. package/src/core/meter.ts +15 -1
  95. package/src/endpoints.ts +9 -0
  96. package/src/processor-runner.ts +6 -0
  97. package/src/processor-state.ts +2 -7
  98. package/src/provider.ts +5 -5
  99. package/src/testing/test-processor-server.ts +10 -6
  100. package/src/utils/conversion.ts +2 -1
  101. package/src/utils/price.ts +51 -1
  102. package/src/utils/token.ts +1 -1
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TYPE_REGISTRY = exports.TypeRegistry = exports.TypeDescriptor = void 0;
3
+ exports.parseMoveType = exports.TypeDescriptor = void 0;
4
4
  const utils_1 = require("./utils");
5
- const typegen_1 = require("../aptos-codegen/typegen");
6
5
  class TypeDescriptor {
7
6
  // type: string
8
7
  // qualified name without type parameters
@@ -75,154 +74,62 @@ class TypeDescriptor {
75
74
  }
76
75
  }
77
76
  exports.TypeDescriptor = TypeDescriptor;
78
- class TypeRegistry {
79
- moduleMapping = new Map();
80
- typeMapping = new Map();
81
- funcMapping = new Map();
82
- contains(account, name) {
83
- return this.moduleMapping.has(account + '::' + name);
84
- }
85
- load(module) {
86
- if (this.contains(module.address, module.name)) {
87
- return;
88
- }
89
- this.moduleMapping.set((0, utils_1.moduleQname)(module), module);
90
- for (const struct of module.structs) {
91
- // TODO move to util
92
- const key = [module.address, module.name, struct.name].join(utils_1.SPLITTER);
93
- this.typeMapping.set(key, struct);
94
- }
95
- for (const func of module.exposed_functions) {
96
- if (!func.is_entry) {
97
- continue;
98
- }
99
- const key = [module.address, module.name, func.name].join(utils_1.SPLITTER);
100
- this.funcMapping.set(key, func);
101
- }
102
- }
103
- getMoveStruct(type) {
104
- const struct = this.typeMapping.get(type);
105
- if (!struct) {
106
- throw new Error('Failed to load type' + type);
107
- }
108
- return struct;
109
- }
110
- getMoveFunction(type) {
111
- const func = this.funcMapping.get(type);
112
- if (!func) {
113
- throw new Error('Failed to load function' + type);
114
- }
115
- return func;
116
- }
117
- decode(data, type) {
118
- // process simple type
119
- if (type.qname.startsWith('&')) {
120
- return data;
121
- }
122
- switch (type.qname) {
123
- case 'signer': // TODO check this
124
- case 'address':
125
- case '0x1::string::String':
126
- case 'bool':
127
- case 'u8':
128
- case 'u16':
129
- case 'u32':
130
- return data;
131
- case 'u64':
132
- case 'u128':
133
- return BigInt(data);
134
- }
135
- // process vector
136
- if (type.qname === utils_1.VECTOR_STR) {
137
- // vector<u8> as hex string
138
- if (type.typeArgs[0].qname === 'u8') {
139
- return data;
77
+ function parseMoveType(type) {
78
+ // type = type.replace('&', '')
79
+ type = type.replaceAll('&mut ', '&');
80
+ type = type.replaceAll('mut ', '');
81
+ // TODO replace ' ' is not exactly safe, need to double check this
82
+ type = type.replaceAll(' ', '');
83
+ const stack = [new TypeDescriptor('')];
84
+ let buffer = [];
85
+ // xxx:asdf<g1<a,<c,d>>, b, g2<a,b>, e>
86
+ for (let i = 0; i < type.length; i++) {
87
+ const ch = type[i];
88
+ if (ch === '<') {
89
+ // const symbol = type.slice(symbolStart, i)
90
+ // symbolStart =
91
+ const symbol = buffer.join('');
92
+ buffer = [];
93
+ stack[stack.length - 1].qname = symbol;
94
+ stack.push(new TypeDescriptor(''));
95
+ continue;
96
+ }
97
+ if (ch === '>') {
98
+ const typeParam = stack.pop();
99
+ if (!typeParam) {
100
+ throw Error('Uxpectecd stack size');
140
101
  }
141
- const res = [];
142
- for (const entry of data) {
143
- res.push(this.decode(entry, type.typeArgs[0]));
102
+ if (buffer.length > 0) {
103
+ typeParam.qname = buffer.join('');
104
+ buffer = [];
144
105
  }
145
- return res;
146
- }
147
- // Process complex type
148
- const struct = this.getMoveStruct(type.qname);
149
- const typeCtx = new Map();
150
- for (const [idx, typeArg] of type.typeArgs.entries()) {
151
- typeCtx.set('T' + idx, typeArg);
152
- }
153
- const typedData = {};
154
- for (const field of struct.fields) {
155
- let filedType = (0, typegen_1.parseMoveType)(field.type);
156
- filedType = filedType.applyTypeArgs(typeCtx);
157
- const value = this.decode(data[field.name], filedType);
158
- typedData[field.name] = value;
106
+ stack[stack.length - 1].typeArgs.push(typeParam);
107
+ continue;
159
108
  }
160
- return typedData;
161
- }
162
- decodeEvent(event) {
163
- return this.decodedInternal(event);
164
- }
165
- filterAndDecodeEvents(typeQname, resources) {
166
- return this.filterAndDecodeInternal(typeQname, resources);
167
- }
168
- decodeResource(res) {
169
- return this.decodedInternal(res);
170
- }
171
- filterAndDecodeResources(typeQname, resources) {
172
- return this.filterAndDecodeInternal(typeQname, resources);
173
- }
174
- filterAndDecodeInternal(typeQname, structs) {
175
- if (!structs) {
176
- return [];
177
- }
178
- const results = [];
179
- for (const resource of structs) {
180
- if (resource.type.split('<')[0] !== typeQname) {
181
- continue;
109
+ if (ch === ',') {
110
+ const typeParam = stack.pop();
111
+ if (!typeParam) {
112
+ throw Error('Uxpectecd stack size');
182
113
  }
183
- const result = this.decodedInternal(resource);
184
- if (result) {
185
- results.push(result);
114
+ if (buffer.length > 0) {
115
+ typeParam.qname = buffer.join('');
116
+ buffer = [];
186
117
  }
118
+ stack[stack.length - 1].typeArgs.push(typeParam);
119
+ // continue parse next param
120
+ stack.push(new TypeDescriptor(''));
121
+ continue;
187
122
  }
188
- return results;
123
+ buffer.push(ch);
189
124
  }
190
- decodedInternal(typeStruct) {
191
- const registry = exports.TYPE_REGISTRY;
192
- // this.loadTypes(registry)
193
- // TODO check if module is not loaded
194
- const typeDescriptor = (0, typegen_1.parseMoveType)(typeStruct.type);
195
- const typeArguments = typeDescriptor.typeArgs.map((t) => t.getSignature());
196
- let dataTyped = undefined;
197
- try {
198
- dataTyped = registry.decode(typeStruct.data, typeDescriptor);
199
- }
200
- catch (e) {
201
- console.error('Decoding error for ', JSON.stringify(typeStruct), e);
202
- return undefined;
203
- }
204
- return { ...typeStruct, data_typed: dataTyped, type_arguments: typeArguments };
125
+ if (buffer.length > 0) {
126
+ stack[stack.length - 1].qname = buffer.join('');
205
127
  }
206
- decodeFunctionPayload(payload) {
207
- const registry = exports.TYPE_REGISTRY;
208
- // this.loadTypes(registry)
209
- const argumentsTyped = [];
210
- try {
211
- const func = registry.getMoveFunction(payload.function);
212
- const params = (0, utils_1.getMeaningfulFunctionParams)(func);
213
- for (const [idx, arg] of payload.arguments.entries()) {
214
- // TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them
215
- const argType = (0, typegen_1.parseMoveType)(params[idx]);
216
- argumentsTyped.push(registry.decode(arg, argType));
217
- }
218
- }
219
- catch (e) {
220
- console.error('Decoding error for ', JSON.stringify(payload), e);
221
- return payload;
222
- }
223
- return { ...payload, arguments_typed: argumentsTyped };
128
+ const res = stack.pop();
129
+ if (!res || stack.length > 0) {
130
+ throw Error('Uxpectecd stack size');
224
131
  }
132
+ return res;
225
133
  }
226
- exports.TypeRegistry = TypeRegistry;
227
- exports.TYPE_REGISTRY = new TypeRegistry();
134
+ exports.parseMoveType = parseMoveType;
228
135
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/aptos/types.ts"],"names":[],"mappings":";;;AAQA,mCAAwF;AACxF,sDAAwD;AAmCxD,MAAa,cAAc;IACzB,eAAe;IAEf,yCAAyC;IACzC,KAAK,CAAQ;IACb,mBAAmB;IACnB,kBAAkB;IAElB,QAAQ,CAAkB;IAE1B,YAAY,MAAc,EAAE,UAA6B;QACvD,IAAI,CAAC,KAAK,GAAG,MAAM,CAAA;QACnB,IAAI,CAAC,QAAQ,GAAG,UAAU,IAAI,EAAE,CAAA;IAClC,CAAC;IAED,YAAY;QACV,IAAI,IAAI,CAAC,QAAQ,CAAC,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C,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAA;aACnD;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,EAAE,GAAG,OAAO,EAAE,eAAe,EAAE,cAAc,EAAoC,CAAA;IAC1F,CAAC;CACF;AAtKD,oCAsKC;AAEY,QAAA,aAAa,GAAG,IAAI,YAAY,EAAE,CAAA","sourcesContent":["import {\n Event,\n MoveFunction,\n MoveModule,\n MoveStruct,\n TransactionPayload_EntryFunctionPayload,\n MoveResource,\n} from 'aptos-sdk/src/generated'\nimport { getMeaningfulFunctionParams, moduleQname, SPLITTER, VECTOR_STR } from './utils'\nimport { parseMoveType } from '../aptos-codegen/typegen'\n\nexport type EventInstance = Event & {\n version: string\n}\n\nexport type TypedEventInstance<T> = EventInstance & {\n // Typed data converted from ABI\n // undefined if there is converting error, usually because the ABI/data\n // mismatch\n data_typed: T\n\n type_arguments: string[]\n}\n\n// Don't use intermedidate type to make IDE happier\nexport type TypedEntryFunctionPayload<T extends Array<any>> = TransactionPayload_EntryFunctionPayload & {\n arguments_typed: T\n}\n\nexport type TypedMoveResource<T> = MoveResource & {\n data_typed: T\n type_arguments: string[]\n}\n\ninterface StructWithTag {\n type: string\n data: any\n}\n\ninterface StructWithType<T> extends StructWithTag {\n data_typed: T\n type_arguments: string[]\n}\n\nexport class TypeDescriptor {\n // type: string\n\n // qualified name without type parameters\n qname: string\n // account?: string\n // module?: string\n\n typeArgs: TypeDescriptor[]\n\n constructor(symbol: string, typeParams?: TypeDescriptor[]) {\n this.qname = symbol\n this.typeArgs = typeParams || []\n }\n\n getSignature(): string {\n if (this.typeArgs.length > 0) {\n return this.qname + '<' + this.typeArgs.map((t) => t.getSignature()).join(', ') + '>'\n }\n return this.qname\n }\n\n // Replace T0, T1 with more concrete type\n applyTypeArgs(ctx: Map<string, TypeDescriptor>): TypeDescriptor {\n const replace = ctx.get(this.qname)\n if (replace) {\n return replace\n }\n if (ctx.size === 0 || this.typeArgs.length === 0) {\n return this\n }\n\n const typeArgs: TypeDescriptor[] = []\n for (const arg of this.typeArgs) {\n const replace = ctx.get(arg.qname)\n if (replace) {\n typeArgs.push(replace)\n } else {\n typeArgs.push(arg.applyTypeArgs(ctx))\n }\n }\n return new TypeDescriptor(this.qname, typeArgs)\n }\n\n // all depended types including itself, not include system type\n dependedTypes(): string[] {\n if (this.qname.startsWith('&')) {\n return []\n }\n switch (this.qname) {\n case 'signer':\n case 'address':\n case '0x1::string::String':\n case 'bool':\n case 'u8':\n case 'u16':\n case 'u32':\n case 'u64':\n case 'u128':\n return []\n }\n\n // Type parameters are not depended\n if (this.qname.indexOf(SPLITTER) == -1) {\n if (this.qname.startsWith('T')) {\n return []\n }\n }\n\n const types = new Set<string>()\n for (const param of this.typeArgs) {\n param.dependedTypes().forEach((t) => types.add(t))\n }\n\n if (this.qname !== VECTOR_STR) {\n types.add(this.qname)\n }\n\n return Array.from(types)\n }\n}\n\nexport class TypeRegistry {\n moduleMapping = new Map<string, MoveModule>()\n typeMapping = new Map<string, MoveStruct>()\n funcMapping = new Map<string, MoveFunction>()\n\n contains(account: string, name: string) {\n return this.moduleMapping.has(account + '::' + name)\n }\n\n load(module: MoveModule) {\n if (this.contains(module.address, module.name)) {\n return\n }\n this.moduleMapping.set(moduleQname(module), module)\n\n for (const struct of module.structs) {\n // TODO move to util\n const key = [module.address, module.name, struct.name].join(SPLITTER)\n this.typeMapping.set(key, struct)\n }\n\n for (const func of module.exposed_functions) {\n if (!func.is_entry) {\n continue\n }\n const key = [module.address, module.name, func.name].join(SPLITTER)\n this.funcMapping.set(key, func)\n }\n }\n\n getMoveStruct(type: string): MoveStruct {\n const struct = this.typeMapping.get(type)\n if (!struct) {\n throw new Error('Failed to load type' + type)\n }\n return struct\n }\n\n getMoveFunction(type: string): MoveFunction {\n const func = this.funcMapping.get(type)\n if (!func) {\n throw new Error('Failed to load function' + type)\n }\n return func\n }\n\n decode(data: any, type: TypeDescriptor): any {\n // process simple type\n if (type.qname.startsWith('&')) {\n return data\n }\n switch (type.qname) {\n case 'signer': // TODO check this\n case 'address':\n case '0x1::string::String':\n case 'bool':\n case 'u8':\n case 'u16':\n case 'u32':\n return data\n case 'u64':\n case 'u128':\n return BigInt(data)\n }\n\n // process vector\n if (type.qname === VECTOR_STR) {\n // vector<u8> as hex string\n if (type.typeArgs[0].qname === 'u8') {\n return data\n }\n\n const res = []\n for (const entry of data) {\n res.push(this.decode(entry, type.typeArgs[0]))\n }\n return res\n }\n\n // Process complex type\n const struct = this.getMoveStruct(type.qname)\n\n const typeCtx = new Map<string, TypeDescriptor>()\n for (const [idx, typeArg] of type.typeArgs.entries()) {\n typeCtx.set('T' + idx, typeArg)\n }\n\n const typedData: any = {}\n\n for (const field of struct.fields) {\n let filedType = parseMoveType(field.type)\n filedType = filedType.applyTypeArgs(typeCtx)\n const value = this.decode(data[field.name], filedType)\n typedData[field.name] = value\n }\n return typedData\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 private filterAndDecodeInternal<T>(typeQname: string, structs: StructWithTag[]): StructWithType<T>[] {\n if (!structs) {\n return []\n }\n const results: StructWithType<T>[] = []\n for (const resource of structs) {\n if (resource.type.split('<')[0] !== typeQname) {\n continue\n }\n const result = this.decodedInternal(resource)\n if (result) {\n results.push(result as StructWithType<T>)\n }\n }\n return results\n }\n\n private decodedInternal<T>(typeStruct: StructWithTag): StructWithType<T> | undefined {\n const registry = TYPE_REGISTRY\n // this.loadTypes(registry)\n // TODO check if module is not loaded\n\n const typeDescriptor = parseMoveType(typeStruct.type)\n const typeArguments = typeDescriptor.typeArgs.map((t) => t.getSignature())\n\n let dataTyped = undefined\n try {\n dataTyped = registry.decode(typeStruct.data, typeDescriptor)\n } catch (e) {\n console.error('Decoding error for ', JSON.stringify(typeStruct), e)\n return undefined\n }\n return { ...typeStruct, data_typed: dataTyped, type_arguments: typeArguments } as StructWithType<T>\n }\n\n decodeFunctionPayload(payload: TransactionPayload_EntryFunctionPayload): TransactionPayload_EntryFunctionPayload {\n const registry = TYPE_REGISTRY\n // this.loadTypes(registry)\n const argumentsTyped: any[] = []\n\n try {\n const func = registry.getMoveFunction(payload.function)\n const params = getMeaningfulFunctionParams(func)\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 = parseMoveType(params[idx])\n argumentsTyped.push(registry.decode(arg, argType))\n }\n } catch (e) {\n console.error('Decoding error for ', JSON.stringify(payload), e)\n return payload\n }\n\n return { ...payload, arguments_typed: argumentsTyped } as TypedEntryFunctionPayload<any>\n }\n}\n\nexport const TYPE_REGISTRY = new TypeRegistry()\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/aptos/types.ts"],"names":[],"mappings":";;;AAAA,mCAA8C;AAE9C,MAAa,cAAc;IACzB,eAAe;IAEf,yCAAyC;IACzC,KAAK,CAAQ;IACb,mBAAmB;IACnB,kBAAkB;IAElB,QAAQ,CAAkB;IAE1B,YAAY,MAAc,EAAE,UAA6B;QACvD,IAAI,CAAC,KAAK,GAAG,MAAM,CAAA;QACnB,IAAI,CAAC,QAAQ,GAAG,UAAU,IAAI,EAAE,CAAA;IAClC,CAAC;IAED,YAAY;QACV,IAAI,I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AM,GAAG,EAAE,CAAA;aACZ;YAED,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;YAChD,4BAA4B;YAC5B,KAAK,CAAC,IAAI,CAAC,IAAI,cAAc,CAAC,EAAE,CAAC,CAAC,CAAA;YAClC,SAAQ;SACT;QAED,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;KAChB;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;QACrB,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;KAChD;IAED,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,EAAE,CAAA;IACvB,IAAI,CAAC,GAAG,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;QAC5B,MAAM,KAAK,CAAC,sBAAsB,CAAC,CAAA;KACpC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAhED,sCAgEC","sourcesContent":["import { SPLITTER, VECTOR_STR } from './utils'\n\nexport class TypeDescriptor {\n // type: string\n\n // qualified name without type parameters\n qname: string\n // account?: string\n // module?: string\n\n typeArgs: TypeDescriptor[]\n\n constructor(symbol: string, typeParams?: TypeDescriptor[]) {\n this.qname = symbol\n this.typeArgs = typeParams || []\n }\n\n getSignature(): string {\n if (this.typeArgs.length > 0) {\n return this.qname + '<' + this.typeArgs.map((t) => t.getSignature()).join(', ') + '>'\n }\n return this.qname\n }\n\n // Replace T0, T1 with more concrete type\n applyTypeArgs(ctx: Map<string, TypeDescriptor>): TypeDescriptor {\n const replace = ctx.get(this.qname)\n if (replace) {\n return replace\n }\n if (ctx.size === 0 || this.typeArgs.length === 0) {\n return this\n }\n\n const typeArgs: TypeDescriptor[] = []\n for (const arg of this.typeArgs) {\n const replace = ctx.get(arg.qname)\n if (replace) {\n typeArgs.push(replace)\n } else {\n typeArgs.push(arg.applyTypeArgs(ctx))\n }\n }\n return new TypeDescriptor(this.qname, typeArgs)\n }\n\n // all depended types including itself, not include system type\n dependedTypes(): string[] {\n if (this.qname.startsWith('&')) {\n return []\n }\n switch (this.qname) {\n case 'signer':\n case 'address':\n case '0x1::string::String':\n case 'bool':\n case 'u8':\n case 'u16':\n case 'u32':\n case 'u64':\n case 'u128':\n return []\n }\n\n // Type parameters are not depended\n if (this.qname.indexOf(SPLITTER) == -1) {\n if (this.qname.startsWith('T')) {\n return []\n }\n }\n\n const types = new Set<string>()\n for (const param of this.typeArgs) {\n param.dependedTypes().forEach((t) => types.add(t))\n }\n\n if (this.qname !== VECTOR_STR) {\n types.add(this.qname)\n }\n\n return Array.from(types)\n }\n}\n\nexport function parseMoveType(type: string): TypeDescriptor {\n // type = type.replace('&', '')\n\n type = type.replaceAll('&mut ', '&')\n type = type.replaceAll('mut ', '')\n\n // TODO replace ' ' is not exactly safe, need to double check this\n type = type.replaceAll(' ', '')\n\n const stack: TypeDescriptor[] = [new TypeDescriptor('')]\n let buffer = []\n\n // xxx:asdf<g1<a,<c,d>>, b, g2<a,b>, e>\n for (let i = 0; i < type.length; i++) {\n const ch = type[i]\n if (ch === '<') {\n // const symbol = type.slice(symbolStart, i)\n // symbolStart =\n const symbol = buffer.join('')\n buffer = []\n stack[stack.length - 1].qname = symbol\n stack.push(new TypeDescriptor(''))\n continue\n }\n if (ch === '>') {\n const typeParam = stack.pop()\n if (!typeParam) {\n throw Error('Uxpectecd stack size')\n }\n if (buffer.length > 0) {\n typeParam.qname = buffer.join('')\n buffer = []\n }\n stack[stack.length - 1].typeArgs.push(typeParam)\n continue\n }\n if (ch === ',') {\n const typeParam = stack.pop()\n if (!typeParam) {\n throw Error('Uxpectecd stack size')\n }\n if (buffer.length > 0) {\n typeParam.qname = buffer.join('')\n buffer = []\n }\n\n stack[stack.length - 1].typeArgs.push(typeParam)\n // continue parse next param\n stack.push(new TypeDescriptor(''))\n continue\n }\n\n buffer.push(ch)\n }\n\n if (buffer.length > 0) {\n stack[stack.length - 1].qname = buffer.join('')\n }\n\n const res = stack.pop()\n if (!res || stack.length > 0) {\n throw Error('Uxpectecd stack size')\n }\n return res\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.test.js","sourceRoot":"","sources":["../../src/aptos/types.test.ts"],"names":[],"mappings":";;AAAA,mCAAuC;AACvC,+CAAoD;AAEpD,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,oBAAa,CAAC,SAAS,CAAC,qBAAa,CAAC,CAAA;IACtC,IAAI,CAAC,yBAAyB,EAAE,KAAK,IAAI,EAAE;QACzC,MAAM,OAAO,GAAG,qBAAa,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAA;QACzD,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IACtB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAEF,MAAM,IAAI,GAAG;IACX,IAAI,EAAE,wBAAwB;IAC9B,cAAc,EAAE,EAAE;IAClB,SAAS,EAAE,CAAC,oEAAoE,CAAC;IACjF,IAAI,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;IACtB,QAAQ,EAAE,oCAAoC;CAC/C,CAAA","sourcesContent":["import { TYPE_REGISTRY } from './types'\nimport { aptos_account } from '../builtin/aptos/0x1'\n\ndescribe('type decode', () => {\n aptos_account.loadTypes(TYPE_REGISTRY)\n test('decode function payload', async () => {\n const decoded = TYPE_REGISTRY.decodeFunctionPayload(data)\n console.log(decoded)\n })\n})\n\nconst data = {\n type: 'entry_function_payload',\n type_arguments: [],\n arguments: ['0xaaaf981fec16d967eb79bb51b4c6d39e75acb3482c6dabddb19ca9adbfceee80'],\n code: { bytecode: '' },\n function: '0x1::aptos_account::create_account',\n}\n"]}
1
+ {"version":3,"file":"types.test.js","sourceRoot":"","sources":["../../src/aptos/types.test.ts"],"names":[],"mappings":";;AAAA,mDAA+C;AAC/C,+CAAoD;AAEpD,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,oBAAa,CAAC,SAAS,CAAC,6BAAa,CAAC,CAAA;IACtC,IAAI,CAAC,yBAAyB,EAAE,KAAK,IAAI,EAAE;QACzC,MAAM,OAAO,GAAG,6BAAa,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAA;QACzD,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IACtB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAEF,MAAM,IAAI,GAAG;IACX,IAAI,EAAE,wBAAwB;IAC9B,cAAc,EAAE,EAAE;IAClB,SAAS,EAAE,CAAC,oEAAoE,CAAC;IACjF,IAAI,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;IACtB,QAAQ,EAAE,oCAAoC;CAC/C,CAAA","sourcesContent":["import { TYPE_REGISTRY } from './type-registry'\nimport { aptos_account } from '../builtin/aptos/0x1'\n\ndescribe('type decode', () => {\n aptos_account.loadTypes(TYPE_REGISTRY)\n test('decode function payload', async () => {\n const decoded = TYPE_REGISTRY.decodeFunctionPayload(data)\n console.log(decoded)\n })\n})\n\nconst data = {\n type: 'entry_function_payload',\n type_arguments: [],\n arguments: ['0xaaaf981fec16d967eb79bb51b4c6d39e75acb3482c6dabddb19ca9adbfceee80'],\n code: { bytecode: '' },\n function: '0x1::aptos_account::create_account',\n}\n"]}
@@ -1,9 +1,7 @@
1
1
  import { MoveFunction, MoveModule } from 'aptos-sdk/src/generated';
2
- import { AptosQueryClient } from '../gen/chainquery/protos/chainquery';
3
2
  export declare const SPLITTER = "::";
4
3
  export declare const VECTOR_STR = "vector";
5
4
  export declare function isFrameworkAccount(account: string): boolean;
6
5
  export declare function moduleQname(module: MoveModule): string;
7
6
  export declare function moduleQnameForType(type: string): [string, string];
8
- export declare function getChainQueryClient(address?: string): AptosQueryClient;
9
7
  export declare function getMeaningfulFunctionParams(func: MoveFunction): string[];
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getMeaningfulFunctionParams = exports.getChainQueryClient = exports.moduleQnameForType = exports.moduleQname = exports.isFrameworkAccount = exports.VECTOR_STR = exports.SPLITTER = void 0;
4
- const nice_grpc_1 = require("nice-grpc");
5
- const chainquery_1 = require("../gen/chainquery/protos/chainquery");
3
+ exports.getMeaningfulFunctionParams = exports.moduleQnameForType = exports.moduleQname = exports.isFrameworkAccount = exports.VECTOR_STR = exports.SPLITTER = void 0;
6
4
  exports.SPLITTER = '::';
7
5
  exports.VECTOR_STR = 'vector';
8
6
  function isFrameworkAccount(account) {
@@ -18,11 +16,6 @@ function moduleQnameForType(type) {
18
16
  return [parts[0], parts[1]];
19
17
  }
20
18
  exports.moduleQnameForType = moduleQnameForType;
21
- function getChainQueryClient(address = 'chainquery-server.chain-sync:6809') {
22
- const channel = (0, nice_grpc_1.createChannel)(address);
23
- return (0, nice_grpc_1.createClient)(chainquery_1.AptosQueryDefinition, channel);
24
- }
25
- exports.getChainQueryClient = getChainQueryClient;
26
19
  function getMeaningfulFunctionParams(func) {
27
20
  let params = func.params;
28
21
  if (func.params[0] === '&signer') {
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/aptos/utils.ts"],"names":[],"mappings":";;;AAEA,yCAAuD;AACvD,oEAA4F;AAE/E,QAAA,QAAQ,GAAG,IAAI,CAAA;AAEf,QAAA,UAAU,GAAG,QAAQ,CAAA;AAElC,SAAgB,kBAAkB,CAAC,OAAe;IAChD,OAAO,OAAO,KAAK,KAAK,IAAI,OAAO,KAAK,KAAK,IAAI,OAAO,KAAK,KAAK,CAAA;AACpE,CAAC;AAFD,gDAEC;AAED,SAAgB,WAAW,CAAC,MAAkB;IAC5C,OAAO,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,gBAAQ,GAAG,MAAM,CAAC,IAAI,CAAA;AAC9D,CAAC;AAFD,kCAEC;AAED,SAAgB,kBAAkB,CAAC,IAAY;IAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC9C,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;AAC7B,CAAC;AAHD,gDAGC;AAED,SAAgB,mBAAmB,CAAC,OAAO,GAAG,mCAAmC;IAC/E,MAAM,OAAO,GAAG,IAAA,yBAAa,EAAC,OAAO,CAAC,CAAA;IAEtC,OAAO,IAAA,wBAAY,EAAC,iCAAoB,EAAE,OAAO,CAAC,CAAA;AACpD,CAAC;AAJD,kDAIC;AAED,SAAgB,2BAA2B,CAAC,IAAkB;IAC5D,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;IACxB,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE;QAChC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;KACzB;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAND,kEAMC","sourcesContent":["import { MoveFunction, MoveModule } from 'aptos-sdk/src/generated'\n\nimport { createChannel, createClient } from 'nice-grpc'\nimport { AptosQueryClient, AptosQueryDefinition } from '../gen/chainquery/protos/chainquery'\n\nexport const SPLITTER = '::'\n\nexport const VECTOR_STR = 'vector'\n\nexport function isFrameworkAccount(account: string) {\n return account === '0x1' || account === '0x2' || account === '0x3'\n}\n\nexport function moduleQname(module: MoveModule): string {\n return module.address.toLowerCase() + SPLITTER + module.name\n}\n\nexport function moduleQnameForType(type: string): [string, string] {\n const parts = type.split(SPLITTER).slice(0, 2)\n return [parts[0], parts[1]]\n}\n\nexport function getChainQueryClient(address = 'chainquery-server.chain-sync:6809'): AptosQueryClient {\n const channel = createChannel(address)\n\n return createClient(AptosQueryDefinition, channel)\n}\n\nexport function getMeaningfulFunctionParams(func: MoveFunction): string[] {\n let params = func.params\n if (func.params[0] === '&signer') {\n params = params.slice(1)\n }\n return params\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/aptos/utils.ts"],"names":[],"mappings":";;;AAEa,QAAA,QAAQ,GAAG,IAAI,CAAA;AAEf,QAAA,UAAU,GAAG,QAAQ,CAAA;AAElC,SAAgB,kBAAkB,CAAC,OAAe;IAChD,OAAO,OAAO,KAAK,KAAK,IAAI,OAAO,KAAK,KAAK,IAAI,OAAO,KAAK,KAAK,CAAA;AACpE,CAAC;AAFD,gDAEC;AAED,SAAgB,WAAW,CAAC,MAAkB;IAC5C,OAAO,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,gBAAQ,GAAG,MAAM,CAAC,IAAI,CAAA;AAC9D,CAAC;AAFD,kCAEC;AAED,SAAgB,kBAAkB,CAAC,IAAY;IAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC9C,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;AAC7B,CAAC;AAHD,gDAGC;AAED,SAAgB,2BAA2B,CAAC,IAAkB;IAC5D,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;IACxB,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE;QAChC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;KACzB;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAND,kEAMC","sourcesContent":["import { MoveFunction, MoveModule } from 'aptos-sdk/src/generated'\n\nexport const SPLITTER = '::'\n\nexport const VECTOR_STR = 'vector'\n\nexport function isFrameworkAccount(account: string) {\n return account === '0x1' || account === '0x2' || account === '0x3'\n}\n\nexport function moduleQname(module: MoveModule): string {\n return module.address.toLowerCase() + SPLITTER + module.name\n}\n\nexport function moduleQnameForType(type: string): [string, string] {\n const parts = type.split(SPLITTER).slice(0, 2)\n return [parts[0], parts[1]]\n}\n\nexport function getMeaningfulFunctionParams(func: MoveFunction): string[] {\n let params = func.params\n if (func.params[0] === '&signer') {\n params = params.slice(1)\n }\n return params\n}\n"]}
@@ -11,6 +11,7 @@ const typegen_1 = require("./typegen");
11
11
  const utils_1 = require("../aptos/utils");
12
12
  const chalk_1 = __importDefault(require("chalk"));
13
13
  const network_1 = require("../aptos/network");
14
+ const types_1 = require("../aptos/types");
14
15
  async function generate(srcDir, outputDir) {
15
16
  await generateForNetwork(srcDir, outputDir, network_1.AptosNetwork.MAIN_NET);
16
17
  await generateForNetwork(path_1.default.join(srcDir, 'testnet'), path_1.default.join(outputDir, 'testnet'), network_1.AptosNetwork.TEST_NET);
@@ -313,7 +314,7 @@ function getEventStructs(module) {
313
314
  }
314
315
  for (const struct of module.structs) {
315
316
  for (const field of struct.fields) {
316
- const t = (0, typegen_1.parseMoveType)(field.type);
317
+ const t = (0, types_1.parseMoveType)(field.type);
317
318
  if (t.qname === '0x1::event::EventHandle') {
318
319
  const event = t.typeArgs[0].qname;
319
320
  const eventStruct = structMap.get(event);
@@ -1 +1 @@
1
- {"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../src/aptos-codegen/codegen.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAmB;AACnB,gDAAuB;AACvB,wDAA+B;AAE/B,uCAAkG;AAClG,0CAAuG;AACvG,kDAAyB;AACzB,8CAA2E;AAEpE,KAAK,UAAU,QAAQ,CAAC,MAAc,EAAE,SAAiB;IAC9D,MAAM,kBAAkB,CAAC,MAAM,EAAE,SAAS,EAAE,sBAAY,CAAC,QAAQ,CAAC,CAAA;IAClE,MAAM,kBAAkB,CAAC,cAAI,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,sBAAY,CAAC,QAAQ,CAAC,CAAA;AAChH,CAAC;A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,EAAE,CAAC,CAAA;AAC9E,CAAC","sourcesContent":["import fs from 'fs'\nimport path from 'path'\nimport prettier from 'prettier'\nimport { MoveFunction, MoveModule, MoveModuleBytecode, MoveStruct } from 'aptos-sdk/src/generated'\nimport { AccountModulesImportInfo, AccountRegister, generateType, parseMoveType } from './typegen'\nimport { getMeaningfulFunctionParams, isFrameworkAccount, moduleQname, SPLITTER } from '../aptos/utils'\nimport chalk from 'chalk'\nimport { AptosNetwork, getChainName, getRpcClient } from '../aptos/network'\n\nexport async function generate(srcDir: string, outputDir: string) {\n await generateForNetwork(srcDir, outputDir, AptosNetwork.MAIN_NET)\n await generateForNetwork(path.join(srcDir, 'testnet'), path.join(outputDir, 'testnet'), AptosNetwork.TEST_NET)\n}\n\nexport async function generateForNetwork(srcDir: string, outputDir: string, network: AptosNetwork) {\n if (!fs.existsSync(srcDir)) {\n return\n }\n if (network === AptosNetwork.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 modules = JSON.parse(fs.readFileSync(fullPath, 'utf-8'))\n\n for (const module of modules) {\n if (module.abi) {\n loader.register(module.abi, path.basename(file, '.json'))\n }\n }\n const codeGen = new AccountCodegen(loader, 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 ${getChainName(network)}`)\n\n try {\n const modules = await client.getAccountModules(account)\n fs.writeFileSync(path.resolve(srcDir, account + '.json'), JSON.stringify(modules, null, '\\t'))\n\n for (const module of modules) {\n if (module.abi) {\n loader.register(module.abi, account)\n }\n }\n const codeGen = new AccountCodegen(loader, 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 = prettier.format(output.fileContent, { parser: 'typescript' })\n fs.writeFileSync(path.join(outputDir, output.fileName), content)\n }\n}\n\ninterface OutputFile {\n fileName: string\n fileContent: string\n}\n\ninterface Config {\n fileName: string\n outputDir: string\n network: AptosNetwork\n}\n\nexport class AccountCodegen {\n modules: MoveModuleBytecode[]\n config: Config\n loader: AccountRegister\n\n constructor(loader: AccountRegister, modules: MoveModuleBytecode[], config: Config) {\n // const json = fs.readFileSync(config.srcFile, 'utf-8')\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 if (module.abi && module.abi.address) {\n address = module.abi.address\n }\n }\n if (!address) {\n return []\n }\n\n const imports = `\n import { aptos } from \"@sentio/sdk\"\n import { Address, MoveModule } from \"aptos-sdk/src/generated\"\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 let tsAccountModule = './' + (this.loader.accountImports.get(account)?.moduleName || account)\n if (isFrameworkAccount(account) && !isFrameworkAccount(address)) {\n // Decide where to find runtime library\n let srcRoot = 'lib'\n if (__dirname.includes('sdk/src/aptos-codegen')) {\n srcRoot = 'src'\n }\n tsAccountModule = `@sentio/sdk/${srcRoot}/builtin/aptos/${account}`\n }\n moduleImports.push(`import * as _${account} from \"${tsAccountModule}\"`)\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) => generateModule(m, this.config.network)).join('\\n')}\n \n export function loadAllTypes(_r: aptos.TypeRegistry) {\n ${dependedAccounts.map((a) => `_${a}.loadAllTypes(_r)`).join('\\n')}\n\n ${this.modules\n .map((m) => {\n return `_r.load(${m.abi?.name}.ABI)`\n })\n .join('\\n')}\n }\n ` // source\n\n return [\n {\n fileName: this.config.fileName + '.ts',\n fileContent: source,\n },\n ]\n }\n}\n\nfunction generateNetworkOption(network: AptosNetwork) {\n switch (network) {\n case AptosNetwork.TEST_NET:\n return 'TEST_NET'\n }\n return 'MAIN_NET'\n}\n\nfunction generateModule(moduleByteCode: MoveModuleBytecode, network: AptosNetwork) {\n if (!moduleByteCode.abi) {\n return ''\n }\n const module = moduleByteCode.abi\n\n const functions = module.exposed_functions.map((f) => generateOnEntryFunctions(module, f)).filter((s) => s !== '')\n\n const eventStructs = getEventStructs(module)\n const eventTypes = new Set(eventStructs.keys())\n const events = Array.from(eventStructs.values())\n .map((e) => generateOnEvents(module, e))\n .filter((s) => s !== '')\n const structs = module.structs.map((s) => generateStructs(module, s, eventTypes))\n const callArgs = module.exposed_functions.map((f) => generateCallArgsStructs(module, f))\n\n let processor = ''\n if (functions.length > 0 || events.length > 0) {\n processor = `export class ${module.name} extends aptos.AptosBaseProcessor {\n\n constructor(options: aptos.AptosBindOptions) {\n super(\"${module.name}\", options)\n }\n static DEFAULT_OPTIONS: aptos.AptosBindOptions = {\n address: \"${module.address}\",\n network: aptos.AptosNetwork.${generateNetworkOption(network)} \n }\n\n static bind(options: Partial<aptos.AptosBindOptions> = {}): ${module.name} {\n return new ${module.name}({ ...${module.name}.DEFAULT_OPTIONS, ...options })\n }\n \n ${functions.join('\\n')}\n \n ${events.join('\\n')}\n \n loadTypesInternal(registry: aptos.TypeRegistry) {\n loadAllTypes(registry)\n }\n }\n `\n }\n\n return `\n ${processor}\n\n export namespace ${module.name} {\n ${structs.join('\\n')}\n \n ${callArgs.join('\\n')}\n \n export function loadTypes(_r: aptos.TypeRegistry) {\n loadAllTypes(_r)\n }\n export const ABI: MoveModule = JSON.parse('${JSON.stringify(module)}')\n }\n `\n}\n\nfunction generateStructs(module: MoveModule, struct: MoveStruct, events: Set<string>) {\n const genericString = generateStructTypeParameters(struct)\n const genericStringAny = generateStructTypeParameters(struct, true)\n\n const fields = struct.fields.map((field) => {\n return `${field.name}: ${generateType(field.type, module.address)}`\n })\n\n let eventPayload = ''\n if (events.has(moduleQname(module) + SPLITTER + struct.name)) {\n eventPayload = `\n export interface ${struct.name}Instance extends \n aptos.TypedEventInstance<${struct.name}${genericStringAny}> {\n data_typed: ${struct.name}${genericStringAny}\n type_arguments: [${struct.generic_type_params.map((_) => 'string').join(', ')}]\n }\n `\n }\n\n return `\n export class ${struct.name}${genericString} {\n static TYPE_QNAME = '${module.address}::${module.name}::${struct.name}'\n ${fields.join('\\n')} \n }\n \n ${eventPayload}\n `\n}\n\nfunction generateFunctionTypeParameters(func: MoveFunction) {\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\nfunction generateStructTypeParameters(struct: MoveStruct, 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\nfunction generateCallArgsStructs(module: MoveModule, func: MoveFunction) {\n if (!func.is_entry) {\n return\n }\n\n const fields = getMeaningfulFunctionParams(func).map((param) => {\n return `${generateType(param, module.address)}`\n })\n\n const camelFuncName = capitalizeFirstChar(camelize(func.name))\n\n const genericString = generateFunctionTypeParameters(func)\n return `\n export interface ${camelFuncName}Payload${genericString}\n extends aptos.TypedEntryFunctionPayload<[${fields.join(',')}]> {\n arguments_typed: [${fields.join(',')}],\n type_arguments: [${func.generic_type_params.map((_) => 'string').join(', ')}]\n }\n `\n}\n\nfunction generateOnEntryFunctions(module: MoveModule, func: MoveFunction) {\n if (!func.is_entry) {\n return ''\n }\n\n // const genericString = generateFunctionTypeParameters(func)\n\n const camelFuncName = capitalizeFirstChar(camelize(func.name))\n const source = `\n onEntry${camelFuncName}(func: (call: ${module.name}.${camelFuncName}Payload, ctx: aptos.AptosContext) => void, filter?: aptos.CallFilter): ${module.name} {\n this.onEntryFunctionCall(func, {\n ...filter,\n function: '${module.name}::${func.name}'\n })\n return this\n }`\n\n return source\n}\n\nfunction getEventStructs(module: MoveModule) {\n const qname = moduleQname(module)\n const structMap = new Map<string, MoveStruct>()\n const eventMap = new Map<string, MoveStruct>()\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 = parseMoveType(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\nfunction generateOnEvents(module: MoveModule, struct: MoveStruct): 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 source = `\n onEvent${struct.name}(func: (event: ${module.name}.${struct.name}Instance, ctx: aptos.AptosContext) => void): ${module.name} {\n this.onEvent(func, {\n type: '${module.name}::${struct.name}'\n })\n return this\n }\n `\n return source\n}\n\nfunction camelize(input: string): string {\n return input\n .split('_')\n .reduce(\n (res, word, i) =>\n i === 0 ? word.toLowerCase() : `${res}${word.charAt(0).toUpperCase()}${word.substr(1).toLowerCase()}`,\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":"codegen.js","sourceRoot":"","sources":["../../src/aptos-codegen/codegen.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAmB;AACnB,gDAAuB;AACvB,wDAA+B;AAE/B,uCAAmF;AACnF,0CAAuG;AACvG,kDAAyB;AACzB,8CAA2E;AAC3E,0CAA8C;AAEvC,KAAK,UAAU,QAAQ,CAAC,MAAc,EAAE,SAAiB;IAC9D,MAAM,kBAAkB,CAAC,MAAM,EAAE,SAAS,EAAE,sBAAY,CAAC,QAAQ,CAAC,CAAA;IAClE,MAAM,kBAAkB,CAAC,cAAI,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,sBAAY,CAAC,QAAQ,CAAC,CAAA;AAChH,CAAC;AAHD,4BAGC;AAEM,KAAK,UAAU,kBAAkB,CAAC,MAAc,EAAE,SAAiB,EAAE,OAAqB;IAC/F,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;QAC1B,OAAM;KACP;IACD,IAAI,OAAO,KAAK,sBAAY,CAAC,QAAQ,EAAE;QACrC,OAAO,CAAC,GAAG,CAAC,4DAA4D,CAAC,CAAA;KAC1E;IACD,MAAM,KAAK,GAAG,YAAE,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IACpC,SAAS,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;IACnC,MAAM,OAAO,GAAiB,EAAE,CAAA;IAEhC,YAAE,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IAE5C,MAAM,MA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I;;;;GAIvC,CAAA;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED,SAAS,QAAQ,CAAC,KAAa;IAC7B,OAAO,KAAK;SACT,KAAK,CAAC,GAAG,CAAC;SACV,MAAM,CACL,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,CACf,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,EAAE,EACvG,EAAE,CACH,CAAA;AACL,CAAC;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 fs from 'fs'\nimport path from 'path'\nimport prettier from 'prettier'\nimport { MoveFunction, MoveModule, MoveModuleBytecode, MoveStruct } from 'aptos-sdk/src/generated'\nimport { AccountModulesImportInfo, AccountRegister, generateType } from './typegen'\nimport { getMeaningfulFunctionParams, isFrameworkAccount, moduleQname, SPLITTER } from '../aptos/utils'\nimport chalk from 'chalk'\nimport { AptosNetwork, getChainName, getRpcClient } from '../aptos/network'\nimport { parseMoveType } from '../aptos/types'\n\nexport async function generate(srcDir: string, outputDir: string) {\n await generateForNetwork(srcDir, outputDir, AptosNetwork.MAIN_NET)\n await generateForNetwork(path.join(srcDir, 'testnet'), path.join(outputDir, 'testnet'), AptosNetwork.TEST_NET)\n}\n\nexport async function generateForNetwork(srcDir: string, outputDir: string, network: AptosNetwork) {\n if (!fs.existsSync(srcDir)) {\n return\n }\n if (network === AptosNetwork.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 modules = JSON.parse(fs.readFileSync(fullPath, 'utf-8'))\n\n for (const module of modules) {\n if (module.abi) {\n loader.register(module.abi, path.basename(file, '.json'))\n }\n }\n const codeGen = new AccountCodegen(loader, 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 ${getChainName(network)}`)\n\n try {\n const modules = await client.getAccountModules(account)\n fs.writeFileSync(path.resolve(srcDir, account + '.json'), JSON.stringify(modules, null, '\\t'))\n\n for (const module of modules) {\n if (module.abi) {\n loader.register(module.abi, account)\n }\n }\n const codeGen = new AccountCodegen(loader, 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 = prettier.format(output.fileContent, { parser: 'typescript' })\n fs.writeFileSync(path.join(outputDir, output.fileName), content)\n }\n}\n\ninterface OutputFile {\n fileName: string\n fileContent: string\n}\n\ninterface Config {\n fileName: string\n outputDir: string\n network: AptosNetwork\n}\n\nexport class AccountCodegen {\n modules: MoveModuleBytecode[]\n config: Config\n loader: AccountRegister\n\n constructor(loader: AccountRegister, modules: MoveModuleBytecode[], config: Config) {\n // const json = fs.readFileSync(config.srcFile, 'utf-8')\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 if (module.abi && module.abi.address) {\n address = module.abi.address\n }\n }\n if (!address) {\n return []\n }\n\n const imports = `\n import { aptos } from \"@sentio/sdk\"\n import { Address, MoveModule } from \"aptos-sdk/src/generated\"\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 let tsAccountModule = './' + (this.loader.accountImports.get(account)?.moduleName || account)\n if (isFrameworkAccount(account) && !isFrameworkAccount(address)) {\n // Decide where to find runtime library\n let srcRoot = 'lib'\n if (__dirname.includes('sdk/src/aptos-codegen')) {\n srcRoot = 'src'\n }\n tsAccountModule = `@sentio/sdk/${srcRoot}/builtin/aptos/${account}`\n }\n moduleImports.push(`import * as _${account} from \"${tsAccountModule}\"`)\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) => generateModule(m, this.config.network)).join('\\n')}\n \n export function loadAllTypes(_r: aptos.TypeRegistry) {\n ${dependedAccounts.map((a) => `_${a}.loadAllTypes(_r)`).join('\\n')}\n\n ${this.modules\n .map((m) => {\n return `_r.load(${m.abi?.name}.ABI)`\n })\n .join('\\n')}\n }\n ` // source\n\n return [\n {\n fileName: this.config.fileName + '.ts',\n fileContent: source,\n },\n ]\n }\n}\n\nfunction generateNetworkOption(network: AptosNetwork) {\n switch (network) {\n case AptosNetwork.TEST_NET:\n return 'TEST_NET'\n }\n return 'MAIN_NET'\n}\n\nfunction generateModule(moduleByteCode: MoveModuleBytecode, network: AptosNetwork) {\n if (!moduleByteCode.abi) {\n return ''\n }\n const module = moduleByteCode.abi\n\n const functions = module.exposed_functions.map((f) => generateOnEntryFunctions(module, f)).filter((s) => s !== '')\n\n const eventStructs = getEventStructs(module)\n const eventTypes = new Set(eventStructs.keys())\n const events = Array.from(eventStructs.values())\n .map((e) => generateOnEvents(module, e))\n .filter((s) => s !== '')\n const structs = module.structs.map((s) => generateStructs(module, s, eventTypes))\n const callArgs = module.exposed_functions.map((f) => generateCallArgsStructs(module, f))\n\n let processor = ''\n if (functions.length > 0 || events.length > 0) {\n processor = `export class ${module.name} extends aptos.AptosBaseProcessor {\n\n constructor(options: aptos.AptosBindOptions) {\n super(\"${module.name}\", options)\n }\n static DEFAULT_OPTIONS: aptos.AptosBindOptions = {\n address: \"${module.address}\",\n network: aptos.AptosNetwork.${generateNetworkOption(network)} \n }\n\n static bind(options: Partial<aptos.AptosBindOptions> = {}): ${module.name} {\n return new ${module.name}({ ...${module.name}.DEFAULT_OPTIONS, ...options })\n }\n \n ${functions.join('\\n')}\n \n ${events.join('\\n')}\n \n loadTypesInternal(registry: aptos.TypeRegistry) {\n loadAllTypes(registry)\n }\n }\n `\n }\n\n return `\n ${processor}\n\n export namespace ${module.name} {\n ${structs.join('\\n')}\n \n ${callArgs.join('\\n')}\n \n export function loadTypes(_r: aptos.TypeRegistry) {\n loadAllTypes(_r)\n }\n export const ABI: MoveModule = JSON.parse('${JSON.stringify(module)}')\n }\n `\n}\n\nfunction generateStructs(module: MoveModule, struct: MoveStruct, events: Set<string>) {\n const genericString = generateStructTypeParameters(struct)\n const genericStringAny = generateStructTypeParameters(struct, true)\n\n const fields = struct.fields.map((field) => {\n return `${field.name}: ${generateType(field.type, module.address)}`\n })\n\n let eventPayload = ''\n if (events.has(moduleQname(module) + SPLITTER + struct.name)) {\n eventPayload = `\n export interface ${struct.name}Instance extends \n aptos.TypedEventInstance<${struct.name}${genericStringAny}> {\n data_typed: ${struct.name}${genericStringAny}\n type_arguments: [${struct.generic_type_params.map((_) => 'string').join(', ')}]\n }\n `\n }\n\n return `\n export class ${struct.name}${genericString} {\n static TYPE_QNAME = '${module.address}::${module.name}::${struct.name}'\n ${fields.join('\\n')} \n }\n \n ${eventPayload}\n `\n}\n\nfunction generateFunctionTypeParameters(func: MoveFunction) {\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\nfunction generateStructTypeParameters(struct: MoveStruct, 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\nfunction generateCallArgsStructs(module: MoveModule, func: MoveFunction) {\n if (!func.is_entry) {\n return\n }\n\n const fields = getMeaningfulFunctionParams(func).map((param) => {\n return `${generateType(param, module.address)}`\n })\n\n const camelFuncName = capitalizeFirstChar(camelize(func.name))\n\n const genericString = generateFunctionTypeParameters(func)\n return `\n export interface ${camelFuncName}Payload${genericString}\n extends aptos.TypedEntryFunctionPayload<[${fields.join(',')}]> {\n arguments_typed: [${fields.join(',')}],\n type_arguments: [${func.generic_type_params.map((_) => 'string').join(', ')}]\n }\n `\n}\n\nfunction generateOnEntryFunctions(module: MoveModule, func: MoveFunction) {\n if (!func.is_entry) {\n return ''\n }\n\n // const genericString = generateFunctionTypeParameters(func)\n\n const camelFuncName = capitalizeFirstChar(camelize(func.name))\n const source = `\n onEntry${camelFuncName}(func: (call: ${module.name}.${camelFuncName}Payload, ctx: aptos.AptosContext) => void, filter?: aptos.CallFilter): ${module.name} {\n this.onEntryFunctionCall(func, {\n ...filter,\n function: '${module.name}::${func.name}'\n })\n return this\n }`\n\n return source\n}\n\nfunction getEventStructs(module: MoveModule) {\n const qname = moduleQname(module)\n const structMap = new Map<string, MoveStruct>()\n const eventMap = new Map<string, MoveStruct>()\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 = parseMoveType(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\nfunction generateOnEvents(module: MoveModule, struct: MoveStruct): 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 source = `\n onEvent${struct.name}(func: (event: ${module.name}.${struct.name}Instance, ctx: aptos.AptosContext) => void): ${module.name} {\n this.onEvent(func, {\n type: '${module.name}::${struct.name}'\n })\n return this\n }\n `\n return source\n}\n\nfunction camelize(input: string): string {\n return input\n .split('_')\n .reduce(\n (res, word, i) =>\n i === 0 ? word.toLowerCase() : `${res}${word.charAt(0).toUpperCase()}${word.substr(1).toLowerCase()}`,\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,6 +1,5 @@
1
1
  import { MoveModule } from 'aptos-sdk/src/generated';
2
2
  import { TypeDescriptor } from '../aptos/types';
3
- export declare function parseMoveType(type: string): TypeDescriptor;
4
3
  export declare function generateType(type: string, currentAddress: string): string;
5
4
  export declare class AccountModulesImportInfo {
6
5
  imports: Map<string, Set<string>>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AccountRegister = exports.AccountModulesImportInfo = exports.generateType = exports.parseMoveType = void 0;
3
+ exports.AccountRegister = exports.AccountModulesImportInfo = exports.generateType = void 0;
4
4
  const types_1 = require("../aptos/types");
5
5
  const utils_1 = require("../aptos/utils");
6
6
  function generateTypeForDescriptor(type, currentAddress) {
@@ -58,67 +58,9 @@ function generateSimpleType(type, currentAddress) {
58
58
  }
59
59
  return '_' + parts.join('.');
60
60
  }
61
- function parseMoveType(type) {
62
- // type = type.replace('&', '')
63
- type = type.replaceAll('&mut ', '&');
64
- type = type.replaceAll('mut ', '');
65
- // TODO replace ' ' is not exactly safe, need to double check this
66
- type = type.replaceAll(' ', '');
67
- const stack = [new types_1.TypeDescriptor('')];
68
- let buffer = [];
69
- // xxx:asdf<g1<a,<c,d>>, b, g2<a,b>, e>
70
- for (let i = 0; i < type.length; i++) {
71
- const ch = type[i];
72
- if (ch === '<') {
73
- // const symbol = type.slice(symbolStart, i)
74
- // symbolStart =
75
- const symbol = buffer.join('');
76
- buffer = [];
77
- stack[stack.length - 1].qname = symbol;
78
- stack.push(new types_1.TypeDescriptor(''));
79
- continue;
80
- }
81
- if (ch === '>') {
82
- const typeParam = stack.pop();
83
- if (!typeParam) {
84
- throw Error('Uxpectecd stack size');
85
- }
86
- if (buffer.length > 0) {
87
- typeParam.qname = buffer.join('');
88
- buffer = [];
89
- }
90
- stack[stack.length - 1].typeArgs.push(typeParam);
91
- continue;
92
- }
93
- if (ch === ',') {
94
- const typeParam = stack.pop();
95
- if (!typeParam) {
96
- throw Error('Uxpectecd stack size');
97
- }
98
- if (buffer.length > 0) {
99
- typeParam.qname = buffer.join('');
100
- buffer = [];
101
- }
102
- stack[stack.length - 1].typeArgs.push(typeParam);
103
- // continue parse next param
104
- stack.push(new types_1.TypeDescriptor(''));
105
- continue;
106
- }
107
- buffer.push(ch);
108
- }
109
- if (buffer.length > 0) {
110
- stack[stack.length - 1].qname = buffer.join('');
111
- }
112
- const res = stack.pop();
113
- if (!res || stack.length > 0) {
114
- throw Error('Uxpectecd stack size');
115
- }
116
- return res;
117
- }
118
- exports.parseMoveType = parseMoveType;
119
61
  // TODO ctx need to have type parameters
120
62
  function generateType(type, currentAddress) {
121
- return generateTypeForDescriptor(parseMoveType(type), currentAddress);
63
+ return generateTypeForDescriptor((0, types_1.parseMoveType)(type), currentAddress);
122
64
  }
123
65
  exports.generateType = generateType;
124
66
  class AccountModulesImportInfo {
@@ -153,7 +95,7 @@ class AccountRegister {
153
95
  let descriptor = this.typeRegistry.get(type);
154
96
  // const descriptparseMoveType(type)
155
97
  if (!descriptor) {
156
- descriptor = parseMoveType(type);
98
+ descriptor = (0, types_1.parseMoveType)(type);
157
99
  this.typeRegistry.set(type, descriptor);
158
100
  }
159
101
  return descriptor;
@@ -1 +1 @@
1
- {"version":3,"file":"typegen.js","sourceRoot":"","sources":["../../src/aptos-codegen/typegen.ts"],"names":[],"mappings":";;;AACA,0CAA+C;AAC/C,0CAAsF;AAEtF,SAAS,yBAAyB,CAAC,IAAoB,EAAE,cAAsB;IAC7E,iEAAiE;IACjE,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QAC9B,OAAO,SAAS,CAAA;KACjB;IAED,QAAQ,IAAI,CAAC,KAAK,EAAE;QAClB,KAAK,QAAQ,CAAC,CAAC,kBAAkB;QACjC,KAAK,SAAS;YACZ,OAAO,SAAS,CAAA;QAClB,KAAK,qBAAqB;YACxB,OAAO,QAAQ,CAAA;QACjB,KAAK,MAAM;YACT,OAAO,SAAS,CAAA;QAClB,KAAK,IAAI,CAAC;QACV,KAAK,KAAK,CAAC;QACX,KAAK,KAAK;YACR,OAAO,QAAQ,CAAA;QACjB,KAAK,KAAK,CAAC;QACX,KAAK,MAAM;YACT,OAAO,QAAQ,CAAA;KAClB;IAED,IAAI,IAAI,CAAC,KAAK,KAAK,kBAAU,EAAE;QAC7B,2BAA2B;QAC3B,MAAM,gBAAgB,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;QAC/C,IAAI,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IAAI,IAAI,CAAC,MAAM,EAAE;gBAC/B,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,aAAa,EAAE,EAAE;oBACjE,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,IAAA,0BAAkB,EAAC,IAAI,CAAC,CAAA;oBAClD,oBAAoB,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;oBAC/C,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;wBACrC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;qBAClC;iBACF;aACF;SACF;QACD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,gBAAgB,EAAE,oBAAoB,CAAC,CAAA;QAC/D,OAAO,oBAAoB,CAAA;IAC7B,CAAC;CACF;AA1DD,0CA0DC","sourcesContent":["import { MoveModule } from 'aptos-sdk/src/generated'\nimport { TypeDescriptor } from '../aptos/types'\nimport { moduleQname, moduleQnameForType, SPLITTER, VECTOR_STR } from '../aptos/utils'\n\nfunction generateTypeForDescriptor(type: TypeDescriptor, currentAddress: string): string {\n // TODO &signer is defintely an address, but what if &OTHER_TYPE?\n if (type.qname.startsWith('&')) {\n return 'Address'\n }\n\n switch (type.qname) {\n case 'signer': // TODO check this\n case 'address':\n return 'Address'\n case '0x1::string::String':\n return 'string'\n case 'bool':\n return 'Boolean'\n case 'u8':\n case 'u16':\n case 'u32':\n return 'number'\n case 'u64':\n case 'u128':\n return 'bigint'\n }\n\n if (type.qname === VECTOR_STR) {\n // vector<u8> as hex string\n const elementTypeQname = type.typeArgs[0].qname\n if (elementTypeQname === 'u8') {\n return 'string'\n }\n if (elementTypeQname.startsWith('T') && !elementTypeQname.includes(SPLITTER)) {\n return `${elementTypeQname}[] | string`\n }\n return generateTypeForDescriptor(type.typeArgs[0], currentAddress) + '[]'\n }\n\n const simpleName = generateSimpleType(type.qname, currentAddress)\n if (simpleName.length === 0) {\n console.error('unexpected error')\n }\n if (simpleName.includes('vector')) {\n console.error('unexpected error')\n }\n if (type.typeArgs.length > 0) {\n // return simpleName\n return simpleName + '<' + type.typeArgs.map((t) => generateTypeForDescriptor(t, currentAddress)).join(',') + '>'\n }\n return simpleName\n}\n\nfunction generateSimpleType(type: string, currentAddress: string): string {\n const parts = type.split(SPLITTER)\n if (parts.length < 2) {\n return parts[0]\n }\n if (parts[0] === currentAddress) {\n return parts.slice(1).join('.')\n }\n return '_' + parts.join('.')\n}\n\nexport function parseMoveType(type: string): TypeDescriptor {\n // type = type.replace('&', '')\n\n type = type.replaceAll('&mut ', '&')\n type = type.replaceAll('mut ', '')\n\n // TODO replace ' ' is not exactly safe, need to double check this\n type = type.replaceAll(' ', '')\n\n const stack: TypeDescriptor[] = [new TypeDescriptor('')]\n let buffer = []\n\n // xxx:asdf<g1<a,<c,d>>, b, g2<a,b>, e>\n for (let i = 0; i < type.length; i++) {\n const ch = type[i]\n if (ch === '<') {\n // const symbol = type.slice(symbolStart, i)\n // symbolStart =\n const symbol = buffer.join('')\n buffer = []\n stack[stack.length - 1].qname = symbol\n stack.push(new TypeDescriptor(''))\n continue\n }\n if (ch === '>') {\n const typeParam = stack.pop()\n if (!typeParam) {\n throw Error('Uxpectecd stack size')\n }\n if (buffer.length > 0) {\n typeParam.qname = buffer.join('')\n buffer = []\n }\n stack[stack.length - 1].typeArgs.push(typeParam)\n continue\n }\n if (ch === ',') {\n const typeParam = stack.pop()\n if (!typeParam) {\n throw Error('Uxpectecd stack size')\n }\n if (buffer.length > 0) {\n typeParam.qname = buffer.join('')\n buffer = []\n }\n\n stack[stack.length - 1].typeArgs.push(typeParam)\n // continue parse next param\n stack.push(new TypeDescriptor(''))\n continue\n }\n\n buffer.push(ch)\n }\n\n if (buffer.length > 0) {\n stack[stack.length - 1].qname = buffer.join('')\n }\n\n const res = stack.pop()\n if (!res || stack.length > 0) {\n throw Error('Uxpectecd stack size')\n }\n return res\n}\n\n// TODO ctx need to have type parameters\nexport function generateType(type: string, currentAddress: string): string {\n return generateTypeForDescriptor(parseMoveType(type), currentAddress)\n}\n\nexport class AccountModulesImportInfo {\n // account to module\n imports: Map<string, Set<string>>\n account: string\n moduleName: string\n\n constructor(account: string, tsModuleName: string) {\n this.account = account\n this.moduleName = tsModuleName\n this.imports = new Map<string, Set<string>>()\n }\n\n addImport(account: string, module: string) {\n if (account === this.account) {\n return\n }\n let accountModules = this.imports.get(account)\n if (!accountModules) {\n accountModules = new Set<string>()\n this.imports.set(account, accountModules)\n }\n accountModules.add(module)\n }\n}\n\nexport class AccountRegister {\n accountImports = new Map<string, AccountModulesImportInfo>()\n pendingAccounts = new Set<string>()\n\n // loadedAccount = new Set<string>()\n typeRegistry = new Map<string, TypeDescriptor>()\n\n private loadTypeDescriptor(type: string) {\n let descriptor = this.typeRegistry.get(type)\n\n // const descriptparseMoveType(type)\n if (!descriptor) {\n descriptor = parseMoveType(type)\n this.typeRegistry.set(type, descriptor)\n }\n return descriptor\n }\n\n register(module: MoveModule, tsModuleName: string): AccountModulesImportInfo {\n const currentModuleFqn = moduleQname(module)\n\n let accountModuleImports = this.accountImports.get(module.address)\n if (!accountModuleImports) {\n accountModuleImports = new AccountModulesImportInfo(module.address, tsModuleName)\n this.accountImports.set(module.address, accountModuleImports)\n // the account has already be processed, delete pending task\n this.pendingAccounts.delete(module.address)\n }\n\n for (const struct of module.structs) {\n for (const field of struct.fields) {\n for (const type of this.loadTypeDescriptor(field.type).dependedTypes()) {\n const [account, module] = moduleQnameForType(type)\n accountModuleImports.addImport(account, module)\n if (!this.accountImports.has(account)) {\n this.pendingAccounts.add(account)\n }\n }\n }\n }\n\n for (const func of module.exposed_functions) {\n if (!func.is_entry) {\n continue\n }\n for (const param of func.params) {\n for (const type of this.loadTypeDescriptor(param).dependedTypes()) {\n const [account, module] = moduleQnameForType(type)\n accountModuleImports.addImport(account, module)\n if (!this.accountImports.has(account)) {\n this.pendingAccounts.add(account)\n }\n }\n }\n }\n this.accountImports.set(currentModuleFqn, accountModuleImports)\n return accountModuleImports\n }\n}\n"]}
1
+ {"version":3,"file":"typegen.js","sourceRoot":"","sources":["../../src/aptos-codegen/typegen.ts"],"names":[],"mappings":";;;AACA,0CAA8D;AAC9D,0CAAsF;AAEtF,SAAS,yBAAyB,CAAC,IAAoB,EAAE,cAAsB;IAC7E,iEAAiE;IACjE,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QAC9B,OAAO,SAAS,CAAA;KACjB;IAED,QAAQ,IAAI,CAAC,KAAK,EAAE;QAClB,KAAK,QAAQ,CAAC,CAAC,kBAAkB;QACjC,KAAK,SAAS;YACZ,OAAO,SAAS,CAAA;QAClB,KAAK,qBAAqB;YACxB,OAAO,QAAQ,CAAA;QACjB,KAAK,MAAM;YACT,OAAO,SAAS,CAAA;QAClB,KAAK,IAAI,CAAC;QACV,KAAK,KAAK,CAAC;QACX,KAAK,KAAK;YACR,OAAO,QAAQ,CAAA;QACjB,KAAK,KAAK,CAAC;QACX,KAAK,MAAM;YACT,OAAO,QAAQ,CAAA;KAClB;IAED,IAAI,IAAI,CAAC,KAAK,KAAK,kBAAU,EAAE;QAC7B,2BAA2B;QAC3B,MAAM,gBAAgB,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;QAC/C,IAAI,gBAAgB,KAAK,IAAI,EAAE;YAC7B,OAAO,QAAQ,CAAA;SAChB;QACD,IAAI,gBAAgB,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,gBAAQ,CAAC,EAAE;YAC5E,OAAO,GAAG,gBAAgB,aAAa,CAAA;SACxC;QACD,OAAO,yBAAyB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,cAAc,CAAC,GAAG,IAAI,CAAA;KAC1E;IAED,MAAM,UAAU,GAAG,kBAAkB,CAAC,IAAI,CA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AAC,CAAA;oBAClD,oBAAoB,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;oBAC/C,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;wBACrC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;qBAClC;iBACF;aACF;SACF;QACD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,gBAAgB,EAAE,oBAAoB,CAAC,CAAA;QAC/D,OAAO,oBAAoB,CAAA;IAC7B,CAAC;CACF;AA1DD,0CA0DC","sourcesContent":["import { MoveModule } from 'aptos-sdk/src/generated'\nimport { parseMoveType, TypeDescriptor } from '../aptos/types'\nimport { moduleQname, moduleQnameForType, SPLITTER, VECTOR_STR } from '../aptos/utils'\n\nfunction generateTypeForDescriptor(type: TypeDescriptor, currentAddress: string): string {\n // TODO &signer is defintely an address, but what if &OTHER_TYPE?\n if (type.qname.startsWith('&')) {\n return 'Address'\n }\n\n switch (type.qname) {\n case 'signer': // TODO check this\n case 'address':\n return 'Address'\n case '0x1::string::String':\n return 'string'\n case 'bool':\n return 'Boolean'\n case 'u8':\n case 'u16':\n case 'u32':\n return 'number'\n case 'u64':\n case 'u128':\n return 'bigint'\n }\n\n if (type.qname === VECTOR_STR) {\n // vector<u8> as hex string\n const elementTypeQname = type.typeArgs[0].qname\n if (elementTypeQname === 'u8') {\n return 'string'\n }\n if (elementTypeQname.startsWith('T') && !elementTypeQname.includes(SPLITTER)) {\n return `${elementTypeQname}[] | string`\n }\n return generateTypeForDescriptor(type.typeArgs[0], currentAddress) + '[]'\n }\n\n const simpleName = generateSimpleType(type.qname, currentAddress)\n if (simpleName.length === 0) {\n console.error('unexpected error')\n }\n if (simpleName.includes('vector')) {\n console.error('unexpected error')\n }\n if (type.typeArgs.length > 0) {\n // return simpleName\n return simpleName + '<' + type.typeArgs.map((t) => generateTypeForDescriptor(t, currentAddress)).join(',') + '>'\n }\n return simpleName\n}\n\nfunction generateSimpleType(type: string, currentAddress: string): string {\n const parts = type.split(SPLITTER)\n if (parts.length < 2) {\n return parts[0]\n }\n if (parts[0] === currentAddress) {\n return parts.slice(1).join('.')\n }\n return '_' + parts.join('.')\n}\n\n// TODO ctx need to have type parameters\nexport function generateType(type: string, currentAddress: string): string {\n return generateTypeForDescriptor(parseMoveType(type), currentAddress)\n}\n\nexport class AccountModulesImportInfo {\n // account to module\n imports: Map<string, Set<string>>\n account: string\n moduleName: string\n\n constructor(account: string, tsModuleName: string) {\n this.account = account\n this.moduleName = tsModuleName\n this.imports = new Map<string, Set<string>>()\n }\n\n addImport(account: string, module: string) {\n if (account === this.account) {\n return\n }\n let accountModules = this.imports.get(account)\n if (!accountModules) {\n accountModules = new Set<string>()\n this.imports.set(account, accountModules)\n }\n accountModules.add(module)\n }\n}\n\nexport class AccountRegister {\n accountImports = new Map<string, AccountModulesImportInfo>()\n pendingAccounts = new Set<string>()\n\n // loadedAccount = new Set<string>()\n typeRegistry = new Map<string, TypeDescriptor>()\n\n private loadTypeDescriptor(type: string) {\n let descriptor = this.typeRegistry.get(type)\n\n // const descriptparseMoveType(type)\n if (!descriptor) {\n descriptor = parseMoveType(type)\n this.typeRegistry.set(type, descriptor)\n }\n return descriptor\n }\n\n register(module: MoveModule, tsModuleName: string): AccountModulesImportInfo {\n const currentModuleFqn = moduleQname(module)\n\n let accountModuleImports = this.accountImports.get(module.address)\n if (!accountModuleImports) {\n accountModuleImports = new AccountModulesImportInfo(module.address, tsModuleName)\n this.accountImports.set(module.address, accountModuleImports)\n // the account has already be processed, delete pending task\n this.pendingAccounts.delete(module.address)\n }\n\n for (const struct of module.structs) {\n for (const field of struct.fields) {\n for (const type of this.loadTypeDescriptor(field.type).dependedTypes()) {\n const [account, module] = moduleQnameForType(type)\n accountModuleImports.addImport(account, module)\n if (!this.accountImports.has(account)) {\n this.pendingAccounts.add(account)\n }\n }\n }\n }\n\n for (const func of module.exposed_functions) {\n if (!func.is_entry) {\n continue\n }\n for (const param of func.params) {\n for (const type of this.loadTypeDescriptor(param).dependedTypes()) {\n const [account, module] = moduleQnameForType(type)\n accountModuleImports.addImport(account, module)\n if (!this.accountImports.has(account)) {\n this.pendingAccounts.add(account)\n }\n }\n }\n }\n this.accountImports.set(currentModuleFqn, accountModuleImports)\n return accountModuleImports\n }\n}\n"]}