@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":"move-types.js","sourceRoot":"","sources":["../../src/sui/move-types.ts"],"names":[],"mappings":"AAOA,OAAO,EAEL,
|
|
1
|
+
{"version":3,"file":"move-types.js","sourceRoot":"","sources":["../../src/sui/move-types.ts"],"names":[],"mappings":"AAOA,OAAO,EAEL,8BAA8B,GAI/B,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAI3D,MAAM,UAAU,gBAAgB,CAAC,MAA+B;IAC9D,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,gBAAgB,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACpG,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;KAChF,CAAA;AACH,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAE,IAA+B;IAC9E,IAAI,UAAU,CAAA;IACd,QAAQ,IAAI,CAAC,UAAU,EAAE;QACvB,KAAK,SAAS;YACZ,UAAU,GAAG,8BAA8B,CAAC,OAAO,CAA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\n SuiMoveNormalizedField,\n SuiMoveNormalizedFunction,\n SuiMoveNormalizedModule,\n SuiMoveNormalizedStruct,\n SuiMoveNormalizedType,\n} from '@mysten/sui.js'\nimport {\n InternalMoveFunction,\n InternalMoveFunctionVisibility,\n InternalMoveModule,\n InternalMoveStruct,\n InternalMoveStructField,\n} from '../move/internal-models.js'\nimport { SPLITTER, TypeDescriptor } from '../move/index.js'\n\nexport type { SuiAddress } from '@mysten/sui.js'\n\nexport function toInternalModule(module: SuiMoveNormalizedModule): InternalMoveModule {\n return {\n address: module.address,\n exposedFunctions: Object.entries(module.exposed_functions).map(([n, f]) => toInternalFunction(n, f)),\n name: module.name,\n structs: Object.entries(module.structs).map(([n, s]) => toInternalStruct(n, s)),\n }\n}\n\nexport function toInternalFunction(name: string, func: SuiMoveNormalizedFunction): InternalMoveFunction {\n let visibility\n switch (func.visibility) {\n case 'Private':\n visibility = InternalMoveFunctionVisibility.PRIVATE\n break\n case 'Public':\n visibility = InternalMoveFunctionVisibility.PUBLIC\n break\n case 'Friend':\n visibility = InternalMoveFunctionVisibility.FRIEND\n break\n default:\n throw Error('No visibility for function' + name)\n }\n return {\n typeParams: func.type_parameters.map((p: any) => {\n return { constraints: p.abilities }\n }),\n isEntry: func.is_entry,\n name: name,\n params: func.parameters.map(toTypeDescriptor),\n return: func.return_.map(toTypeDescriptor),\n visibility: visibility,\n }\n}\n\nexport function toInternalStruct(name: string, struct: SuiMoveNormalizedStruct): InternalMoveStruct {\n return {\n abilities: struct.abilities.abilities,\n fields: struct.fields.map(toInternalField),\n typeParams: struct.type_parameters.map((p: any) => {\n return { constraints: p.constraints.abilities }\n }),\n isNative: false,\n name: name,\n }\n}\n\nexport function toInternalField(module: SuiMoveNormalizedField): InternalMoveStructField {\n return {\n name: module.name,\n type: toTypeDescriptor(module.type_),\n }\n}\n\nexport function toTypeDescriptor(normalizedType: SuiMoveNormalizedType): TypeDescriptor {\n if (typeof normalizedType === 'string') {\n return new TypeDescriptor(normalizedType)\n }\n\n if ('Struct' in normalizedType) {\n const qname = [normalizedType.Struct.address, normalizedType.Struct.module, normalizedType.Struct.name].join(\n SPLITTER\n )\n\n const args = normalizedType.Struct.type_arguments.map(toTypeDescriptor)\n\n return new TypeDescriptor(qname, args)\n }\n\n if ('Vector' in normalizedType) {\n return new TypeDescriptor('vector', [toTypeDescriptor(normalizedType.Vector)])\n }\n if ('TypeParameter' in normalizedType) {\n return new TypeDescriptor('T' + normalizedType.TypeParameter)\n }\n\n if ('Reference' in normalizedType) {\n const res = toTypeDescriptor(normalizedType.Reference)\n res.reference = true\n return res\n }\n\n if ('MutableReference' in normalizedType) {\n const res = toTypeDescriptor(normalizedType.MutableReference)\n res.reference = true\n res.mutable = true\n return res\n }\n\n throw new Error('Unexpected sui type')\n}\n"]}
|
package/lib/sui/utils.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { SuiTransactionResponse
|
|
2
|
-
export declare function getMoveCalls(tx: SuiTransactionResponse):
|
|
1
|
+
import { SuiTransactionResponse } from '@mysten/sui.js';
|
|
2
|
+
export declare function getMoveCalls(tx: SuiTransactionResponse): any;
|
package/lib/sui/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/sui/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,sBAAsB,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/sui/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,sBAAsB,EAAsB,MAAM,gBAAgB,CAAA;AAEnG,MAAM,UAAU,YAAY,CAAC,EAA0B;IACrD,OAAO,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,EAAsB,EAAE,EAAE;QACzE,MAAM,IAAI,GAAG,sBAAsB,CAAC,EAAE,CAAC,CAAA;QACvC,IAAI,IAAI,EAAE;YACR,OAAO,CAAC,IAAI,CAAC,CAAA;SACd;QACD,OAAO,EAAE,CAAA;IACX,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import { SuiTransactionResponse, getMoveCallTransaction, SuiTransactionKind } from '@mysten/sui.js'\n\nexport function getMoveCalls(tx: SuiTransactionResponse) {\n return tx.certificate.data.transactions.flatMap((tx: SuiTransactionKind) => {\n const call = getMoveCallTransaction(tx)\n if (call) {\n return [call]\n }\n return []\n })\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentio/sdk",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "2.5.
|
|
4
|
+
"version": "2.5.1-rc.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"compile": "tsc && cp src/utils/*.csv lib/utils && cp src/tsup.config.ts lib",
|
|
@@ -19,13 +19,13 @@
|
|
|
19
19
|
"docs": "typedoc --options typedoc.json"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@mysten/sui.js": "npm:@sentio/sui.js@0.
|
|
22
|
+
"@mysten/sui.js": "npm:@sentio/sui.js@0.27.0",
|
|
23
23
|
"@project-serum/anchor": "^0.26.0",
|
|
24
24
|
"@sentio/bigdecimal": "^9.1.1-patch.3",
|
|
25
25
|
"@sentio/ethers-v6": "^1.0.25",
|
|
26
|
-
"@sentio/protos": "^2.5.
|
|
27
|
-
"@sentio/runtime": "^2.5.
|
|
28
|
-
"@solana/web3.js": "^1.
|
|
26
|
+
"@sentio/protos": "^2.5.1-rc.1",
|
|
27
|
+
"@sentio/runtime": "^2.5.1-rc.1",
|
|
28
|
+
"@solana/web3.js": "^1.73.2",
|
|
29
29
|
"@types/prettier": "^2.7.2",
|
|
30
30
|
"aptos-sdk": "npm:@sentio/aptos@^1.6.0",
|
|
31
31
|
"bs58": "^5.0.0",
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
"ethers": "npm:@sentio/ethers@^6.0.2",
|
|
35
35
|
"lodash-es": "^4.17.21",
|
|
36
36
|
"mkdirp": "^2.1.3",
|
|
37
|
-
"p-queue": "^7.3.
|
|
38
|
-
"prettier": "^2.8.
|
|
37
|
+
"p-queue": "^7.3.4",
|
|
38
|
+
"prettier": "^2.8.4",
|
|
39
39
|
"typechain": "^8.0.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@certusone/wormhole-sdk": "^0.9.
|
|
42
|
+
"@certusone/wormhole-sdk": "^0.9.10",
|
|
43
43
|
"@types/google-protobuf": "^3.15.6",
|
|
44
44
|
"@types/lodash-es": "^4.17.6"
|
|
45
45
|
},
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"typedoc": {
|
|
82
82
|
"entryPoint": "./src/index.ts"
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "67085a9cfa83c3c13b3f38cea88970680bd60b5c"
|
|
85
85
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as fs from 'fs'
|
|
2
|
-
import { MoveModuleBytecode,
|
|
2
|
+
import { MoveModuleBytecode, toInternalModule } from '../move-types.js'
|
|
3
3
|
import { moduleQname, SPLITTER, TypeDescriptor } from '../../move/index.js'
|
|
4
4
|
import chalk from 'chalk'
|
|
5
5
|
import { AptosNetwork } from '../network.js'
|
|
6
6
|
import { AptosClient } from 'aptos-sdk'
|
|
7
7
|
import { getMeaningfulFunctionParams } from '../utils.js'
|
|
8
|
-
import {
|
|
8
|
+
import { InternalMoveModule, InternalMoveStruct } from '../../move/internal-models.js'
|
|
9
9
|
import { AbstractCodegen } from '../../move/abstract-codegen.js'
|
|
10
10
|
|
|
11
11
|
export async function codegen(abisDir: string, outDir = 'src/types/aptos') {
|
|
@@ -40,18 +40,18 @@ class AptosCodegen extends AbstractCodegen<MoveModuleBytecode[], AptosNetwork> {
|
|
|
40
40
|
return await client.getAccountModules(account)
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
return modules.flatMap((m) => (m.abi ? [
|
|
43
|
+
toInternalModules(modules: MoveModuleBytecode[]): InternalMoveModule[] {
|
|
44
|
+
return modules.flatMap((m) => (m.abi ? [toInternalModule(m)] : []))
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {
|
|
48
48
|
return getMeaningfulFunctionParams(params)
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
getEventStructs(module:
|
|
51
|
+
getEventStructs(module: InternalMoveModule) {
|
|
52
52
|
const qname = moduleQname(module)
|
|
53
|
-
const structMap = new Map<string,
|
|
54
|
-
const eventMap = new Map<string,
|
|
53
|
+
const structMap = new Map<string, InternalMoveStruct>()
|
|
54
|
+
const eventMap = new Map<string, InternalMoveStruct>()
|
|
55
55
|
|
|
56
56
|
for (const struct of module.structs) {
|
|
57
57
|
structMap.set(qname + SPLITTER + struct.name, struct)
|
package/src/aptos/move-coder.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Event,
|
|
3
|
-
MoveModule,
|
|
4
3
|
MoveModuleBytecode,
|
|
5
4
|
MoveResource,
|
|
6
|
-
|
|
5
|
+
toInternalModule,
|
|
7
6
|
TransactionPayload_EntryFunctionPayload,
|
|
8
7
|
} from './move-types.js'
|
|
9
8
|
|
|
@@ -19,7 +18,7 @@ export class MoveCoder extends AbstractMoveCoder<Event | MoveResource> {
|
|
|
19
18
|
if (this.contains(module.abi.address, module.abi.name)) {
|
|
20
19
|
return
|
|
21
20
|
}
|
|
22
|
-
this.
|
|
21
|
+
this.loadInternal(toInternalModule(module))
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
decodeEvent<T>(event: Event): TypedEventInstance<T> | undefined {
|
package/src/aptos/move-types.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Types } from 'aptos-sdk'
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from '../move/
|
|
3
|
+
InternalMoveFunction,
|
|
4
|
+
InternalMoveFunctionVisibility,
|
|
5
|
+
InternalMoveModule,
|
|
6
|
+
InternalMoveStruct,
|
|
7
|
+
InternalMoveStructField,
|
|
8
|
+
} from '../move/internal-models.js'
|
|
9
9
|
import { parseMoveType } from '../move/index.js'
|
|
10
10
|
|
|
11
11
|
export type Address = Types.Address
|
|
@@ -19,35 +19,35 @@ export type MoveModuleBytecode = Types.MoveModuleBytecode
|
|
|
19
19
|
export type TransactionPayload_EntryFunctionPayload = Types.TransactionPayload_EntryFunctionPayload
|
|
20
20
|
export type Transaction_UserTransaction = Types.Transaction_UserTransaction
|
|
21
21
|
|
|
22
|
-
export function
|
|
22
|
+
export function toInternalModule(module: MoveModuleBytecode): InternalMoveModule {
|
|
23
23
|
if (!module.abi) {
|
|
24
24
|
throw Error('module with no ABI found')
|
|
25
25
|
}
|
|
26
26
|
const abi = module.abi
|
|
27
27
|
return {
|
|
28
28
|
address: abi.address,
|
|
29
|
-
|
|
29
|
+
exposedFunctions: abi.exposed_functions.map(toInternalFunction),
|
|
30
30
|
name: abi.name,
|
|
31
|
-
structs: abi.structs.map(
|
|
31
|
+
structs: abi.structs.map(toInternalStruct),
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export function
|
|
35
|
+
export function toInternalFunction(func: MoveFunction): InternalMoveFunction {
|
|
36
36
|
let visibility
|
|
37
37
|
switch (func.visibility) {
|
|
38
38
|
case Types.MoveFunctionVisibility.PRIVATE:
|
|
39
|
-
visibility =
|
|
39
|
+
visibility = InternalMoveFunctionVisibility.PRIVATE
|
|
40
40
|
break
|
|
41
41
|
case Types.MoveFunctionVisibility.PUBLIC:
|
|
42
|
-
visibility =
|
|
42
|
+
visibility = InternalMoveFunctionVisibility.PUBLIC
|
|
43
43
|
break
|
|
44
44
|
case Types.MoveFunctionVisibility.FRIEND:
|
|
45
|
-
visibility =
|
|
45
|
+
visibility = InternalMoveFunctionVisibility.FRIEND
|
|
46
46
|
break
|
|
47
47
|
}
|
|
48
48
|
return {
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
typeParams: func.generic_type_params,
|
|
50
|
+
isEntry: func.is_entry,
|
|
51
51
|
name: func.name,
|
|
52
52
|
params: func.params.map(parseMoveType),
|
|
53
53
|
return: func.return.map(parseMoveType),
|
|
@@ -55,17 +55,17 @@ export function toNeutralFunction(func: MoveFunction): NeutralMoveFunction {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
export function
|
|
58
|
+
export function toInternalStruct(struct: MoveStruct): InternalMoveStruct {
|
|
59
59
|
return {
|
|
60
60
|
abilities: struct.abilities,
|
|
61
|
-
fields: struct.fields.map(
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
fields: struct.fields.map(toInternalField),
|
|
62
|
+
typeParams: struct.generic_type_params,
|
|
63
|
+
isNative: struct.is_native,
|
|
64
64
|
name: struct.name,
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
export function
|
|
68
|
+
export function toInternalField(module: MoveStructField): InternalMoveStructField {
|
|
69
69
|
return {
|
|
70
70
|
name: module.name,
|
|
71
71
|
type: parseMoveType(module.type),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InternalMoveFunction, InternalMoveModule, InternalMoveStruct } from './internal-models.js'
|
|
2
2
|
import path from 'path'
|
|
3
3
|
import fs from 'fs'
|
|
4
4
|
import { AccountModulesImportInfo, AccountRegister } from './account.js'
|
|
@@ -28,9 +28,11 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
|
28
28
|
STRUCT_FIELD_NAME: string = 'data'
|
|
29
29
|
|
|
30
30
|
abstract fetchModules(account: string, network: NetworkType): Promise<ModuleTypes>
|
|
31
|
-
abstract
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
abstract toInternalModules(modules: ModuleTypes): InternalMoveModule[]
|
|
32
|
+
// Get the structs that represent Events
|
|
33
|
+
abstract getEventStructs(module: InternalMoveModule): Map<string, InternalMoveStruct>
|
|
34
|
+
// Get the parameters that actually have arguments in runtime
|
|
35
|
+
// Aptos first signer and Sui's last TxContext are no use
|
|
34
36
|
abstract getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[]
|
|
35
37
|
|
|
36
38
|
readModulesFile(fullPath: string) {
|
|
@@ -69,7 +71,7 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
|
69
71
|
}
|
|
70
72
|
const fullPath = path.resolve(srcDir, file)
|
|
71
73
|
const abi = this.readModulesFile(fullPath)
|
|
72
|
-
const modules = this.
|
|
74
|
+
const modules = this.toInternalModules(abi)
|
|
73
75
|
|
|
74
76
|
for (const module of modules) {
|
|
75
77
|
loader.register(module, path.basename(file, '.json'))
|
|
@@ -89,7 +91,7 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
|
89
91
|
|
|
90
92
|
try {
|
|
91
93
|
const rawModules = await this.fetchModules(account, network)
|
|
92
|
-
const modules = this.
|
|
94
|
+
const modules = this.toInternalModules(rawModules)
|
|
93
95
|
|
|
94
96
|
fs.writeFileSync(path.resolve(srcDir, account + '.json'), JSON.stringify(rawModules, null, '\t'))
|
|
95
97
|
|
|
@@ -143,8 +145,8 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
|
143
145
|
return 'MAIN_NET'
|
|
144
146
|
}
|
|
145
147
|
|
|
146
|
-
generateModule(module:
|
|
147
|
-
const functions = module.
|
|
148
|
+
generateModule(module: InternalMoveModule, network: NetworkType) {
|
|
149
|
+
const functions = module.exposedFunctions
|
|
148
150
|
.map((f) => this.generateOnEntryFunctions(module, f))
|
|
149
151
|
.filter((s) => s !== '')
|
|
150
152
|
|
|
@@ -154,7 +156,7 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
|
154
156
|
.map((e) => this.generateOnEvents(module, e))
|
|
155
157
|
.filter((s) => s !== '')
|
|
156
158
|
const structs = module.structs.map((s) => this.generateStructs(module, s, eventTypes))
|
|
157
|
-
const callArgs = module.
|
|
159
|
+
const callArgs = module.exposedFunctions.map((f) => this.generateCallArgsStructs(module, f))
|
|
158
160
|
|
|
159
161
|
const moduleName = normalizeToJSName(module.name)
|
|
160
162
|
let processor = ''
|
|
@@ -166,15 +168,15 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
|
166
168
|
}
|
|
167
169
|
static DEFAULT_OPTIONS: ${this.PREFIX}BindOptions = {
|
|
168
170
|
address: "${module.address}",
|
|
169
|
-
network: ${this.PREFIX}Network.${this.generateNetworkOption(network)}
|
|
171
|
+
network: ${this.PREFIX}Network.${this.generateNetworkOption(network)}
|
|
170
172
|
}
|
|
171
173
|
|
|
172
174
|
static bind(options: Partial<${this.PREFIX}BindOptions> = {}): ${moduleName} {
|
|
173
175
|
return new ${moduleName}({ ...${moduleName}.DEFAULT_OPTIONS, ...options })
|
|
174
176
|
}
|
|
175
|
-
|
|
177
|
+
|
|
176
178
|
${functions.join('\n')}
|
|
177
|
-
|
|
179
|
+
|
|
178
180
|
${events.join('\n')}
|
|
179
181
|
}
|
|
180
182
|
`
|
|
@@ -185,13 +187,13 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
|
185
187
|
|
|
186
188
|
export namespace ${moduleName} {
|
|
187
189
|
${structs.join('\n')}
|
|
188
|
-
|
|
190
|
+
|
|
189
191
|
${callArgs.join('\n')}
|
|
190
192
|
}
|
|
191
193
|
`
|
|
192
194
|
}
|
|
193
195
|
|
|
194
|
-
generateStructs(module:
|
|
196
|
+
generateStructs(module: InternalMoveModule, struct: InternalMoveStruct, events: Set<string>) {
|
|
195
197
|
const genericString = this.generateStructTypeParameters(struct)
|
|
196
198
|
const genericStringAny = this.generateStructTypeParameters(struct, true)
|
|
197
199
|
|
|
@@ -205,10 +207,10 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
|
205
207
|
let eventPayload = ''
|
|
206
208
|
if (events.has(moduleQname(module) + SPLITTER + struct.name)) {
|
|
207
209
|
eventPayload = `
|
|
208
|
-
export interface ${structName}Instance extends
|
|
210
|
+
export interface ${structName}Instance extends
|
|
209
211
|
TypedEventInstance<${structName}${genericStringAny}> {
|
|
210
212
|
${this.STRUCT_FIELD_NAME}_decoded: ${structName}${genericStringAny}
|
|
211
|
-
type_arguments: [${struct.
|
|
213
|
+
type_arguments: [${struct.typeParams.map((_) => 'string').join(', ')}]
|
|
212
214
|
}
|
|
213
215
|
`
|
|
214
216
|
}
|
|
@@ -216,17 +218,17 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
|
216
218
|
return `
|
|
217
219
|
export class ${structName}${genericString} {
|
|
218
220
|
static TYPE_QNAME = '${module.address}::${module.name}::${struct.name}'
|
|
219
|
-
${fields.join('\n')}
|
|
221
|
+
${fields.join('\n')}
|
|
220
222
|
}
|
|
221
|
-
|
|
223
|
+
|
|
222
224
|
${eventPayload}
|
|
223
225
|
`
|
|
224
226
|
}
|
|
225
227
|
|
|
226
|
-
generateFunctionTypeParameters(func:
|
|
228
|
+
generateFunctionTypeParameters(func: InternalMoveFunction) {
|
|
227
229
|
let genericString = ''
|
|
228
|
-
if (func.
|
|
229
|
-
const params = func.
|
|
230
|
+
if (func.typeParams && func.typeParams.length > 0) {
|
|
231
|
+
const params = func.typeParams
|
|
230
232
|
.map((v, idx) => {
|
|
231
233
|
return `T${idx}=any`
|
|
232
234
|
})
|
|
@@ -236,11 +238,11 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
|
236
238
|
return genericString
|
|
237
239
|
}
|
|
238
240
|
|
|
239
|
-
generateStructTypeParameters(struct:
|
|
241
|
+
generateStructTypeParameters(struct: InternalMoveStruct, useAny = false) {
|
|
240
242
|
let genericString = ''
|
|
241
243
|
|
|
242
|
-
if (struct.
|
|
243
|
-
const params = struct.
|
|
244
|
+
if (struct.typeParams && struct.typeParams.length > 0) {
|
|
245
|
+
const params = struct.typeParams
|
|
244
246
|
.map((v, idx) => {
|
|
245
247
|
return useAny ? 'any' : 'T' + idx
|
|
246
248
|
})
|
|
@@ -250,8 +252,8 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
|
250
252
|
return genericString
|
|
251
253
|
}
|
|
252
254
|
|
|
253
|
-
generateCallArgsStructs(module:
|
|
254
|
-
if (!func.
|
|
255
|
+
generateCallArgsStructs(module: InternalMoveModule, func: InternalMoveFunction) {
|
|
256
|
+
if (!func.isEntry) {
|
|
255
257
|
return
|
|
256
258
|
}
|
|
257
259
|
|
|
@@ -266,13 +268,13 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
|
266
268
|
export interface ${camelFuncName}Payload${genericString}
|
|
267
269
|
extends TypedEntryFunctionPayload<[${fields.join(',')}]> {
|
|
268
270
|
arguments_decoded: [${fields.join(',')}],
|
|
269
|
-
type_arguments: [${func.
|
|
271
|
+
type_arguments: [${func.typeParams.map((_) => 'string').join(', ')}]
|
|
270
272
|
}
|
|
271
273
|
`
|
|
272
274
|
}
|
|
273
275
|
|
|
274
|
-
generateOnEntryFunctions(module:
|
|
275
|
-
if (!func.
|
|
276
|
+
generateOnEntryFunctions(module: InternalMoveModule, func: InternalMoveFunction) {
|
|
277
|
+
if (!func.isEntry) {
|
|
276
278
|
return ''
|
|
277
279
|
}
|
|
278
280
|
|
|
@@ -293,7 +295,7 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
|
293
295
|
return source
|
|
294
296
|
}
|
|
295
297
|
|
|
296
|
-
generateOnEvents(module:
|
|
298
|
+
generateOnEvents(module: InternalMoveModule, struct: InternalMoveStruct): string {
|
|
297
299
|
// for struct that has drop + store
|
|
298
300
|
// if (!isEvent(struct, module)) {
|
|
299
301
|
// return ''
|
|
@@ -318,7 +320,7 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
|
318
320
|
}
|
|
319
321
|
|
|
320
322
|
export class AccountCodegen<ModuleType, NetworkType> {
|
|
321
|
-
modules:
|
|
323
|
+
modules: InternalMoveModule[]
|
|
322
324
|
config: Config<NetworkType>
|
|
323
325
|
abi: ModuleType
|
|
324
326
|
loader: AccountRegister
|
|
@@ -328,7 +330,7 @@ export class AccountCodegen<ModuleType, NetworkType> {
|
|
|
328
330
|
moduleGen: AbstractCodegen<ModuleType, NetworkType>,
|
|
329
331
|
loader: AccountRegister,
|
|
330
332
|
abi: ModuleType,
|
|
331
|
-
modules:
|
|
333
|
+
modules: InternalMoveModule[],
|
|
332
334
|
config: Config<NetworkType>
|
|
333
335
|
) {
|
|
334
336
|
// const json = fs.readFileSync(config.srcFile, 'utf-8')
|
|
@@ -355,8 +357,8 @@ export class AccountCodegen<ModuleType, NetworkType> {
|
|
|
355
357
|
|
|
356
358
|
const imports = `
|
|
357
359
|
import { CallFilter } from "@sentio/sdk/move"
|
|
358
|
-
import {
|
|
359
|
-
MoveCoder, defaultMoveCoder, ${this.moduleGen.PREFIX}BindOptions, ${this.moduleGen.PREFIX}BaseProcessor,
|
|
360
|
+
import {
|
|
361
|
+
MoveCoder, defaultMoveCoder, ${this.moduleGen.PREFIX}BindOptions, ${this.moduleGen.PREFIX}BaseProcessor,
|
|
360
362
|
TypedEventInstance, ${this.moduleGen.PREFIX}Network, TypedEntryFunctionPayload,
|
|
361
363
|
${this.moduleGen.PREFIX}Context } from "@sentio/sdk/${this.moduleGen.PREFIX.toLowerCase()}"
|
|
362
364
|
import { MoveFetchConfig } from "@sentio/protos"
|
|
@@ -388,15 +390,15 @@ export class AccountCodegen<ModuleType, NetworkType> {
|
|
|
388
390
|
/* Autogenerated file. Do not edit manually. */
|
|
389
391
|
/* tslint:disable */
|
|
390
392
|
/* eslint-disable */
|
|
391
|
-
|
|
393
|
+
|
|
392
394
|
/* Generated modules for account ${address} */
|
|
393
|
-
|
|
395
|
+
|
|
394
396
|
${imports}
|
|
395
|
-
|
|
397
|
+
|
|
396
398
|
${moduleImports.join('\n')}
|
|
397
|
-
|
|
399
|
+
|
|
398
400
|
${this.modules.map((m) => this.moduleGen.generateModule(m, this.config.network)).join('\n')}
|
|
399
|
-
|
|
401
|
+
|
|
400
402
|
const MODULES = JSON.parse('${JSON.stringify(this.abi)}')
|
|
401
403
|
|
|
402
404
|
export function loadAllTypes(coder: MoveCoder) {
|
|
@@ -405,7 +407,7 @@ export class AccountCodegen<ModuleType, NetworkType> {
|
|
|
405
407
|
coder.load(m as any)
|
|
406
408
|
}
|
|
407
409
|
}
|
|
408
|
-
|
|
410
|
+
|
|
409
411
|
loadAllTypes(defaultMoveCoder())
|
|
410
412
|
` // source
|
|
411
413
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { moduleQname, SPLITTER, VECTOR_STR } from './utils.js'
|
|
2
2
|
import { parseMoveType, TypeDescriptor } from './types.js'
|
|
3
|
-
import {
|
|
3
|
+
import { InternalMoveFunction, InternalMoveModule, InternalMoveStruct } from './internal-models.js'
|
|
4
4
|
import { bytesToBigInt } from '../utils/index.js'
|
|
5
5
|
|
|
6
6
|
type StructWithTag<Base> = Base & {
|
|
@@ -14,15 +14,15 @@ type DecodedStructWithTag<B, T> = StructWithTag<B> & {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export abstract class AbstractMoveCoder<StructType> {
|
|
17
|
-
private moduleMapping = new Map<string,
|
|
18
|
-
private typeMapping = new Map<string,
|
|
19
|
-
private funcMapping = new Map<string,
|
|
17
|
+
private moduleMapping = new Map<string, InternalMoveModule>()
|
|
18
|
+
private typeMapping = new Map<string, InternalMoveStruct>()
|
|
19
|
+
private funcMapping = new Map<string, InternalMoveFunction>()
|
|
20
20
|
|
|
21
21
|
contains(account: string, name: string) {
|
|
22
22
|
return this.moduleMapping.has(account + '::' + name)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
loadInternal(module: InternalMoveModule) {
|
|
26
26
|
if (this.contains(module.address, module.name)) {
|
|
27
27
|
return
|
|
28
28
|
}
|
|
@@ -34,8 +34,8 @@ export abstract class AbstractMoveCoder<StructType> {
|
|
|
34
34
|
this.typeMapping.set(key, struct)
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
for (const func of module.
|
|
38
|
-
if (!func.
|
|
37
|
+
for (const func of module.exposedFunctions) {
|
|
38
|
+
if (!func.isEntry) {
|
|
39
39
|
continue
|
|
40
40
|
}
|
|
41
41
|
const key = [module.address, module.name, func.name].join(SPLITTER)
|
|
@@ -53,7 +53,7 @@ export abstract class AbstractMoveCoder<StructType> {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
protected getMoveStruct(type: string):
|
|
56
|
+
protected getMoveStruct(type: string): InternalMoveStruct {
|
|
57
57
|
const struct = this.typeMapping.get(type)
|
|
58
58
|
if (!struct) {
|
|
59
59
|
throw new Error('Failed to load type' + type + ' type are not imported anywhere')
|
|
@@ -61,7 +61,7 @@ export abstract class AbstractMoveCoder<StructType> {
|
|
|
61
61
|
return struct
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
protected getMoveFunction(type: string):
|
|
64
|
+
protected getMoveFunction(type: string): InternalMoveFunction {
|
|
65
65
|
const func = this.funcMapping.get(type)
|
|
66
66
|
if (!func) {
|
|
67
67
|
throw new Error('Failed to load function' + type + ' type are not imported anywhere')
|
package/src/move/account.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { parseMoveType, TypeDescriptor } from './types.js'
|
|
2
1
|
import { moduleQname, moduleQnameForType } from './utils.js'
|
|
3
|
-
import {
|
|
2
|
+
import { InternalMoveModule } from './internal-models.js'
|
|
4
3
|
|
|
5
4
|
export class AccountModulesImportInfo {
|
|
6
5
|
// account to module
|
|
@@ -31,21 +30,7 @@ export class AccountRegister {
|
|
|
31
30
|
accountImports = new Map<string, AccountModulesImportInfo>()
|
|
32
31
|
pendingAccounts = new Set<string>()
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
typeDescriptors = new Map<string, TypeDescriptor>()
|
|
36
|
-
|
|
37
|
-
protected loadTypeDescriptor(type: string) {
|
|
38
|
-
let descriptor = this.typeDescriptors.get(type)
|
|
39
|
-
|
|
40
|
-
// const descriptparseMoveType(type)
|
|
41
|
-
if (!descriptor) {
|
|
42
|
-
descriptor = parseMoveType(type)
|
|
43
|
-
this.typeDescriptors.set(type, descriptor)
|
|
44
|
-
}
|
|
45
|
-
return descriptor
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
register(module: NeutralMoveModule, tsModuleName: string): AccountModulesImportInfo {
|
|
33
|
+
register(module: InternalMoveModule, tsModuleName: string): AccountModulesImportInfo {
|
|
49
34
|
const currentModuleFqn = moduleQname(module)
|
|
50
35
|
|
|
51
36
|
let accountModuleImports = this.accountImports.get(module.address)
|
|
@@ -63,9 +48,9 @@ export class AccountRegister {
|
|
|
63
48
|
return accountModuleImports
|
|
64
49
|
}
|
|
65
50
|
|
|
66
|
-
registerFunctions(module:
|
|
67
|
-
for (const func of module.
|
|
68
|
-
if (!func.
|
|
51
|
+
private registerFunctions(module: InternalMoveModule, accountModuleImports: AccountModulesImportInfo): void {
|
|
52
|
+
for (const func of module.exposedFunctions) {
|
|
53
|
+
if (!func.isEntry) {
|
|
69
54
|
continue
|
|
70
55
|
}
|
|
71
56
|
for (const param of func.params) {
|
|
@@ -80,7 +65,7 @@ export class AccountRegister {
|
|
|
80
65
|
}
|
|
81
66
|
}
|
|
82
67
|
|
|
83
|
-
registerStruct(module:
|
|
68
|
+
private registerStruct(module: InternalMoveModule, accountModuleImports: AccountModulesImportInfo): void {
|
|
84
69
|
for (const struct of module.structs) {
|
|
85
70
|
for (const field of struct.fields) {
|
|
86
71
|
for (const type of field.type.dependedTypes()) {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { TypeDescriptor } from './types.js'
|
|
2
|
+
|
|
3
|
+
export interface InternalMoveModule {
|
|
4
|
+
address: string
|
|
5
|
+
name: string
|
|
6
|
+
exposedFunctions: InternalMoveFunction[]
|
|
7
|
+
structs: InternalMoveStruct[]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface InternalMoveFunction {
|
|
11
|
+
name: string
|
|
12
|
+
visibility: InternalMoveFunctionVisibility
|
|
13
|
+
isEntry: boolean
|
|
14
|
+
typeParams: InternalMoveTypeParam[]
|
|
15
|
+
params: TypeDescriptor[]
|
|
16
|
+
return: TypeDescriptor[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface InternalMoveStruct {
|
|
20
|
+
name: string
|
|
21
|
+
isNative: boolean
|
|
22
|
+
abilities: string[]
|
|
23
|
+
typeParams: InternalMoveTypeParam[]
|
|
24
|
+
fields: InternalMoveStructField[]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface InternalMoveStructField {
|
|
28
|
+
name: string
|
|
29
|
+
type: TypeDescriptor
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export enum InternalMoveFunctionVisibility {
|
|
33
|
+
PRIVATE = 'private',
|
|
34
|
+
PUBLIC = 'public',
|
|
35
|
+
FRIEND = 'friend',
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type InternalMoveTypeParam = {
|
|
39
|
+
constraints: string[]
|
|
40
|
+
}
|
package/src/move/ts-type.ts
CHANGED
|
@@ -2,10 +2,8 @@ import { TypeDescriptor } from './types.js'
|
|
|
2
2
|
import { normalizeToJSName, SPLITTER, VECTOR_STR } from './utils.js'
|
|
3
3
|
|
|
4
4
|
export function generateTypeForDescriptor(type: TypeDescriptor, currentAddress: string, addressType: string): string {
|
|
5
|
-
// TODO &signer is defintely an address, but what if &OTHER_TYPE?
|
|
6
5
|
if (type.qname.startsWith('&')) {
|
|
7
|
-
|
|
8
|
-
return addressType
|
|
6
|
+
throw Error('Unexpected &')
|
|
9
7
|
}
|
|
10
8
|
if (type.reference) {
|
|
11
9
|
return addressType
|