@sentio/sdk 1.37.0-rc.2 → 1.37.0-rc.3
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.
- package/lib/builtin/index.d.ts +0 -2
- package/lib/builtin/index.js +1 -3
- package/lib/builtin/index.js.map +1 -1
- package/lib/core/eth-plugin.js +12 -15
- package/lib/core/eth-plugin.js.map +1 -1
- package/lib/core/index.d.ts +0 -4
- package/lib/core/index.js +1 -9
- package/lib/core/index.js.map +1 -1
- package/lib/core/sui-plugin.js +1 -1
- package/lib/core/sui-plugin.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +3 -14
- package/lib/index.js.map +1 -1
- package/lib/service.d.ts +0 -4
- package/lib/service.js +40 -71
- package/lib/service.js.map +1 -1
- package/package.json +5 -16
- package/src/builtin/index.ts +1 -4
- package/src/core/eth-plugin.ts +5 -8
- package/src/core/index.ts +0 -5
- package/src/core/sui-plugin.ts +2 -2
- package/src/index.ts +3 -1
- package/src/service.ts +13 -71
- package/lib/aptos/api.d.ts +0 -2
- package/lib/aptos/api.js +0 -14
- package/lib/aptos/api.js.map +0 -1
- package/lib/aptos/aptos-plugin.d.ts +0 -14
- package/lib/aptos/aptos-plugin.js +0 -185
- package/lib/aptos/aptos-plugin.js.map +0 -1
- package/lib/aptos/aptos-processor.d.ts +0 -75
- package/lib/aptos/aptos-processor.js +0 -193
- package/lib/aptos/aptos-processor.js.map +0 -1
- package/lib/aptos/context.d.ts +0 -22
- package/lib/aptos/context.js +0 -65
- package/lib/aptos/context.js.map +0 -1
- package/lib/aptos/index.d.ts +0 -9
- package/lib/aptos/index.js +0 -34
- package/lib/aptos/index.js.map +0 -1
- package/lib/aptos/models.d.ts +0 -23
- package/lib/aptos/models.js +0 -3
- package/lib/aptos/models.js.map +0 -1
- package/lib/aptos/network.d.ts +0 -14
- package/lib/aptos/network.js +0 -46
- package/lib/aptos/network.js.map +0 -1
- package/lib/aptos/runtime.d.ts +0 -2
- package/lib/aptos/runtime.js +0 -16
- package/lib/aptos/runtime.js.map +0 -1
- package/lib/aptos/type-registry.d.ts +0 -21
- package/lib/aptos/type-registry.js +0 -156
- package/lib/aptos/type-registry.js.map +0 -1
- package/lib/aptos/types.d.ts +0 -9
- package/lib/aptos/types.js +0 -135
- package/lib/aptos/types.js.map +0 -1
- package/lib/aptos/types.test.d.ts +0 -1
- package/lib/aptos/types.test.js.map +0 -1
- package/lib/aptos/utils.d.ts +0 -7
- package/lib/aptos/utils.js +0 -27
- package/lib/aptos/utils.js.map +0 -1
- package/lib/aptos-codegen/codegen.d.ts +0 -23
- package/lib/aptos-codegen/codegen.js +0 -364
- package/lib/aptos-codegen/codegen.js.map +0 -1
- package/lib/aptos-codegen/typegen.d.ts +0 -17
- package/lib/aptos-codegen/typegen.js +0 -142
- package/lib/aptos-codegen/typegen.js.map +0 -1
- package/lib/builtin/aptos/0x1.d.ts +0 -1913
- package/lib/builtin/aptos/0x1.js +0 -2748
- package/lib/builtin/aptos/0x1.js.map +0 -1
- package/lib/builtin/aptos/0x3.d.ts +0 -482
- package/lib/builtin/aptos/0x3.js +0 -526
- package/lib/builtin/aptos/0x3.js.map +0 -1
- package/lib/builtin/aptos/index.d.ts +0 -2
- package/lib/builtin/aptos/index.js +0 -29
- package/lib/builtin/aptos/index.js.map +0 -1
- package/lib/builtin/solana/index.d.ts +0 -2
- package/lib/builtin/solana/index.js +0 -19
- package/lib/builtin/solana/index.js.map +0 -1
- package/lib/builtin/solana/spl-token-processor.d.ts +0 -39
- package/lib/builtin/solana/spl-token-processor.js +0 -258
- package/lib/builtin/solana/spl-token-processor.js.map +0 -1
- package/lib/builtin/solana/types.d.ts +0 -427
- package/lib/builtin/solana/types.js +0 -203
- package/lib/builtin/solana/types.js.map +0 -1
- package/lib/builtin/solana/wormhole-processor.d.ts +0 -12
- package/lib/builtin/solana/wormhole-processor.js +0 -268
- package/lib/builtin/solana/wormhole-processor.js.map +0 -1
- package/lib/core/solana-context.d.ts +0 -11
- package/lib/core/solana-context.js +0 -34
- package/lib/core/solana-context.js.map +0 -1
- package/lib/core/solana-options.d.ts +0 -8
- package/lib/core/solana-options.js +0 -13
- package/lib/core/solana-options.js.map +0 -1
- package/lib/core/solana-plugin.d.ts +0 -9
- package/lib/core/solana-plugin.js +0 -79
- package/lib/core/solana-plugin.js.map +0 -1
- package/lib/core/solana-processor.d.ts +0 -40
- package/lib/core/solana-processor.js +0 -80
- package/lib/core/solana-processor.js.map +0 -1
- package/lib/solana-codegen/codegen.d.ts +0 -1
- package/lib/solana-codegen/codegen.js +0 -124
- package/lib/solana-codegen/codegen.js.map +0 -1
- package/lib/test-abi-code-gen.d.ts +0 -2
- package/lib/test-abi-code-gen.js +0 -20
- package/lib/test-abi-code-gen.js.map +0 -1
- package/src/abis/aptos/0x1.json +0 -9205
- package/src/abis/aptos/0x3.json +0 -1515
- package/src/aptos/api.ts +0 -11
- package/src/aptos/aptos-plugin.ts +0 -216
- package/src/aptos/aptos-processor.ts +0 -305
- package/src/aptos/context.ts +0 -74
- package/src/aptos/index.ts +0 -10
- package/src/aptos/models.ts +0 -34
- package/src/aptos/network.ts +0 -42
- package/src/aptos/runtime.ts +0 -13
- package/src/aptos/type-registry.ts +0 -187
- package/src/aptos/types.ts +0 -149
- package/src/aptos/utils.ts +0 -26
- package/src/aptos-codegen/codegen.ts +0 -428
- package/src/aptos-codegen/tsconfig.json +0 -9
- package/src/aptos-codegen/typegen.ts +0 -153
- package/src/builtin/aptos/0x1.ts +0 -4210
- package/src/builtin/aptos/0x3.ts +0 -888
- package/src/builtin/aptos/index.ts +0 -2
- package/src/builtin/solana/index.ts +0 -2
- package/src/builtin/solana/spl-token-processor.ts +0 -298
- package/src/builtin/solana/types.ts +0 -279
- package/src/builtin/solana/wormhole-processor.ts +0 -269
- package/src/core/solana-context.ts +0 -34
- package/src/core/solana-options.ts +0 -8
- package/src/core/solana-plugin.ts +0 -97
- package/src/core/solana-processor.ts +0 -102
- package/src/solana-codegen/codegen.ts +0 -129
- package/src/test-abi-code-gen.ts +0 -16
|
@@ -1,364 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.AccountCodegen = exports.generateForNetwork = exports.generate = exports.codeGenAptosProcessor = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const prettier_1 = __importDefault(require("prettier"));
|
|
10
|
-
const typegen_1 = require("./typegen");
|
|
11
|
-
const utils_1 = require("../aptos/utils");
|
|
12
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
13
|
-
const network_1 = require("../aptos/network");
|
|
14
|
-
const types_1 = require("../aptos/types");
|
|
15
|
-
function codeGenAptosProcessor(abisDir, outDir = 'src/types/aptos') {
|
|
16
|
-
if (!fs_1.default.existsSync(abisDir)) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
console.log(chalk_1.default.green('Generated Types for Aptos'));
|
|
20
|
-
generate(abisDir, outDir);
|
|
21
|
-
}
|
|
22
|
-
exports.codeGenAptosProcessor = codeGenAptosProcessor;
|
|
23
|
-
async function generate(srcDir, outputDir) {
|
|
24
|
-
await generateForNetwork(srcDir, outputDir, network_1.AptosNetwork.MAIN_NET);
|
|
25
|
-
await generateForNetwork(path_1.default.join(srcDir, 'testnet'), path_1.default.join(outputDir, 'testnet'), network_1.AptosNetwork.TEST_NET);
|
|
26
|
-
}
|
|
27
|
-
exports.generate = generate;
|
|
28
|
-
async function generateForNetwork(srcDir, outputDir, network) {
|
|
29
|
-
if (!fs_1.default.existsSync(srcDir)) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
if (network === network_1.AptosNetwork.TEST_NET) {
|
|
33
|
-
console.log('Found testnet directory, generate code for testnet modules');
|
|
34
|
-
}
|
|
35
|
-
const files = fs_1.default.readdirSync(srcDir);
|
|
36
|
-
outputDir = path_1.default.resolve(outputDir);
|
|
37
|
-
const outputs = [];
|
|
38
|
-
fs_1.default.mkdirSync(outputDir, { recursive: true });
|
|
39
|
-
const loader = new typegen_1.AccountRegister();
|
|
40
|
-
// when generating user code, don't need to generate framework account
|
|
41
|
-
loader.accountImports.set('0x1', new typegen_1.AccountModulesImportInfo('0x1', '0x1'));
|
|
42
|
-
loader.accountImports.set('0x2', new typegen_1.AccountModulesImportInfo('0x2', '0x2'));
|
|
43
|
-
loader.accountImports.set('0x3', new typegen_1.AccountModulesImportInfo('0x3', '0x3'));
|
|
44
|
-
const client = (0, network_1.getRpcClient)(network);
|
|
45
|
-
for (const file of files) {
|
|
46
|
-
if (!file.endsWith('.json')) {
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
const fullPath = path_1.default.resolve(srcDir, file);
|
|
50
|
-
const modules = JSON.parse(fs_1.default.readFileSync(fullPath, 'utf-8'));
|
|
51
|
-
for (const module of modules) {
|
|
52
|
-
if (module.abi) {
|
|
53
|
-
loader.register(module.abi, path_1.default.basename(file, '.json'));
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const codeGen = new AccountCodegen(loader, modules, {
|
|
57
|
-
fileName: path_1.default.basename(file, '.json'),
|
|
58
|
-
outputDir: outputDir,
|
|
59
|
-
network,
|
|
60
|
-
});
|
|
61
|
-
outputs.push(...codeGen.generate());
|
|
62
|
-
}
|
|
63
|
-
while (loader.pendingAccounts.size > 0) {
|
|
64
|
-
for (const account of loader.pendingAccounts) {
|
|
65
|
-
console.log(`download dependent module for account ${account} at ${(0, network_1.getAptosChainName)(network)}`);
|
|
66
|
-
try {
|
|
67
|
-
const modules = await client.getAccountModules(account);
|
|
68
|
-
fs_1.default.writeFileSync(path_1.default.resolve(srcDir, account + '.json'), JSON.stringify(modules, null, '\t'));
|
|
69
|
-
for (const module of modules) {
|
|
70
|
-
if (module.abi) {
|
|
71
|
-
loader.register(module.abi, account);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
const codeGen = new AccountCodegen(loader, modules, {
|
|
75
|
-
fileName: account,
|
|
76
|
-
outputDir: outputDir,
|
|
77
|
-
network,
|
|
78
|
-
});
|
|
79
|
-
outputs.push(...codeGen.generate());
|
|
80
|
-
}
|
|
81
|
-
catch (e) {
|
|
82
|
-
console.error(chalk_1.default.red('Error downloading account module, check if you choose the right network,or download account modules manually into your director'));
|
|
83
|
-
console.error(e);
|
|
84
|
-
process.exit(1);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
for (const output of outputs) {
|
|
89
|
-
const content = prettier_1.default.format(output.fileContent, { parser: 'typescript' });
|
|
90
|
-
fs_1.default.writeFileSync(path_1.default.join(outputDir, output.fileName), content);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
exports.generateForNetwork = generateForNetwork;
|
|
94
|
-
class AccountCodegen {
|
|
95
|
-
modules;
|
|
96
|
-
config;
|
|
97
|
-
loader;
|
|
98
|
-
constructor(loader, modules, config) {
|
|
99
|
-
// const json = fs.readFileSync(config.srcFile, 'utf-8')
|
|
100
|
-
this.modules = modules;
|
|
101
|
-
this.config = config;
|
|
102
|
-
this.loader = loader;
|
|
103
|
-
}
|
|
104
|
-
generate() {
|
|
105
|
-
if (!this.modules) {
|
|
106
|
-
return [];
|
|
107
|
-
}
|
|
108
|
-
// const baseName = path.basename(this.config.fileName, '.json')
|
|
109
|
-
let address;
|
|
110
|
-
for (const module of this.modules) {
|
|
111
|
-
if (module.abi && module.abi.address) {
|
|
112
|
-
address = module.abi.address;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if (!address) {
|
|
116
|
-
return [];
|
|
117
|
-
}
|
|
118
|
-
const imports = `
|
|
119
|
-
import { aptos } from "@sentio/sdk"
|
|
120
|
-
import { Address, MoveModule } from "aptos-sdk/src/generated"
|
|
121
|
-
`;
|
|
122
|
-
const dependedAccounts = [];
|
|
123
|
-
const moduleImports = [];
|
|
124
|
-
const info = this.loader.accountImports.get(address);
|
|
125
|
-
if (info) {
|
|
126
|
-
for (const [account] of info.imports.entries()) {
|
|
127
|
-
// Remap to user's filename if possible, TODO codepath not well tested
|
|
128
|
-
let tsAccountModule = './' + (this.loader.accountImports.get(account)?.moduleName || account);
|
|
129
|
-
if ((0, utils_1.isFrameworkAccount)(account) && !(0, utils_1.isFrameworkAccount)(address)) {
|
|
130
|
-
// Decide where to find runtime library
|
|
131
|
-
let srcRoot = 'lib';
|
|
132
|
-
if (__dirname.includes('sdk/src/aptos-codegen')) {
|
|
133
|
-
srcRoot = 'src';
|
|
134
|
-
}
|
|
135
|
-
tsAccountModule = `@sentio/sdk/${srcRoot}/builtin/aptos/${account}`;
|
|
136
|
-
}
|
|
137
|
-
moduleImports.push(`import * as _${account} from "${tsAccountModule}"`);
|
|
138
|
-
dependedAccounts.push(account);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
const source = `
|
|
142
|
-
/* Autogenerated file. Do not edit manually. */
|
|
143
|
-
/* tslint:disable */
|
|
144
|
-
/* eslint-disable */
|
|
145
|
-
|
|
146
|
-
/* Generated modules for account ${address} */
|
|
147
|
-
|
|
148
|
-
${imports}
|
|
149
|
-
|
|
150
|
-
${moduleImports.join('\n')}
|
|
151
|
-
|
|
152
|
-
${this.modules.map((m) => generateModule(m, this.config.network)).join('\n')}
|
|
153
|
-
|
|
154
|
-
export function loadAllTypes(_r: aptos.TypeRegistry) {
|
|
155
|
-
${dependedAccounts.map((a) => `_${a}.loadAllTypes(_r)`).join('\n')}
|
|
156
|
-
|
|
157
|
-
${this.modules
|
|
158
|
-
.map((m) => {
|
|
159
|
-
return `_r.load(${m.abi?.name}.ABI)`;
|
|
160
|
-
})
|
|
161
|
-
.join('\n')}
|
|
162
|
-
}
|
|
163
|
-
`; // source
|
|
164
|
-
return [
|
|
165
|
-
{
|
|
166
|
-
fileName: this.config.fileName + '.ts',
|
|
167
|
-
fileContent: source,
|
|
168
|
-
},
|
|
169
|
-
];
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
exports.AccountCodegen = AccountCodegen;
|
|
173
|
-
function generateNetworkOption(network) {
|
|
174
|
-
switch (network) {
|
|
175
|
-
case network_1.AptosNetwork.TEST_NET:
|
|
176
|
-
return 'TEST_NET';
|
|
177
|
-
}
|
|
178
|
-
return 'MAIN_NET';
|
|
179
|
-
}
|
|
180
|
-
function generateModule(moduleByteCode, network) {
|
|
181
|
-
if (!moduleByteCode.abi) {
|
|
182
|
-
return '';
|
|
183
|
-
}
|
|
184
|
-
const module = moduleByteCode.abi;
|
|
185
|
-
const functions = module.exposed_functions.map((f) => generateOnEntryFunctions(module, f)).filter((s) => s !== '');
|
|
186
|
-
const eventStructs = getEventStructs(module);
|
|
187
|
-
const eventTypes = new Set(eventStructs.keys());
|
|
188
|
-
const events = Array.from(eventStructs.values())
|
|
189
|
-
.map((e) => generateOnEvents(module, e))
|
|
190
|
-
.filter((s) => s !== '');
|
|
191
|
-
const structs = module.structs.map((s) => generateStructs(module, s, eventTypes));
|
|
192
|
-
const callArgs = module.exposed_functions.map((f) => generateCallArgsStructs(module, f));
|
|
193
|
-
let processor = '';
|
|
194
|
-
if (functions.length > 0 || events.length > 0) {
|
|
195
|
-
processor = `export class ${module.name} extends aptos.AptosBaseProcessor {
|
|
196
|
-
|
|
197
|
-
constructor(options: aptos.AptosBindOptions) {
|
|
198
|
-
super("${module.name}", options)
|
|
199
|
-
}
|
|
200
|
-
static DEFAULT_OPTIONS: aptos.AptosBindOptions = {
|
|
201
|
-
address: "${module.address}",
|
|
202
|
-
network: aptos.AptosNetwork.${generateNetworkOption(network)}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
static bind(options: Partial<aptos.AptosBindOptions> = {}): ${module.name} {
|
|
206
|
-
return new ${module.name}({ ...${module.name}.DEFAULT_OPTIONS, ...options })
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
${functions.join('\n')}
|
|
210
|
-
|
|
211
|
-
${events.join('\n')}
|
|
212
|
-
|
|
213
|
-
loadTypesInternal(registry: aptos.TypeRegistry) {
|
|
214
|
-
loadAllTypes(registry)
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
`;
|
|
218
|
-
}
|
|
219
|
-
return `
|
|
220
|
-
${processor}
|
|
221
|
-
|
|
222
|
-
export namespace ${module.name} {
|
|
223
|
-
${structs.join('\n')}
|
|
224
|
-
|
|
225
|
-
${callArgs.join('\n')}
|
|
226
|
-
|
|
227
|
-
export function loadTypes(_r: aptos.TypeRegistry) {
|
|
228
|
-
loadAllTypes(_r)
|
|
229
|
-
}
|
|
230
|
-
export const ABI: MoveModule = JSON.parse('${JSON.stringify(module)}')
|
|
231
|
-
}
|
|
232
|
-
`;
|
|
233
|
-
}
|
|
234
|
-
function generateStructs(module, struct, events) {
|
|
235
|
-
const genericString = generateStructTypeParameters(struct);
|
|
236
|
-
const genericStringAny = generateStructTypeParameters(struct, true);
|
|
237
|
-
const fields = struct.fields.map((field) => {
|
|
238
|
-
return `${field.name}: ${(0, typegen_1.generateType)(field.type, module.address)}`;
|
|
239
|
-
});
|
|
240
|
-
let eventPayload = '';
|
|
241
|
-
if (events.has((0, utils_1.moduleQname)(module) + utils_1.SPLITTER + struct.name)) {
|
|
242
|
-
eventPayload = `
|
|
243
|
-
export interface ${struct.name}Instance extends
|
|
244
|
-
aptos.TypedEventInstance<${struct.name}${genericStringAny}> {
|
|
245
|
-
data_typed: ${struct.name}${genericStringAny}
|
|
246
|
-
type_arguments: [${struct.generic_type_params.map((_) => 'string').join(', ')}]
|
|
247
|
-
}
|
|
248
|
-
`;
|
|
249
|
-
}
|
|
250
|
-
return `
|
|
251
|
-
export class ${struct.name}${genericString} {
|
|
252
|
-
static TYPE_QNAME = '${module.address}::${module.name}::${struct.name}'
|
|
253
|
-
${fields.join('\n')}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
${eventPayload}
|
|
257
|
-
`;
|
|
258
|
-
}
|
|
259
|
-
function generateFunctionTypeParameters(func) {
|
|
260
|
-
let genericString = '';
|
|
261
|
-
if (func.generic_type_params && func.generic_type_params.length > 0) {
|
|
262
|
-
const params = func.generic_type_params
|
|
263
|
-
.map((v, idx) => {
|
|
264
|
-
return `T${idx}=any`;
|
|
265
|
-
})
|
|
266
|
-
.join(',');
|
|
267
|
-
genericString = `<${params}>`;
|
|
268
|
-
}
|
|
269
|
-
return genericString;
|
|
270
|
-
}
|
|
271
|
-
function generateStructTypeParameters(struct, useAny = false) {
|
|
272
|
-
let genericString = '';
|
|
273
|
-
if (struct.generic_type_params && struct.generic_type_params.length > 0) {
|
|
274
|
-
const params = struct.generic_type_params
|
|
275
|
-
.map((v, idx) => {
|
|
276
|
-
return useAny ? 'any' : 'T' + idx;
|
|
277
|
-
})
|
|
278
|
-
.join(',');
|
|
279
|
-
genericString = `<${params}>`;
|
|
280
|
-
}
|
|
281
|
-
return genericString;
|
|
282
|
-
}
|
|
283
|
-
function generateCallArgsStructs(module, func) {
|
|
284
|
-
if (!func.is_entry) {
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
const fields = (0, utils_1.getMeaningfulFunctionParams)(func).map((param) => {
|
|
288
|
-
return `${(0, typegen_1.generateType)(param, module.address)}`;
|
|
289
|
-
});
|
|
290
|
-
const camelFuncName = capitalizeFirstChar(camelize(func.name));
|
|
291
|
-
const genericString = generateFunctionTypeParameters(func);
|
|
292
|
-
return `
|
|
293
|
-
export interface ${camelFuncName}Payload${genericString}
|
|
294
|
-
extends aptos.TypedEntryFunctionPayload<[${fields.join(',')}]> {
|
|
295
|
-
arguments_typed: [${fields.join(',')}],
|
|
296
|
-
type_arguments: [${func.generic_type_params.map((_) => 'string').join(', ')}]
|
|
297
|
-
}
|
|
298
|
-
`;
|
|
299
|
-
}
|
|
300
|
-
function generateOnEntryFunctions(module, func) {
|
|
301
|
-
if (!func.is_entry) {
|
|
302
|
-
return '';
|
|
303
|
-
}
|
|
304
|
-
// const genericString = generateFunctionTypeParameters(func)
|
|
305
|
-
const camelFuncName = capitalizeFirstChar(camelize(func.name));
|
|
306
|
-
const source = `
|
|
307
|
-
onEntry${camelFuncName}(func: (call: ${module.name}.${camelFuncName}Payload, ctx: aptos.AptosContext) => void, filter?: aptos.CallFilter): ${module.name} {
|
|
308
|
-
this.onEntryFunctionCall(func, {
|
|
309
|
-
...filter,
|
|
310
|
-
function: '${module.name}::${func.name}'
|
|
311
|
-
})
|
|
312
|
-
return this
|
|
313
|
-
}`;
|
|
314
|
-
return source;
|
|
315
|
-
}
|
|
316
|
-
function getEventStructs(module) {
|
|
317
|
-
const qname = (0, utils_1.moduleQname)(module);
|
|
318
|
-
const structMap = new Map();
|
|
319
|
-
const eventMap = new Map();
|
|
320
|
-
for (const struct of module.structs) {
|
|
321
|
-
structMap.set(qname + utils_1.SPLITTER + struct.name, struct);
|
|
322
|
-
}
|
|
323
|
-
for (const struct of module.structs) {
|
|
324
|
-
for (const field of struct.fields) {
|
|
325
|
-
const t = (0, types_1.parseMoveType)(field.type);
|
|
326
|
-
if (t.qname === '0x1::event::EventHandle') {
|
|
327
|
-
const event = t.typeArgs[0].qname;
|
|
328
|
-
const eventStruct = structMap.get(event);
|
|
329
|
-
if (eventStruct) {
|
|
330
|
-
eventMap.set(event, eventStruct);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
return eventMap;
|
|
336
|
-
}
|
|
337
|
-
function generateOnEvents(module, struct) {
|
|
338
|
-
// for struct that has drop + store
|
|
339
|
-
// if (!isEvent(struct, module)) {
|
|
340
|
-
// return ''
|
|
341
|
-
// }
|
|
342
|
-
// const genericString = generateStructTypeParameters(struct)
|
|
343
|
-
const source = `
|
|
344
|
-
onEvent${struct.name}(func: (event: ${module.name}.${struct.name}Instance, ctx: aptos.AptosContext) => void): ${module.name} {
|
|
345
|
-
this.onEvent(func, {
|
|
346
|
-
type: '${module.name}::${struct.name}'
|
|
347
|
-
})
|
|
348
|
-
return this
|
|
349
|
-
}
|
|
350
|
-
`;
|
|
351
|
-
return source;
|
|
352
|
-
}
|
|
353
|
-
function camelize(input) {
|
|
354
|
-
return input
|
|
355
|
-
.split('_')
|
|
356
|
-
.reduce((res, word, i) => i === 0 ? word.toLowerCase() : `${res}${word.charAt(0).toUpperCase()}${word.substr(1).toLowerCase()}`, '');
|
|
357
|
-
}
|
|
358
|
-
function capitalizeFirstChar(input) {
|
|
359
|
-
if (!input) {
|
|
360
|
-
return input;
|
|
361
|
-
}
|
|
362
|
-
return input[0].toUpperCase() + (input.length > 1 ? input.substring(1) : '');
|
|
363
|
-
}
|
|
364
|
-
//# sourceMappingURL=codegen.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,8CAAgF;AAChF,0CAA8C;AAE9C,SAAgB,qBAAqB,CAAC,OAAe,EAAE,MAAM,GAAG,iBAAiB;IAC/E,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;QAC3B,OAAM;KACP;IACD,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC,CAAA;IACrD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;AAC3B,CAAC;AAND,sDAMC;AAEM,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,IA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AM,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, getAptosChainName, getRpcClient } from '../aptos/network'\nimport { parseMoveType } from '../aptos/types'\n\nexport function codeGenAptosProcessor(abisDir: string, outDir = 'src/types/aptos') {\n if (!fs.existsSync(abisDir)) {\n return\n }\n console.log(chalk.green('Generated Types for Aptos'))\n generate(abisDir, outDir)\n}\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 ${getAptosChainName(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,17 +0,0 @@
|
|
|
1
|
-
import { MoveModule } from 'aptos-sdk/src/generated';
|
|
2
|
-
import { TypeDescriptor } from '../aptos/types';
|
|
3
|
-
export declare function generateType(type: string, currentAddress: string): string;
|
|
4
|
-
export declare class AccountModulesImportInfo {
|
|
5
|
-
imports: Map<string, Set<string>>;
|
|
6
|
-
account: string;
|
|
7
|
-
moduleName: string;
|
|
8
|
-
constructor(account: string, tsModuleName: string);
|
|
9
|
-
addImport(account: string, module: string): void;
|
|
10
|
-
}
|
|
11
|
-
export declare class AccountRegister {
|
|
12
|
-
accountImports: Map<string, AccountModulesImportInfo>;
|
|
13
|
-
pendingAccounts: Set<string>;
|
|
14
|
-
typeRegistry: Map<string, TypeDescriptor>;
|
|
15
|
-
private loadTypeDescriptor;
|
|
16
|
-
register(module: MoveModule, tsModuleName: string): AccountModulesImportInfo;
|
|
17
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AccountRegister = exports.AccountModulesImportInfo = exports.generateType = void 0;
|
|
4
|
-
const types_1 = require("../aptos/types");
|
|
5
|
-
const utils_1 = require("../aptos/utils");
|
|
6
|
-
function generateTypeForDescriptor(type, currentAddress) {
|
|
7
|
-
// TODO &signer is defintely an address, but what if &OTHER_TYPE?
|
|
8
|
-
if (type.qname.startsWith('&')) {
|
|
9
|
-
return 'Address';
|
|
10
|
-
}
|
|
11
|
-
switch (type.qname) {
|
|
12
|
-
case 'signer': // TODO check this
|
|
13
|
-
case 'address':
|
|
14
|
-
return 'Address';
|
|
15
|
-
case '0x1::string::String':
|
|
16
|
-
return 'string';
|
|
17
|
-
case 'bool':
|
|
18
|
-
return 'Boolean';
|
|
19
|
-
case 'u8':
|
|
20
|
-
case 'u16':
|
|
21
|
-
case 'u32':
|
|
22
|
-
return 'number';
|
|
23
|
-
case 'u64':
|
|
24
|
-
case 'u128':
|
|
25
|
-
return 'bigint';
|
|
26
|
-
}
|
|
27
|
-
if (type.qname === utils_1.VECTOR_STR) {
|
|
28
|
-
// vector<u8> as hex string
|
|
29
|
-
const elementTypeQname = type.typeArgs[0].qname;
|
|
30
|
-
if (elementTypeQname === 'u8') {
|
|
31
|
-
return 'string';
|
|
32
|
-
}
|
|
33
|
-
if (elementTypeQname.startsWith('T') && !elementTypeQname.includes(utils_1.SPLITTER)) {
|
|
34
|
-
return `${elementTypeQname}[] | string`;
|
|
35
|
-
}
|
|
36
|
-
return generateTypeForDescriptor(type.typeArgs[0], currentAddress) + '[]';
|
|
37
|
-
}
|
|
38
|
-
const simpleName = generateSimpleType(type.qname, currentAddress);
|
|
39
|
-
if (simpleName.length === 0) {
|
|
40
|
-
console.error('unexpected error');
|
|
41
|
-
}
|
|
42
|
-
if (simpleName.includes('vector')) {
|
|
43
|
-
console.error('unexpected error');
|
|
44
|
-
}
|
|
45
|
-
if (type.typeArgs.length > 0) {
|
|
46
|
-
// return simpleName
|
|
47
|
-
return simpleName + '<' + type.typeArgs.map((t) => generateTypeForDescriptor(t, currentAddress)).join(',') + '>';
|
|
48
|
-
}
|
|
49
|
-
return simpleName;
|
|
50
|
-
}
|
|
51
|
-
function generateSimpleType(type, currentAddress) {
|
|
52
|
-
const parts = type.split(utils_1.SPLITTER);
|
|
53
|
-
if (parts.length < 2) {
|
|
54
|
-
return parts[0];
|
|
55
|
-
}
|
|
56
|
-
if (parts[0] === currentAddress) {
|
|
57
|
-
return parts.slice(1).join('.');
|
|
58
|
-
}
|
|
59
|
-
return '_' + parts.join('.');
|
|
60
|
-
}
|
|
61
|
-
// TODO ctx need to have type parameters
|
|
62
|
-
function generateType(type, currentAddress) {
|
|
63
|
-
return generateTypeForDescriptor((0, types_1.parseMoveType)(type), currentAddress);
|
|
64
|
-
}
|
|
65
|
-
exports.generateType = generateType;
|
|
66
|
-
class AccountModulesImportInfo {
|
|
67
|
-
// account to module
|
|
68
|
-
imports;
|
|
69
|
-
account;
|
|
70
|
-
moduleName;
|
|
71
|
-
constructor(account, tsModuleName) {
|
|
72
|
-
this.account = account;
|
|
73
|
-
this.moduleName = tsModuleName;
|
|
74
|
-
this.imports = new Map();
|
|
75
|
-
}
|
|
76
|
-
addImport(account, module) {
|
|
77
|
-
if (account === this.account) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
let accountModules = this.imports.get(account);
|
|
81
|
-
if (!accountModules) {
|
|
82
|
-
accountModules = new Set();
|
|
83
|
-
this.imports.set(account, accountModules);
|
|
84
|
-
}
|
|
85
|
-
accountModules.add(module);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
exports.AccountModulesImportInfo = AccountModulesImportInfo;
|
|
89
|
-
class AccountRegister {
|
|
90
|
-
accountImports = new Map();
|
|
91
|
-
pendingAccounts = new Set();
|
|
92
|
-
// loadedAccount = new Set<string>()
|
|
93
|
-
typeRegistry = new Map();
|
|
94
|
-
loadTypeDescriptor(type) {
|
|
95
|
-
let descriptor = this.typeRegistry.get(type);
|
|
96
|
-
// const descriptparseMoveType(type)
|
|
97
|
-
if (!descriptor) {
|
|
98
|
-
descriptor = (0, types_1.parseMoveType)(type);
|
|
99
|
-
this.typeRegistry.set(type, descriptor);
|
|
100
|
-
}
|
|
101
|
-
return descriptor;
|
|
102
|
-
}
|
|
103
|
-
register(module, tsModuleName) {
|
|
104
|
-
const currentModuleFqn = (0, utils_1.moduleQname)(module);
|
|
105
|
-
let accountModuleImports = this.accountImports.get(module.address);
|
|
106
|
-
if (!accountModuleImports) {
|
|
107
|
-
accountModuleImports = new AccountModulesImportInfo(module.address, tsModuleName);
|
|
108
|
-
this.accountImports.set(module.address, accountModuleImports);
|
|
109
|
-
// the account has already be processed, delete pending task
|
|
110
|
-
this.pendingAccounts.delete(module.address);
|
|
111
|
-
}
|
|
112
|
-
for (const struct of module.structs) {
|
|
113
|
-
for (const field of struct.fields) {
|
|
114
|
-
for (const type of this.loadTypeDescriptor(field.type).dependedTypes()) {
|
|
115
|
-
const [account, module] = (0, utils_1.moduleQnameForType)(type);
|
|
116
|
-
accountModuleImports.addImport(account, module);
|
|
117
|
-
if (!this.accountImports.has(account)) {
|
|
118
|
-
this.pendingAccounts.add(account);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
for (const func of module.exposed_functions) {
|
|
124
|
-
if (!func.is_entry) {
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
for (const param of func.params) {
|
|
128
|
-
for (const type of this.loadTypeDescriptor(param).dependedTypes()) {
|
|
129
|
-
const [account, module] = (0, utils_1.moduleQnameForType)(type);
|
|
130
|
-
accountModuleImports.addImport(account, module);
|
|
131
|
-
if (!this.accountImports.has(account)) {
|
|
132
|
-
this.pendingAccounts.add(account);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
this.accountImports.set(currentModuleFqn, accountModuleImports);
|
|
138
|
-
return accountModuleImports;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
exports.AccountRegister = AccountRegister;
|
|
142
|
-
//# sourceMappingURL=typegen.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"typegen.js","sourceRoot":"","sources":["../../src/aptos-codegen/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AC,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"]}
|