@sentio/sdk 2.5.0-rc.3 → 2.5.1-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/aptos/codegen/codegen.js +3 -3
- package/lib/aptos/codegen/codegen.js.map +1 -1
- package/lib/aptos/move-coder.js +2 -2
- package/lib/aptos/move-coder.js.map +1 -1
- package/lib/aptos/move-types.d.ts +5 -5
- package/lib/aptos/move-types.js +15 -15
- package/lib/aptos/move-types.js.map +1 -1
- package/lib/move/abstract-codegen.d.ts +12 -12
- package/lib/move/abstract-codegen.js +27 -27
- package/lib/move/abstract-codegen.js.map +1 -1
- package/lib/move/abstract-move-coder.d.ts +4 -4
- package/lib/move/abstract-move-coder.js +3 -3
- package/lib/move/abstract-move-coder.js.map +1 -1
- package/lib/move/account.d.ts +4 -7
- package/lib/move/account.js +2 -14
- package/lib/move/account.js.map +1 -1
- package/lib/move/internal-models.d.ts +34 -0
- package/lib/move/internal-models.js +7 -0
- package/lib/move/internal-models.js.map +1 -0
- package/lib/move/ts-type.js +1 -3
- package/lib/move/ts-type.js.map +1 -1
- package/lib/move/types.d.ts +1 -0
- package/lib/move/types.js +13 -25
- package/lib/move/types.js.map +1 -1
- package/lib/sui/codegen/codegen.js +5 -5
- package/lib/sui/codegen/codegen.js.map +1 -1
- package/lib/sui/move-coder.js +2 -2
- package/lib/sui/move-coder.js.map +1 -1
- package/lib/sui/move-types.d.ts +7 -7
- package/lib/sui/move-types.js +26 -25
- package/lib/sui/move-types.js.map +1 -1
- package/lib/sui/utils.d.ts +2 -2
- package/lib/sui/utils.js.map +1 -1
- package/package.json +9 -9
- package/src/aptos/codegen/codegen.ts +7 -7
- package/src/aptos/move-coder.ts +2 -3
- package/src/aptos/move-types.ts +20 -20
- package/src/move/abstract-codegen.ts +42 -40
- package/src/move/abstract-move-coder.ts +9 -9
- package/src/move/account.ts +6 -21
- package/src/move/internal-models.ts +40 -0
- package/src/move/ts-type.ts +1 -3
- package/src/move/types.ts +13 -33
- package/src/sui/codegen/codegen.ts +8 -8
- package/src/sui/move-coder.ts +2 -2
- package/src/sui/move-types.ts +32 -31
- package/src/sui/utils.ts +2 -2
- package/lib/move/neutral-models.d.ts +0 -34
- package/lib/move/neutral-models.js +0 -7
- package/lib/move/neutral-models.js.map +0 -1
- package/src/move/neutral-models.ts +0 -45
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract-move-coder.js","sourceRoot":"","sources":["../../src/move/abstract-move-coder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAC9D,OAAO,EAAE,aAAa,EAAkB,MAAM,YAAY,CAAA;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAYjD,MAAM,OAAgB,iBAAiB;IAC7B,aAAa,GAAG,IAAI,GAAG,
|
|
1
|
+
{"version":3,"file":"abstract-move-coder.js","sourceRoot":"","sources":["../../src/move/abstract-move-coder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAC9D,OAAO,EAAE,aAAa,EAAkB,MAAM,YAAY,CAAA;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAYjD,MAAM,OAAgB,iBAAiB;IAC7B,aAAa,GAAG,IAAI,GAAG,EAA8B,CAAA;IACrD,WAAW,GAAG,IAAI,GAAG,EAA8B,CAAA;IACnD,WAAW,GAAG,IAAI,GAAG,EAAgC,CAAA;IAE7D,QAAQ,CAAC,OAAe,EAAE,IAAY;QACpC,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC,CAAA;IACtD,CAAC;IAED,YAAY,CAAC,MAA0B;QACrC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,C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CAAC,CAAC,CAAC,KAAK,SAAS,EAAE;gBAC7C,SAAQ;aACT;YACD,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAA;YAC7C,IAAI,MAAM,EAAE;gBACV,OAAO,CAAC,IAAI,CAAC,MAA6C,CAAC,CAAA;aAC5D;SACF;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;IAES,eAAe,CAAI,UAAqC;QAChE,MAAM,cAAc,GAAG,aAAa,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;QACrD,MAAM,aAAa,GAAG,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAA;QAE1E,IAAI,SAAS,GAAG,SAAS,CAAA;QACzB,IAAI;YACF,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,cAAc,CAAC,CAAA;SACzD;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAA;YACnE,OAAO,SAAS,CAAA;SACjB;QACD,OAAO;YACL,GAAG,UAAU;YACb,YAAY,EAAE,SAAS;YACvB,cAAc,EAAE,aAAa;SACS,CAAA;IAC1C,CAAC;CACF","sourcesContent":["import { moduleQname, SPLITTER, VECTOR_STR } from './utils.js'\nimport { parseMoveType, TypeDescriptor } from './types.js'\nimport { InternalMoveFunction, InternalMoveModule, InternalMoveStruct } from './internal-models.js'\nimport { bytesToBigInt } from '../utils/index.js'\n\ntype StructWithTag<Base> = Base & {\n type: string\n data: any\n}\n\ntype DecodedStructWithTag<B, T> = StructWithTag<B> & {\n data_decoded: T\n type_arguments: string[]\n}\n\nexport abstract class AbstractMoveCoder<StructType> {\n private moduleMapping = new Map<string, InternalMoveModule>()\n private typeMapping = new Map<string, InternalMoveStruct>()\n private funcMapping = new Map<string, InternalMoveFunction>()\n\n contains(account: string, name: string) {\n return this.moduleMapping.has(account + '::' + name)\n }\n\n loadInternal(module: InternalMoveModule) {\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.exposedFunctions) {\n if (!func.isEntry) {\n continue\n }\n const key = [module.address, module.name, func.name].join(SPLITTER)\n this.funcMapping.set(key, func)\n }\n }\n\n protected dataToBigInt(data: any): bigint {\n if (Array.isArray(data)) {\n // Only sui function need this, strange\n const bytes = data as number[]\n return bytesToBigInt(new Uint8Array(bytes.slice().reverse()))\n } else {\n return BigInt(data)\n }\n }\n\n protected getMoveStruct(type: string): InternalMoveStruct {\n const struct = this.typeMapping.get(type)\n if (!struct) {\n throw new Error('Failed to load type' + type + ' type are not imported anywhere')\n }\n return struct\n }\n\n protected getMoveFunction(type: string): InternalMoveFunction {\n const func = this.funcMapping.get(type)\n if (!func) {\n throw new Error('Failed to load function' + type + ' type are not imported anywhere')\n }\n return func\n }\n\n protected decode(data: any, type: TypeDescriptor): any {\n // process simple type\n if (type.reference) {\n return data\n }\n switch (type.qname) {\n case 'signer': // TODO check this, aptos only\n case 'address':\n case 'Address':\n case '0x2::object::ID':\n case '0x2::coin::Coin':\n case '0x1::string::String':\n case 'bool':\n case 'Bool':\n case 'u8':\n case 'U8':\n case 'u16':\n case 'U16':\n case 'u32':\n case 'U32':\n return data\n case 'u64':\n case 'U64':\n case 'u128':\n case 'U128':\n return this.dataToBigInt(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' || 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 = 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 protected filterAndDecodeInternal<T>(\n typeQname: string,\n structs: StructWithTag<StructType>[]\n ): DecodedStructWithTag<StructType, T>[] {\n if (!structs) {\n return []\n }\n const results: DecodedStructWithTag<StructType, 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 DecodedStructWithTag<StructType, T>)\n }\n }\n return results\n }\n\n protected decodedInternal<T>(typeStruct: StructWithTag<StructType>): DecodedStructWithTag<StructType, T> | undefined {\n const typeDescriptor = parseMoveType(typeStruct.type)\n const typeArguments = typeDescriptor.typeArgs.map((t) => t.getSignature())\n\n let dataTyped = undefined\n try {\n dataTyped = this.decode(typeStruct.data, typeDescriptor)\n } catch (e) {\n console.error('Decoding error for ', JSON.stringify(typeStruct), e)\n return undefined\n }\n return {\n ...typeStruct,\n data_decoded: dataTyped,\n type_arguments: typeArguments,\n } as DecodedStructWithTag<StructType, T>\n }\n}\n"]}
|
package/lib/move/account.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { NeutralMoveModule } from './neutral-models.js';
|
|
1
|
+
import { InternalMoveModule } from './internal-models.js';
|
|
3
2
|
export declare class AccountModulesImportInfo {
|
|
4
3
|
imports: Map<string, Set<string>>;
|
|
5
4
|
account: string;
|
|
@@ -10,9 +9,7 @@ export declare class AccountModulesImportInfo {
|
|
|
10
9
|
export declare class AccountRegister {
|
|
11
10
|
accountImports: Map<string, AccountModulesImportInfo>;
|
|
12
11
|
pendingAccounts: Set<string>;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
registerFunctions(module: NeutralMoveModule, accountModuleImports: AccountModulesImportInfo): void;
|
|
17
|
-
registerStruct(module: NeutralMoveModule, accountModuleImports: AccountModulesImportInfo): void;
|
|
12
|
+
register(module: InternalMoveModule, tsModuleName: string): AccountModulesImportInfo;
|
|
13
|
+
private registerFunctions;
|
|
14
|
+
private registerStruct;
|
|
18
15
|
}
|
package/lib/move/account.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { parseMoveType } from './types.js';
|
|
2
1
|
import { moduleQname, moduleQnameForType } from './utils.js';
|
|
3
2
|
export class AccountModulesImportInfo {
|
|
4
3
|
// account to module
|
|
@@ -25,17 +24,6 @@ export class AccountModulesImportInfo {
|
|
|
25
24
|
export class AccountRegister {
|
|
26
25
|
accountImports = new Map();
|
|
27
26
|
pendingAccounts = new Set();
|
|
28
|
-
// loadedAccount = new Set<string>()
|
|
29
|
-
typeDescriptors = new Map();
|
|
30
|
-
loadTypeDescriptor(type) {
|
|
31
|
-
let descriptor = this.typeDescriptors.get(type);
|
|
32
|
-
// const descriptparseMoveType(type)
|
|
33
|
-
if (!descriptor) {
|
|
34
|
-
descriptor = parseMoveType(type);
|
|
35
|
-
this.typeDescriptors.set(type, descriptor);
|
|
36
|
-
}
|
|
37
|
-
return descriptor;
|
|
38
|
-
}
|
|
39
27
|
register(module, tsModuleName) {
|
|
40
28
|
const currentModuleFqn = moduleQname(module);
|
|
41
29
|
let accountModuleImports = this.accountImports.get(module.address);
|
|
@@ -51,8 +39,8 @@ export class AccountRegister {
|
|
|
51
39
|
return accountModuleImports;
|
|
52
40
|
}
|
|
53
41
|
registerFunctions(module, accountModuleImports) {
|
|
54
|
-
for (const func of module.
|
|
55
|
-
if (!func.
|
|
42
|
+
for (const func of module.exposedFunctions) {
|
|
43
|
+
if (!func.isEntry) {
|
|
56
44
|
continue;
|
|
57
45
|
}
|
|
58
46
|
for (const param of func.params) {
|
package/lib/move/account.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/move/account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/move/account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAG5D,MAAM,OAAO,wBAAwB;IACnC,oBAAoB;IACpB,OAAO,CAA0B;IACjC,OAAO,CAAQ;IACf,UAAU,CAAQ;IAElB,YAAY,OAAe,EAAE,YAAoB;QAC/C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,YAAY,CAAA;QAC9B,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAuB,CAAA;IAC/C,CAAC;IAED,SAAS,CAAC,OAAe,EAAE,MAAc;QACvC,IAAI,OAAO,KAAK,IAAI,CAAC,OAAO,EAAE;YAC5B,OAAM;SACP;QACD,IAAI,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QAC9C,IAAI,CAAC,cAAc,EAAE;YACnB,cAAc,GAAG,IAAI,GAAG,EAAU,CAAA;YAClC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,cAAc,CAAC,CAAA;SAC1C;QACD,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IAC5B,CAAC;CACF;AAED,MAAM,OAAO,eAAe;IAC1B,cAAc,GAAG,IAAI,GAAG,EAAoC,CAAA;IAC5D,eAAe,GAAG,IAAI,GAAG,EAAU,CAAA;IAEnC,QAAQ,CAAC,MAA0B,EAAE,YAAoB;QACvD,MAAM,gBAAgB,GAAG,WAAW,CAAC,MAAM,CAAC,CAAA;QAE5C,IAAI,oBAAoB,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QAClE,IAA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,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE;gBACjC,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE;oBAC7C,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,kBAAkB,CAAC,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;IACH,CAAC;CACF","sourcesContent":["import { moduleQname, moduleQnameForType } from './utils.js'\nimport { InternalMoveModule } from './internal-models.js'\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 register(module: InternalMoveModule, 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 this.registerStruct(module, accountModuleImports)\n this.registerFunctions(module, accountModuleImports)\n\n this.accountImports.set(currentModuleFqn, accountModuleImports)\n return accountModuleImports\n }\n\n private registerFunctions(module: InternalMoveModule, accountModuleImports: AccountModulesImportInfo): void {\n for (const func of module.exposedFunctions) {\n if (!func.isEntry) {\n continue\n }\n for (const param of func.params) {\n for (const type of 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 }\n\n private registerStruct(module: InternalMoveModule, accountModuleImports: AccountModulesImportInfo): void {\n for (const struct of module.structs) {\n for (const field of struct.fields) {\n for (const type of 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}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { TypeDescriptor } from './types.js';
|
|
2
|
+
export interface InternalMoveModule {
|
|
3
|
+
address: string;
|
|
4
|
+
name: string;
|
|
5
|
+
exposedFunctions: InternalMoveFunction[];
|
|
6
|
+
structs: InternalMoveStruct[];
|
|
7
|
+
}
|
|
8
|
+
export interface InternalMoveFunction {
|
|
9
|
+
name: string;
|
|
10
|
+
visibility: InternalMoveFunctionVisibility;
|
|
11
|
+
isEntry: boolean;
|
|
12
|
+
typeParams: InternalMoveTypeParam[];
|
|
13
|
+
params: TypeDescriptor[];
|
|
14
|
+
return: TypeDescriptor[];
|
|
15
|
+
}
|
|
16
|
+
export interface InternalMoveStruct {
|
|
17
|
+
name: string;
|
|
18
|
+
isNative: boolean;
|
|
19
|
+
abilities: string[];
|
|
20
|
+
typeParams: InternalMoveTypeParam[];
|
|
21
|
+
fields: InternalMoveStructField[];
|
|
22
|
+
}
|
|
23
|
+
export interface InternalMoveStructField {
|
|
24
|
+
name: string;
|
|
25
|
+
type: TypeDescriptor;
|
|
26
|
+
}
|
|
27
|
+
export declare enum InternalMoveFunctionVisibility {
|
|
28
|
+
PRIVATE = "private",
|
|
29
|
+
PUBLIC = "public",
|
|
30
|
+
FRIEND = "friend"
|
|
31
|
+
}
|
|
32
|
+
export type InternalMoveTypeParam = {
|
|
33
|
+
constraints: string[];
|
|
34
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export var InternalMoveFunctionVisibility;
|
|
2
|
+
(function (InternalMoveFunctionVisibility) {
|
|
3
|
+
InternalMoveFunctionVisibility["PRIVATE"] = "private";
|
|
4
|
+
InternalMoveFunctionVisibility["PUBLIC"] = "public";
|
|
5
|
+
InternalMoveFunctionVisibility["FRIEND"] = "friend";
|
|
6
|
+
})(InternalMoveFunctionVisibility || (InternalMoveFunctionVisibility = {}));
|
|
7
|
+
//# sourceMappingURL=internal-models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal-models.js","sourceRoot":"","sources":["../../src/move/internal-models.ts"],"names":[],"mappings":"AA+BA,MAAM,CAAN,IAAY,8BAIX;AAJD,WAAY,8BAA8B;IACxC,qDAAmB,CAAA;IACnB,mDAAiB,CAAA;IACjB,mDAAiB,CAAA;AACnB,CAAC,EAJW,8BAA8B,KAA9B,8BAA8B,QAIzC","sourcesContent":["import { TypeDescriptor } from './types.js'\n\nexport interface InternalMoveModule {\n address: string\n name: string\n exposedFunctions: InternalMoveFunction[]\n structs: InternalMoveStruct[]\n}\n\nexport interface InternalMoveFunction {\n name: string\n visibility: InternalMoveFunctionVisibility\n isEntry: boolean\n typeParams: InternalMoveTypeParam[]\n params: TypeDescriptor[]\n return: TypeDescriptor[]\n}\n\nexport interface InternalMoveStruct {\n name: string\n isNative: boolean\n abilities: string[]\n typeParams: InternalMoveTypeParam[]\n fields: InternalMoveStructField[]\n}\n\nexport interface InternalMoveStructField {\n name: string\n type: TypeDescriptor\n}\n\nexport enum InternalMoveFunctionVisibility {\n PRIVATE = 'private',\n PUBLIC = 'public',\n FRIEND = 'friend',\n}\n\nexport type InternalMoveTypeParam = {\n constraints: string[]\n}\n"]}
|
package/lib/move/ts-type.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { normalizeToJSName, SPLITTER, VECTOR_STR } from './utils.js';
|
|
2
2
|
export function generateTypeForDescriptor(type, currentAddress, addressType) {
|
|
3
|
-
// TODO &signer is defintely an address, but what if &OTHER_TYPE?
|
|
4
3
|
if (type.qname.startsWith('&')) {
|
|
5
|
-
|
|
6
|
-
return addressType;
|
|
4
|
+
throw Error('Unexpected &');
|
|
7
5
|
}
|
|
8
6
|
if (type.reference) {
|
|
9
7
|
return addressType;
|
package/lib/move/ts-type.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ts-type.js","sourceRoot":"","sources":["../../src/move/ts-type.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEpE,MAAM,UAAU,yBAAyB,CAAC,IAAoB,EAAE,cAAsB,EAAE,WAAmB;IACzG,
|
|
1
|
+
{"version":3,"file":"ts-type.js","sourceRoot":"","sources":["../../src/move/ts-type.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEpE,MAAM,UAAU,yBAAyB,CAAC,IAAoB,EAAE,cAAsB,EAAE,WAAmB;IACzG,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QAC9B,MAAM,KAAK,CAAC,cAAc,CAAC,CAAA;KAC5B;IACD,IAAI,IAAI,CAAC,SAAS,EAAE;QAClB,OAAO,WAAW,CAAA;KACnB;IAED,QAAQ,IAAI,CAAC,KAAK,EAAE;QAClB,KAAK,QAAQ,CAAC,CAAC,kBAAkB;QACjC,KAAK,SAAS,CAAC;QACf,KAAK,SAAS;YACZ,OAAO,WAAW,CAAA;QACpB,KAAK,iBAAiB,CAAC;QACvB,KAAK,iBAAiB;YACpB,OAAO,QAAQ,CAAA;QACjB,KAAK,qBAAqB;YACxB,OAAO,QAAQ,CAAA;QACjB,KAAK,MAAM,CAAC;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BAAoB;QACpB,OAAO,CACL,UAAU;YACV,GAAG;YACH,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,yBAAyB,CAAC,CAAC,EAAE,cAAc,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;YAC7F,GAAG,CACJ,CAAA;KACF;IACD,OAAO,UAAU,CAAA;AACnB,CAAC;AAED,SAAS,kBAAkB,CAAC,IAAY,EAAE,cAAsB;IAC9D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;IAElC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACrC,KAAK,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;KACvC;IAED,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;QACpB,OAAO,KAAK,CAAC,CAAC,CAAC,CAAA;KAChB;IACD,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,cAAc,EAAE;QAC/B,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;KAChC;IACD,OAAO,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC9B,CAAC","sourcesContent":["import { TypeDescriptor } from './types.js'\nimport { normalizeToJSName, SPLITTER, VECTOR_STR } from './utils.js'\n\nexport function generateTypeForDescriptor(type: TypeDescriptor, currentAddress: string, addressType: string): string {\n if (type.qname.startsWith('&')) {\n throw Error('Unexpected &')\n }\n if (type.reference) {\n return addressType\n }\n\n switch (type.qname) {\n case 'signer': // TODO check this\n case 'address':\n case 'Address':\n return addressType\n case '0x2::object::ID':\n case '0x2::coin::Coin':\n return 'string'\n case '0x1::string::String':\n return 'string'\n case 'bool':\n case 'Bool':\n return 'Boolean'\n case 'u8':\n case 'U8':\n case 'u16':\n case 'U16':\n case 'u32':\n case 'U32':\n return 'number'\n case 'u64':\n case 'U64':\n case 'u128':\n case 'U128':\n return 'bigint'\n }\n\n if (type.qname.toLowerCase() === VECTOR_STR) {\n // vector<u8> as hex string\n const elementTypeQname = type.typeArgs[0].qname\n if (elementTypeQname === 'u8' || 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, addressType) + '[]'\n }\n\n const simpleName = generateSimpleType(type.qname, currentAddress)\n if (simpleName.length === 0) {\n console.error('unexpected error')\n }\n if (simpleName.toLowerCase().includes(VECTOR_STR)) {\n console.error('unexpected vector type error')\n }\n if (type.typeArgs.length > 0) {\n // return simpleName\n return (\n simpleName +\n '<' +\n type.typeArgs.map((t) => generateTypeForDescriptor(t, currentAddress, addressType)).join(',') +\n '>'\n )\n }\n return simpleName\n}\n\nfunction generateSimpleType(type: string, currentAddress: string): string {\n const parts = type.split(SPLITTER)\n\n for (let i = 0; i < parts.length; i++) {\n parts[i] = normalizeToJSName(parts[i])\n }\n\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"]}
|
package/lib/move/types.d.ts
CHANGED
package/lib/move/types.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { SPLITTER, VECTOR_STR } from './utils.js';
|
|
2
2
|
export class TypeDescriptor {
|
|
3
|
-
// type: string
|
|
4
|
-
// TODO add reference flag
|
|
5
|
-
// qualified name without type parameters
|
|
6
3
|
qname;
|
|
7
4
|
reference;
|
|
8
|
-
|
|
9
|
-
// module?: string
|
|
5
|
+
mutable;
|
|
10
6
|
typeArgs;
|
|
11
7
|
constructor(symbol, typeParams) {
|
|
12
8
|
this.qname = symbol;
|
|
9
|
+
this.reference = false;
|
|
10
|
+
this.mutable = false;
|
|
13
11
|
this.typeArgs = typeParams || [];
|
|
14
12
|
}
|
|
15
13
|
getSignature() {
|
|
@@ -84,16 +82,14 @@ export class TypeDescriptor {
|
|
|
84
82
|
}
|
|
85
83
|
}
|
|
86
84
|
export function parseMoveType(type) {
|
|
87
|
-
// type = type.replace('&', '')
|
|
88
|
-
type = type.replaceAll('&mut ', '&');
|
|
89
|
-
type = type.replaceAll('mut ', '');
|
|
90
|
-
// TODO replace ' ' is not exactly safe, need to double check this
|
|
91
|
-
type = type.replaceAll(' ', '');
|
|
92
85
|
const stack = [new TypeDescriptor('')];
|
|
93
86
|
let buffer = [];
|
|
94
87
|
// xxx:asdf<g1<a,<c,d>>, b, g2<a,b>, e>
|
|
95
88
|
for (let i = 0; i < type.length; i++) {
|
|
96
89
|
const ch = type[i];
|
|
90
|
+
if (ch === ' ') {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
97
93
|
if (ch === '<') {
|
|
98
94
|
// const symbol = type.slice(symbolStart, i)
|
|
99
95
|
// symbolStart =
|
|
@@ -104,7 +100,7 @@ export function parseMoveType(type) {
|
|
|
104
100
|
stack.push(new TypeDescriptor(''));
|
|
105
101
|
continue;
|
|
106
102
|
}
|
|
107
|
-
if (ch === '>') {
|
|
103
|
+
if (ch === '>' || ch === ',') {
|
|
108
104
|
const typeParam = stack.pop();
|
|
109
105
|
if (!typeParam) {
|
|
110
106
|
throw Error('Unexpected stack size');
|
|
@@ -115,21 +111,9 @@ export function parseMoveType(type) {
|
|
|
115
111
|
}
|
|
116
112
|
adjustType(typeParam);
|
|
117
113
|
stack[stack.length - 1].typeArgs.push(typeParam);
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (ch === ',') {
|
|
121
|
-
const typeParam = stack.pop();
|
|
122
|
-
if (!typeParam) {
|
|
123
|
-
throw Error('Unexpected stack size');
|
|
114
|
+
if (ch === ',') {
|
|
115
|
+
stack.push(new TypeDescriptor(''));
|
|
124
116
|
}
|
|
125
|
-
if (buffer.length > 0) {
|
|
126
|
-
typeParam.qname = buffer.join('');
|
|
127
|
-
buffer = [];
|
|
128
|
-
}
|
|
129
|
-
adjustType(typeParam);
|
|
130
|
-
stack[stack.length - 1].typeArgs.push(typeParam);
|
|
131
|
-
// continue parse next param
|
|
132
|
-
stack.push(new TypeDescriptor(''));
|
|
133
117
|
continue;
|
|
134
118
|
}
|
|
135
119
|
buffer.push(ch);
|
|
@@ -149,5 +133,9 @@ function adjustType(type) {
|
|
|
149
133
|
type.reference = true;
|
|
150
134
|
type.qname = type.qname.slice(1);
|
|
151
135
|
}
|
|
136
|
+
if (type.qname.startsWith('mut')) {
|
|
137
|
+
type.mutable = true;
|
|
138
|
+
type.qname = type.qname.slice(3);
|
|
139
|
+
}
|
|
152
140
|
}
|
|
153
141
|
//# sourceMappingURL=types.js.map
|
package/lib/move/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/move/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEjD,MAAM,OAAO,cAAc;IACzB,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/move/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEjD,MAAM,OAAO,cAAc;IACzB,KAAK,CAAQ;IACb,SAAS,CAAS;IAClB,OAAO,CAAS;IAChB,QAAQ,CAAkB;IAE1B,YAAY,MAAc,EAAE,UAA6B;QACvD,IAAI,CAAC,KAAK,GAAG,MAAM,CAAA;QACnB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAA;QACtB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;QACpB,IAAI,CAAC,QAAQ,GAAG,UAAU,IAAI,EAAE,CAAA;IAClC,CAAC;IAED,YAAY;QACV,IAAI,IAAI,CAA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D,SAAQ;SACT;QACD,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;IACD,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAA;IAEnC,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,EAAE,CAAA;IACvB,IAAI,CAAC,GAAG,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;QAC5B,MAAM,KAAK,CAAC,uBAAuB,CAAC,CAAA;KACrC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,SAAS,UAAU,CAAC,IAAoB;IACtC,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QAC9B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAA;QACrB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;KACjC;IACD,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;QAChC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QACnB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;KACjC;AACH,CAAC","sourcesContent":["import { SPLITTER, VECTOR_STR } from './utils.js'\n\nexport class TypeDescriptor {\n qname: string\n reference: boolean\n mutable: boolean\n typeArgs: TypeDescriptor[]\n\n constructor(symbol: string, typeParams?: TypeDescriptor[]) {\n this.qname = symbol\n this.reference = false\n this.mutable = false\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 console.error('Not expected &')\n return []\n }\n if (this.reference) {\n return []\n }\n switch (this.qname) {\n case 'signer':\n case 'address':\n case 'Address':\n case '0x1::string::String':\n case 'bool':\n case 'Bool':\n case 'u8':\n case 'U8':\n case 'u16':\n case 'U16':\n case 'u32':\n case 'U32':\n case 'u64':\n case 'U64':\n case 'u128':\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 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 continue\n }\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 adjustType(stack[stack.length - 1])\n stack.push(new TypeDescriptor(''))\n continue\n }\n if (ch === '>' || ch === ',') {\n const typeParam = stack.pop()\n if (!typeParam) {\n throw Error('Unexpected stack size')\n }\n if (buffer.length > 0) {\n typeParam.qname = buffer.join('')\n buffer = []\n }\n adjustType(typeParam)\n stack[stack.length - 1].typeArgs.push(typeParam)\n if (ch === ',') {\n stack.push(new TypeDescriptor(''))\n }\n continue\n }\n buffer.push(ch)\n }\n\n if (buffer.length > 0) {\n stack[stack.length - 1].qname = buffer.join('')\n }\n adjustType(stack[stack.length - 1])\n\n const res = stack.pop()\n if (!res || stack.length > 0) {\n throw Error('Unexpected stack size')\n }\n return res\n}\n\nfunction adjustType(type: TypeDescriptor) {\n if (type.qname.startsWith('&')) {\n type.reference = true\n type.qname = type.qname.slice(1)\n }\n if (type.qname.startsWith('mut')) {\n type.mutable = true\n type.qname = type.qname.slice(3)\n }\n}\n"]}
|
|
@@ -3,14 +3,14 @@ import * as fs from 'fs';
|
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import { AbstractCodegen } from '../../move/abstract-codegen.js';
|
|
5
5
|
import { JsonRpcProvider } from '@mysten/sui.js';
|
|
6
|
-
import {
|
|
6
|
+
import { toInternalModule } from '../move-types.js';
|
|
7
7
|
import { moduleQname, SPLITTER } from '../../move/index.js';
|
|
8
8
|
export async function codegen(abisDir, outDir = 'src/types/sui') {
|
|
9
9
|
if (!fs.existsSync(abisDir)) {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
12
|
console.log(chalk.green('Generated Types for Sui'));
|
|
13
|
-
const gen = new
|
|
13
|
+
const gen = new SuiCodegen();
|
|
14
14
|
await gen.generate(abisDir, outDir);
|
|
15
15
|
}
|
|
16
16
|
function getRpcEndpoint(network) {
|
|
@@ -23,7 +23,7 @@ function getRpcEndpoint(network) {
|
|
|
23
23
|
function getRpcClient(network) {
|
|
24
24
|
return new JsonRpcProvider(getRpcEndpoint(network));
|
|
25
25
|
}
|
|
26
|
-
class
|
|
26
|
+
class SuiCodegen extends AbstractCodegen {
|
|
27
27
|
ADDRESS_TYPE = 'SuiAddress';
|
|
28
28
|
MAIN_NET = SuiNetwork.MAIN_NET;
|
|
29
29
|
TEST_NET = SuiNetwork.TEST_NET;
|
|
@@ -36,8 +36,8 @@ class SuiCodeGen extends AbstractCodegen {
|
|
|
36
36
|
getMeaningfulFunctionParams(params) {
|
|
37
37
|
return params.slice(0, params.length - 1);
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
return Object.values(modules).map(
|
|
39
|
+
toInternalModules(modules) {
|
|
40
|
+
return Object.values(modules).map(toInternalModule);
|
|
41
41
|
}
|
|
42
42
|
getEventStructs(module) {
|
|
43
43
|
const qname = moduleQname(module);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../../src/sui/codegen/codegen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,eAAe,EAA4B,MAAM,gBAAgB,CAAA;AAC1E,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../../src/sui/codegen/codegen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,eAAe,EAA4B,MAAM,gBAAgB,CAAA;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAkB,MAAM,qBAAqB,CAAA;AAE3E,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,OAAe,EAAE,MAAM,GAAG,eAAe;I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,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,CAAA;QACjC,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA8B,CAAA;QAEtD,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE;YACnC,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;YAC3C,IAAI,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;gBAClD,QAAQ,CAAC,GAAG,CAAC,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;aACrD;SACF;QACD,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,eAAe,CAAC,QAAgB;QAC9B,MAAM,GAAG,GAAG,KAAK,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAA;QAC3C,IAAI,GAAG,CAAC,MAAM,EAAE;YACd,OAAO,GAAG,CAAC,MAAM,CAAA;SAClB;QACD,OAAO,GAAG,CAAA;IACZ,CAAC;CACF","sourcesContent":["import { SuiNetwork } from '../network.js'\nimport * as fs from 'fs'\nimport chalk from 'chalk'\nimport { InternalMoveModule, InternalMoveStruct } from '../../move/internal-models.js'\nimport { AbstractCodegen } from '../../move/abstract-codegen.js'\nimport { JsonRpcProvider, SuiMoveNormalizedModules } from '@mysten/sui.js'\nimport { toInternalModule } from '../move-types.js'\nimport { moduleQname, SPLITTER, TypeDescriptor } from '../../move/index.js'\n\nexport async function codegen(abisDir: string, outDir = 'src/types/sui') {\n if (!fs.existsSync(abisDir)) {\n return\n }\n console.log(chalk.green('Generated Types for Sui'))\n const gen = new SuiCodegen()\n await gen.generate(abisDir, outDir)\n}\n\nfunction getRpcEndpoint(network: SuiNetwork): string {\n switch (network) {\n case SuiNetwork.TEST_NET:\n return 'https://fullnode.testnet.sui.io/'\n }\n return 'https://fullnode.mainnet.sui.io/'\n}\n\nfunction getRpcClient(network: SuiNetwork): JsonRpcProvider {\n return new JsonRpcProvider(getRpcEndpoint(network))\n}\n\nclass SuiCodegen extends AbstractCodegen<SuiMoveNormalizedModules, SuiNetwork> {\n ADDRESS_TYPE = 'SuiAddress'\n MAIN_NET = SuiNetwork.MAIN_NET\n TEST_NET = SuiNetwork.TEST_NET\n PREFIX = 'Sui'\n STRUCT_FIELD_NAME = 'fields'\n\n async fetchModules(account: string, network: SuiNetwork): Promise<SuiMoveNormalizedModules> {\n const client = getRpcClient(network)\n return await client.getNormalizedMoveModulesByPackage(account)\n }\n\n getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {\n return params.slice(0, params.length - 1)\n }\n\n toInternalModules(modules: SuiMoveNormalizedModules): InternalMoveModule[] {\n return Object.values(modules).map(toInternalModule)\n }\n\n getEventStructs(module: InternalMoveModule) {\n const qname = moduleQname(module)\n const eventMap = new Map<string, InternalMoveStruct>()\n\n for (const struct of module.structs) {\n const abilities = new Set(struct.abilities)\n if (abilities.has('Drop') && abilities.has('Copy')) {\n eventMap.set(qname + SPLITTER + struct.name, struct)\n }\n }\n return eventMap\n }\n\n readModulesFile(fullPath: string) {\n const res = super.readModulesFile(fullPath)\n if (res.result) {\n return res.result\n }\n return res\n }\n}\n"]}
|
package/lib/sui/move-coder.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { AbstractMoveCoder } from '../move/abstract-move-coder.js';
|
|
2
|
-
import {
|
|
2
|
+
import { toInternalModule } from './move-types.js';
|
|
3
3
|
import { SPLITTER } from '../move/index.js';
|
|
4
4
|
export class MoveCoder extends AbstractMoveCoder {
|
|
5
5
|
load(module) {
|
|
6
6
|
if (this.contains(module.address, module.name)) {
|
|
7
7
|
return;
|
|
8
8
|
}
|
|
9
|
-
this.
|
|
9
|
+
this.loadInternal(toInternalModule(module));
|
|
10
10
|
}
|
|
11
11
|
decodeEvent(event) {
|
|
12
12
|
const res = this.decodedInternal({ ...event, data: event.fields });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"move-coder.js","sourceRoot":"","sources":["../../src/sui/move-coder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAElE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"move-coder.js","sourceRoot":"","sources":["../../src/sui/move-coder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAElE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAE3C,MAAM,OAAO,SAAU,SAAQ,iBAA4B;IACzD,IAAI,CAAC,MAA+B;QAClC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE;YAC9C,OAAM;SACP;QACD,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAA;IAC7C,CAAC;IAED,WAAW,CAAI,KAAgB;QAC7B,MAAM,GAAG,GAAG,IAAI,CAAC,eAAe,CAAI,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAA;QACrE,OAAO,EAAE,GAAG,KAAK,EAAE,cAAc,EAAE,GAAG,EAAE,YAAiB,EAAE,cAAc,EAAE,GAAG,EAAE,cAAc,IAAI,EAAE,EAAE,CAAA;IACxG,CAAC;IACD,qBAAqB,CAAI,SAAiB,EAAE,SAAsB;QAChE,MAAM,IAAI,GAAG,IAAI,CAAC,uBAAuB,CACvC,SAAS,EACT,SAAS,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YACtB,OAAO,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAA;QAC3D,CAAC,CAAC,CACH,CAAA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AG,OAAO;YACV,iBAAiB,EAAE,cAAc;SACA,CAAA;IACrC,CAAC;CACF;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,SAAS,EAAE,CAAA;AAEzC,MAAM,UAAU,gBAAgB;IAC9B,OAAO,UAAU,CAAA;AACnB,CAAC","sourcesContent":["import { TypedEventInstance, TypedEntryFunctionPayload } from './models.js'\nimport { AbstractMoveCoder } from '../move/abstract-move-coder.js'\nimport { MoveCall, MoveEvent, SuiMoveNormalizedModule } from '@mysten/sui.js'\nimport { toInternalModule } from './move-types.js'\nimport { SPLITTER } from '../move/index.js'\n\nexport class MoveCoder extends AbstractMoveCoder<MoveEvent> {\n load(module: SuiMoveNormalizedModule) {\n if (this.contains(module.address, module.name)) {\n return\n }\n this.loadInternal(toInternalModule(module))\n }\n\n decodeEvent<T>(event: MoveEvent): TypedEventInstance<T> | undefined {\n const res = this.decodedInternal<T>({ ...event, data: event.fields })\n return { ...event, fields_decoded: res?.data_decoded as T, type_arguments: res?.type_arguments || [] }\n }\n filterAndDecodeEvents<T>(typeQname: string, resources: MoveEvent[]): TypedEventInstance<T>[] {\n const resp = this.filterAndDecodeInternal(\n typeQname,\n resources.map((event) => {\n return { ...event, data: event.fields, type: event.type }\n })\n )\n return resp.map((res) => {\n delete res.data_decoded\n const event = res as MoveEvent\n return { ...event, fields_decoded: res?.data_decoded as T, type_arguments: res?.type_arguments || [] }\n })\n }\n\n decodeFunctionPayload(payload: MoveCall): MoveCall {\n // this.loadTypes(registry)\n const argumentsTyped: any[] = []\n\n try {\n const functionType = [payload.package.objectId, payload.module, payload.function].join(SPLITTER)\n const func = this.getMoveFunction(functionType)\n const params = func.params.slice(0, func.params.length - 1)\n const args = payload.arguments || []\n for (const [idx, arg] of args.entries()) {\n // TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them\n const argType = params[idx]\n argumentsTyped.push(this.decode(arg, argType))\n }\n } catch (e) {\n console.error('Decoding error for ', JSON.stringify(payload), e)\n return payload\n }\n\n return {\n ...payload,\n arguments_decoded: argumentsTyped,\n } as TypedEntryFunctionPayload<any>\n }\n}\n\nexport const MOVE_CODER = new MoveCoder()\n\nexport function defaultMoveCoder(): MoveCoder {\n return MOVE_CODER\n}\n"]}
|
package/lib/sui/move-types.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { SuiMoveNormalizedField, SuiMoveNormalizedFunction, SuiMoveNormalizedModule, SuiMoveNormalizedStruct, SuiMoveNormalizedType } from '@mysten/sui.js';
|
|
2
|
-
import {
|
|
1
|
+
import type { SuiMoveNormalizedField, SuiMoveNormalizedFunction, SuiMoveNormalizedModule, SuiMoveNormalizedStruct, SuiMoveNormalizedType } from '@mysten/sui.js';
|
|
2
|
+
import { InternalMoveFunction, InternalMoveModule, InternalMoveStruct, InternalMoveStructField } from '../move/internal-models.js';
|
|
3
3
|
import { TypeDescriptor } from '../move/index.js';
|
|
4
4
|
export type { SuiAddress } from '@mysten/sui.js';
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function
|
|
5
|
+
export declare function toInternalModule(module: SuiMoveNormalizedModule): InternalMoveModule;
|
|
6
|
+
export declare function toInternalFunction(name: string, func: SuiMoveNormalizedFunction): InternalMoveFunction;
|
|
7
|
+
export declare function toInternalStruct(name: string, struct: SuiMoveNormalizedStruct): InternalMoveStruct;
|
|
8
|
+
export declare function toInternalField(module: SuiMoveNormalizedField): InternalMoveStructField;
|
|
9
|
+
export declare function toTypeDescriptor(normalizedType: SuiMoveNormalizedType): TypeDescriptor;
|
package/lib/sui/move-types.js
CHANGED
|
@@ -1,79 +1,80 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InternalMoveFunctionVisibility, } from '../move/internal-models.js';
|
|
2
2
|
import { SPLITTER, TypeDescriptor } from '../move/index.js';
|
|
3
|
-
export function
|
|
3
|
+
export function toInternalModule(module) {
|
|
4
4
|
return {
|
|
5
5
|
address: module.address,
|
|
6
|
-
|
|
6
|
+
exposedFunctions: Object.entries(module.exposed_functions).map(([n, f]) => toInternalFunction(n, f)),
|
|
7
7
|
name: module.name,
|
|
8
|
-
structs: Object.entries(module.structs).map(([n, s]) =>
|
|
8
|
+
structs: Object.entries(module.structs).map(([n, s]) => toInternalStruct(n, s)),
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
-
export function
|
|
11
|
+
export function toInternalFunction(name, func) {
|
|
12
12
|
let visibility;
|
|
13
13
|
switch (func.visibility) {
|
|
14
14
|
case 'Private':
|
|
15
|
-
visibility =
|
|
15
|
+
visibility = InternalMoveFunctionVisibility.PRIVATE;
|
|
16
16
|
break;
|
|
17
17
|
case 'Public':
|
|
18
|
-
visibility =
|
|
18
|
+
visibility = InternalMoveFunctionVisibility.PUBLIC;
|
|
19
19
|
break;
|
|
20
20
|
case 'Friend':
|
|
21
|
-
visibility =
|
|
21
|
+
visibility = InternalMoveFunctionVisibility.FRIEND;
|
|
22
22
|
break;
|
|
23
|
+
default:
|
|
24
|
+
throw Error('No visibility for function' + name);
|
|
23
25
|
}
|
|
24
26
|
return {
|
|
25
|
-
|
|
27
|
+
typeParams: func.type_parameters.map((p) => {
|
|
26
28
|
return { constraints: p.abilities };
|
|
27
29
|
}),
|
|
28
|
-
|
|
30
|
+
isEntry: func.is_entry,
|
|
29
31
|
name: name,
|
|
30
|
-
params: func.parameters.map(
|
|
31
|
-
return: func.return_.map(
|
|
32
|
+
params: func.parameters.map(toTypeDescriptor),
|
|
33
|
+
return: func.return_.map(toTypeDescriptor),
|
|
32
34
|
visibility: visibility,
|
|
33
35
|
};
|
|
34
36
|
}
|
|
35
|
-
export function
|
|
37
|
+
export function toInternalStruct(name, struct) {
|
|
36
38
|
return {
|
|
37
39
|
abilities: struct.abilities.abilities,
|
|
38
|
-
fields: struct.fields.map(
|
|
39
|
-
|
|
40
|
+
fields: struct.fields.map(toInternalField),
|
|
41
|
+
typeParams: struct.type_parameters.map((p) => {
|
|
40
42
|
return { constraints: p.constraints.abilities };
|
|
41
43
|
}),
|
|
42
|
-
|
|
44
|
+
isNative: false,
|
|
43
45
|
name: name,
|
|
44
46
|
};
|
|
45
47
|
}
|
|
46
|
-
export function
|
|
48
|
+
export function toInternalField(module) {
|
|
47
49
|
return {
|
|
48
50
|
name: module.name,
|
|
49
|
-
type:
|
|
51
|
+
type: toTypeDescriptor(module.type_),
|
|
50
52
|
};
|
|
51
53
|
}
|
|
52
|
-
export function
|
|
54
|
+
export function toTypeDescriptor(normalizedType) {
|
|
53
55
|
if (typeof normalizedType === 'string') {
|
|
54
56
|
return new TypeDescriptor(normalizedType);
|
|
55
57
|
}
|
|
56
58
|
if ('Struct' in normalizedType) {
|
|
57
|
-
// normalizedType.Struct.
|
|
58
|
-
// return normalizedType;
|
|
59
59
|
const qname = [normalizedType.Struct.address, normalizedType.Struct.module, normalizedType.Struct.name].join(SPLITTER);
|
|
60
|
-
const args = normalizedType.Struct.type_arguments.map(
|
|
60
|
+
const args = normalizedType.Struct.type_arguments.map(toTypeDescriptor);
|
|
61
61
|
return new TypeDescriptor(qname, args);
|
|
62
62
|
}
|
|
63
63
|
if ('Vector' in normalizedType) {
|
|
64
|
-
return new TypeDescriptor('vector', [
|
|
64
|
+
return new TypeDescriptor('vector', [toTypeDescriptor(normalizedType.Vector)]);
|
|
65
65
|
}
|
|
66
66
|
if ('TypeParameter' in normalizedType) {
|
|
67
67
|
return new TypeDescriptor('T' + normalizedType.TypeParameter);
|
|
68
68
|
}
|
|
69
69
|
if ('Reference' in normalizedType) {
|
|
70
|
-
const res =
|
|
70
|
+
const res = toTypeDescriptor(normalizedType.Reference);
|
|
71
71
|
res.reference = true;
|
|
72
72
|
return res;
|
|
73
73
|
}
|
|
74
74
|
if ('MutableReference' in normalizedType) {
|
|
75
|
-
const res =
|
|
75
|
+
const res = toTypeDescriptor(normalizedType.MutableReference);
|
|
76
76
|
res.reference = true;
|
|
77
|
+
res.mutable = true;
|
|
77
78
|
return res;
|
|
78
79
|
}
|
|
79
80
|
throw new Error('Unexpected sui type');
|