@sentio/sdk 2.5.0 → 2.5.1-rc.2
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/eth/codegen/event-handler.js.map +1 -1
- package/lib/eth/codegen/functions-handler.js +4 -9
- package/lib/eth/codegen/functions-handler.js.map +1 -1
- package/lib/eth/context.js.map +1 -1
- package/lib/eth/index.d.ts +0 -1
- package/lib/eth/index.js +0 -1
- package/lib/eth/index.js.map +1 -1
- package/lib/move/abstract-codegen.d.ts +12 -12
- package/lib/move/abstract-codegen.js +30 -36
- 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/sui-processor.js.map +1 -1
- package/lib/sui/utils.d.ts +2 -2
- package/lib/sui/utils.js.map +1 -1
- package/lib/utils/dex-price.test.js.map +1 -1
- package/lib/utils/erc20.test.js.map +1 -1
- package/package.json +10 -13
- 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/eth/codegen/event-handler.ts +1 -1
- package/src/eth/codegen/functions-handler.ts +4 -10
- package/src/eth/context.ts +0 -1
- package/src/eth/index.ts +0 -1
- package/src/move/abstract-codegen.ts +45 -50
- 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/sui-processor.ts +1 -1
- package/src/sui/utils.ts +2 -2
- package/lib/aptos/tests/aptos.test.d.ts +0 -1
- package/lib/aptos/tests/aptos.test.js.map +0 -1
- package/lib/aptos/tests/souffl3.d.ts +0 -1
- package/lib/aptos/tests/souffl3.js +0 -43
- package/lib/aptos/tests/souffl3.js.map +0 -1
- package/lib/aptos/tests/types/index.d.ts +0 -3
- package/lib/aptos/tests/types/index.js +0 -7
- package/lib/aptos/tests/types/index.js.map +0 -1
- package/lib/aptos/tests/types/reserved.d.ts +0 -340
- package/lib/aptos/tests/types/reserved.js +0 -287
- package/lib/aptos/tests/types/reserved.js.map +0 -1
- package/lib/aptos/tests/types/soffl3.d.ts +0 -801
- package/lib/aptos/tests/types/soffl3.js +0 -514
- package/lib/aptos/tests/types/soffl3.js.map +0 -1
- package/lib/aptos/tests/types/souffle.d.ts +0 -335
- package/lib/aptos/tests/types/souffle.js +0 -281
- package/lib/aptos/tests/types/souffle.js.map +0 -1
- package/lib/eth/error.d.ts +0 -1
- package/lib/eth/error.js +0 -3
- package/lib/eth/error.js.map +0 -1
- package/lib/eth/tests/account.test.d.ts +0 -1
- package/lib/eth/tests/account.test.js.map +0 -1
- package/lib/eth/tests/codegen.test.d.ts +0 -1
- package/lib/eth/tests/codegen.test.js.map +0 -1
- package/lib/eth/tests/erc20-template.test.d.ts +0 -1
- package/lib/eth/tests/erc20-template.test.js.map +0 -1
- package/lib/eth/tests/erc20.d.ts +0 -1
- package/lib/eth/tests/erc20.js +0 -52
- package/lib/eth/tests/erc20.js.map +0 -1
- package/lib/eth/tests/erc20.test.d.ts +0 -1
- package/lib/eth/tests/erc20.test.js.map +0 -1
- package/lib/eth/tests/error-capture.test.d.ts +0 -1
- package/lib/eth/tests/error-capture.test.js.map +0 -1
- package/lib/eth/tests/logger.test.d.ts +0 -1
- package/lib/eth/tests/logger.test.js.map +0 -1
- package/lib/eth/tests/types/anyswaprouter.d.ts +0 -3
- package/lib/eth/tests/types/anyswaprouter.js +0 -7
- package/lib/eth/tests/types/anyswaprouter.js.map +0 -1
- package/lib/eth/tests/types/commitmentpool.d.ts +0 -3
- package/lib/eth/tests/types/commitmentpool.js +0 -7
- package/lib/eth/tests/types/commitmentpool.js.map +0 -1
- package/lib/eth/tests/types/index.d.ts +0 -12
- package/lib/eth/tests/types/index.js +0 -16
- package/lib/eth/tests/types/index.js.map +0 -1
- package/lib/eth/tests/types/internal/AnyswapRouter.d.ts +0 -122
- package/lib/eth/tests/types/internal/AnyswapRouter.js +0 -2
- package/lib/eth/tests/types/internal/AnyswapRouter.js.map +0 -1
- package/lib/eth/tests/types/internal/CommitmentPool.d.ts +0 -176
- package/lib/eth/tests/types/internal/CommitmentPool.js +0 -2
- package/lib/eth/tests/types/internal/CommitmentPool.js.map +0 -1
- package/lib/eth/tests/types/internal/MembershipStakerV3.d.ts +0 -81
- package/lib/eth/tests/types/internal/MembershipStakerV3.js +0 -2
- package/lib/eth/tests/types/internal/MembershipStakerV3.js.map +0 -1
- package/lib/eth/tests/types/internal/Pyth.d.ts +0 -204
- package/lib/eth/tests/types/internal/Pyth.js +0 -2
- package/lib/eth/tests/types/internal/Pyth.js.map +0 -1
- package/lib/eth/tests/types/internal/Seaport.d.ts +0 -350
- package/lib/eth/tests/types/internal/Seaport.js +0 -2
- package/lib/eth/tests/types/internal/Seaport.js.map +0 -1
- package/lib/eth/tests/types/internal/TokenExchange.d.ts +0 -128
- package/lib/eth/tests/types/internal/TokenExchange.js +0 -2
- package/lib/eth/tests/types/internal/TokenExchange.js.map +0 -1
- package/lib/eth/tests/types/internal/anyswaprouter-processor.d.ts +0 -463
- package/lib/eth/tests/types/internal/anyswaprouter-processor.js +0 -425
- package/lib/eth/tests/types/internal/anyswaprouter-processor.js.map +0 -1
- package/lib/eth/tests/types/internal/anyswaprouter-test-utils.d.ts +0 -9
- package/lib/eth/tests/types/internal/anyswaprouter-test-utils.js +0 -124
- package/lib/eth/tests/types/internal/anyswaprouter-test-utils.js.map +0 -1
- package/lib/eth/tests/types/internal/commitmentpool-processor.d.ts +0 -348
- package/lib/eth/tests/types/internal/commitmentpool-processor.js +0 -607
- package/lib/eth/tests/types/internal/commitmentpool-processor.js.map +0 -1
- package/lib/eth/tests/types/internal/commitmentpool-test-utils.d.ts +0 -9
- package/lib/eth/tests/types/internal/commitmentpool-test-utils.js +0 -87
- package/lib/eth/tests/types/internal/commitmentpool-test-utils.js.map +0 -1
- package/lib/eth/tests/types/internal/common.d.ts +0 -10
- package/lib/eth/tests/types/internal/common.js +0 -8
- package/lib/eth/tests/types/internal/common.js.map +0 -1
- package/lib/eth/tests/types/internal/factories/AnyswapRouter__factory.d.ts +0 -988
- package/lib/eth/tests/types/internal/factories/AnyswapRouter__factory.js +0 -1269
- package/lib/eth/tests/types/internal/factories/AnyswapRouter__factory.js.map +0 -1
- package/lib/eth/tests/types/internal/factories/CommitmentPool__factory.d.ts +0 -792
- package/lib/eth/tests/types/internal/factories/CommitmentPool__factory.js +0 -1040
- package/lib/eth/tests/types/internal/factories/CommitmentPool__factory.js.map +0 -1
- package/lib/eth/tests/types/internal/factories/MembershipStakerV3__factory.d.ts +0 -549
- package/lib/eth/tests/types/internal/factories/MembershipStakerV3__factory.js +0 -721
- package/lib/eth/tests/types/internal/factories/MembershipStakerV3__factory.js.map +0 -1
- package/lib/eth/tests/types/internal/factories/Pyth__factory.d.ts +0 -1130
- package/lib/eth/tests/types/internal/factories/Pyth__factory.js +0 -1486
- package/lib/eth/tests/types/internal/factories/Pyth__factory.js.map +0 -1
- package/lib/eth/tests/types/internal/factories/Seaport__factory.d.ts +0 -2018
- package/lib/eth/tests/types/internal/factories/Seaport__factory.js +0 -2610
- package/lib/eth/tests/types/internal/factories/Seaport__factory.js.map +0 -1
- package/lib/eth/tests/types/internal/factories/TokenExchange__factory.d.ts +0 -651
- package/lib/eth/tests/types/internal/factories/TokenExchange__factory.js +0 -853
- package/lib/eth/tests/types/internal/factories/TokenExchange__factory.js.map +0 -1
- package/lib/eth/tests/types/internal/factories/index.d.ts +0 -6
- package/lib/eth/tests/types/internal/factories/index.js +0 -10
- package/lib/eth/tests/types/internal/factories/index.js.map +0 -1
- package/lib/eth/tests/types/internal/index.d.ts +0 -13
- package/lib/eth/tests/types/internal/index.js +0 -8
- package/lib/eth/tests/types/internal/index.js.map +0 -1
- package/lib/eth/tests/types/internal/membershipstakerv3-processor.d.ts +0 -287
- package/lib/eth/tests/types/internal/membershipstakerv3-processor.js +0 -596
- package/lib/eth/tests/types/internal/membershipstakerv3-processor.js.map +0 -1
- package/lib/eth/tests/types/internal/membershipstakerv3-test-utils.d.ts +0 -11
- package/lib/eth/tests/types/internal/membershipstakerv3-test-utils.js +0 -109
- package/lib/eth/tests/types/internal/membershipstakerv3-test-utils.js.map +0 -1
- package/lib/eth/tests/types/internal/pyth-processor.d.ts +0 -422
- package/lib/eth/tests/types/internal/pyth-processor.js +0 -890
- package/lib/eth/tests/types/internal/pyth-processor.js.map +0 -1
- package/lib/eth/tests/types/internal/pyth-test-utils.d.ts +0 -13
- package/lib/eth/tests/types/internal/pyth-test-utils.js +0 -131
- package/lib/eth/tests/types/internal/pyth-test-utils.js.map +0 -1
- package/lib/eth/tests/types/internal/seaport-processor.d.ts +0 -211
- package/lib/eth/tests/types/internal/seaport-processor.js +0 -237
- package/lib/eth/tests/types/internal/seaport-processor.js.map +0 -1
- package/lib/eth/tests/types/internal/seaport-test-utils.d.ts +0 -6
- package/lib/eth/tests/types/internal/seaport-test-utils.js +0 -61
- package/lib/eth/tests/types/internal/seaport-test-utils.js.map +0 -1
- package/lib/eth/tests/types/internal/tokenexchange-processor.d.ts +0 -334
- package/lib/eth/tests/types/internal/tokenexchange-processor.js +0 -667
- package/lib/eth/tests/types/internal/tokenexchange-processor.js.map +0 -1
- package/lib/eth/tests/types/internal/tokenexchange-test-utils.d.ts +0 -13
- package/lib/eth/tests/types/internal/tokenexchange-test-utils.js +0 -149
- package/lib/eth/tests/types/internal/tokenexchange-test-utils.js.map +0 -1
- package/lib/eth/tests/types/membershipstakerv3.d.ts +0 -3
- package/lib/eth/tests/types/membershipstakerv3.js +0 -7
- package/lib/eth/tests/types/membershipstakerv3.js.map +0 -1
- package/lib/eth/tests/types/pyth.d.ts +0 -3
- package/lib/eth/tests/types/pyth.js +0 -7
- package/lib/eth/tests/types/pyth.js.map +0 -1
- package/lib/eth/tests/types/seaport.d.ts +0 -3
- package/lib/eth/tests/types/seaport.js +0 -7
- package/lib/eth/tests/types/seaport.js.map +0 -1
- package/lib/eth/tests/types/tokenexchange.d.ts +0 -3
- package/lib/eth/tests/types/tokenexchange.js +0 -7
- package/lib/eth/tests/types/tokenexchange.js.map +0 -1
- 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/lib/solana/tests/solana.test.d.ts +0 -1
- package/lib/solana/tests/solana.test.js.map +0 -1
- package/lib/solana/tests/types/basic_1.d.ts +0 -26
- package/lib/solana/tests/types/basic_1.js +0 -63
- package/lib/solana/tests/types/basic_1.js.map +0 -1
- package/lib/solana/tests/types/basic_1_processor.d.ts +0 -21
- package/lib/solana/tests/types/basic_1_processor.js +0 -35
- package/lib/solana/tests/types/basic_1_processor.js.map +0 -1
- package/lib/solana/tests/types/token_bridge.d.ts +0 -29
- package/lib/solana/tests/types/token_bridge.js +0 -938
- package/lib/solana/tests/types/token_bridge.js.map +0 -1
- package/lib/solana/tests/types/token_bridge_processor.d.ts +0 -212
- package/lib/solana/tests/types/token_bridge_processor.js +0 -134
- package/lib/solana/tests/types/token_bridge_processor.js.map +0 -1
- package/lib/solana/tests/wormhole-token-bridge.d.ts +0 -15
- package/lib/solana/tests/wormhole-token-bridge.js +0 -79
- package/lib/solana/tests/wormhole-token-bridge.js.map +0 -1
- package/lib/sui/tests/sui.test.d.ts +0 -1
- package/lib/sui/tests/sui.test.js.map +0 -1
- package/lib/sui/tests/types/index.d.ts +0 -1
- package/lib/sui/tests/types/index.js +0 -5
- package/lib/sui/tests/types/index.js.map +0 -1
- package/lib/sui/tests/types/testnet/index.d.ts +0 -1
- package/lib/sui/tests/types/testnet/index.js +0 -5
- package/lib/sui/tests/types/testnet/index.js.map +0 -1
- package/lib/sui/tests/types/testnet/swap.d.ts +0 -249
- package/lib/sui/tests/types/testnet/swap.js +0 -310
- package/lib/sui/tests/types/testnet/swap.js.map +0 -1
- package/src/aptos/tests/abis/reserved.json +0 -402
- package/src/aptos/tests/abis/soffl3.json +0 -1411
- package/src/aptos/tests/abis/souffle.json +0 -389
- package/src/aptos/tests/souffl3.ts +0 -56
- package/src/aptos/tests/types/index.ts +0 -6
- package/src/aptos/tests/types/reserved.ts +0 -766
- package/src/aptos/tests/types/soffl3.ts +0 -1528
- package/src/aptos/tests/types/souffle.ts +0 -765
- package/src/eth/error.ts +0 -4
- package/src/eth/tests/abis/eth/CommitmentPool.json +0 -1034
- package/src/eth/tests/abis/eth/MembershipStakerV3.json +0 -706
- package/src/eth/tests/abis/eth/Pyth.json +0 -1471
- package/src/eth/tests/abis/eth/Seaport.json +0 -2595
- package/src/eth/tests/abis/eth/TokenExchange.json +0 -838
- package/src/eth/tests/abis/eth/anyswapRouter.json +0 -490
- package/src/eth/tests/erc20.ts +0 -63
- package/src/eth/tests/types/anyswaprouter.ts +0 -7
- package/src/eth/tests/types/commitmentpool.ts +0 -7
- package/src/eth/tests/types/index.ts +0 -33
- package/src/eth/tests/types/internal/AnyswapRouter.ts +0 -122
- package/src/eth/tests/types/internal/CommitmentPool.ts +0 -208
- package/src/eth/tests/types/internal/MembershipStakerV3.ts +0 -108
- package/src/eth/tests/types/internal/Pyth.ts +0 -246
- package/src/eth/tests/types/internal/Seaport.ts +0 -389
- package/src/eth/tests/types/internal/TokenExchange.ts +0 -142
- package/src/eth/tests/types/internal/anyswaprouter-processor.ts +0 -1396
- package/src/eth/tests/types/internal/anyswaprouter-test-utils.ts +0 -187
- package/src/eth/tests/types/internal/commitmentpool-processor.ts +0 -1575
- package/src/eth/tests/types/internal/commitmentpool-test-utils.ts +0 -150
- package/src/eth/tests/types/internal/common.ts +0 -23
- package/src/eth/tests/types/internal/factories/AnyswapRouter__factory.ts +0 -1278
- package/src/eth/tests/types/internal/factories/CommitmentPool__factory.ts +0 -1049
- package/src/eth/tests/types/internal/factories/MembershipStakerV3__factory.ts +0 -730
- package/src/eth/tests/types/internal/factories/Pyth__factory.ts +0 -1492
- package/src/eth/tests/types/internal/factories/Seaport__factory.ts +0 -2616
- package/src/eth/tests/types/internal/factories/TokenExchange__factory.ts +0 -862
- package/src/eth/tests/types/internal/factories/index.ts +0 -9
- package/src/eth/tests/types/internal/index.ts +0 -16
- package/src/eth/tests/types/internal/membershipstakerv3-processor.ts +0 -1399
- package/src/eth/tests/types/internal/membershipstakerv3-test-utils.ts +0 -188
- package/src/eth/tests/types/internal/pyth-processor.ts +0 -2043
- package/src/eth/tests/types/internal/pyth-test-utils.ts +0 -226
- package/src/eth/tests/types/internal/seaport-processor.ts +0 -678
- package/src/eth/tests/types/internal/seaport-test-utils.ts +0 -100
- package/src/eth/tests/types/internal/tokenexchange-processor.ts +0 -1570
- package/src/eth/tests/types/internal/tokenexchange-test-utils.ts +0 -244
- package/src/eth/tests/types/membershipstakerv3.ts +0 -7
- package/src/eth/tests/types/pyth.ts +0 -7
- package/src/eth/tests/types/seaport.ts +0 -7
- package/src/eth/tests/types/tokenexchange.ts +0 -7
- package/src/move/neutral-models.ts +0 -45
- package/src/solana/tests/abis/basic_1.json +0 -62
- package/src/solana/tests/abis/token_bridge.json +0 -937
- package/src/solana/tests/types/basic_1.ts +0 -62
- package/src/solana/tests/types/basic_1_processor.ts +0 -42
- package/src/solana/tests/types/token_bridge.ts +0 -937
- package/src/solana/tests/types/token_bridge_processor.ts +0 -150
- package/src/solana/tests/wormhole-token-bridge.ts +0 -96
- package/src/sui/tests/abis/testnet/swap.json +0 -1752
- package/src/sui/tests/types/index.ts +0 -3
- package/src/sui/tests/types/testnet/index.ts +0 -4
- package/src/sui/tests/types/testnet/swap.ts +0 -698
|
@@ -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'
|
|
@@ -6,7 +6,7 @@ import chalk from 'chalk'
|
|
|
6
6
|
import { format } from 'prettier'
|
|
7
7
|
import { isFrameworkAccount, moduleQname, normalizeToJSName, SPLITTER } from './utils.js'
|
|
8
8
|
import { generateTypeForDescriptor } from './ts-type.js'
|
|
9
|
-
import { camelCase } from 'lodash-es'
|
|
9
|
+
import { camelCase, upperFirst } from 'lodash-es'
|
|
10
10
|
import { TypeDescriptor } from './types.js'
|
|
11
11
|
|
|
12
12
|
interface OutputFile {
|
|
@@ -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
|
|
|
@@ -259,27 +261,27 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
|
259
261
|
return generateTypeForDescriptor(param, module.address, this.ADDRESS_TYPE)
|
|
260
262
|
})
|
|
261
263
|
|
|
262
|
-
const camelFuncName =
|
|
264
|
+
const camelFuncName = upperFirst(camelCase(func.name))
|
|
263
265
|
|
|
264
266
|
const genericString = this.generateFunctionTypeParameters(func)
|
|
265
267
|
return `
|
|
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
|
|
|
279
281
|
// const genericString = generateFunctionTypeParameters(func)
|
|
280
282
|
const moduleName = normalizeToJSName(module.name)
|
|
281
283
|
|
|
282
|
-
const camelFuncName =
|
|
284
|
+
const camelFuncName = upperFirst(camelCase(func.name))
|
|
283
285
|
const source = `
|
|
284
286
|
onEntry${camelFuncName}(func: (call: ${moduleName}.${camelFuncName}Payload, ctx: ${this.PREFIX}Context) => void, filter?: CallFilter, fetchConfig?: MoveFetchConfig): ${moduleName} {
|
|
285
287
|
this.onEntryFunctionCall(func, {
|
|
@@ -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
|
|
|
@@ -417,10 +419,3 @@ export class AccountCodegen<ModuleType, NetworkType> {
|
|
|
417
419
|
]
|
|
418
420
|
}
|
|
419
421
|
}
|
|
420
|
-
|
|
421
|
-
function capitalizeFirstChar(input: string): string {
|
|
422
|
-
if (!input) {
|
|
423
|
-
return input
|
|
424
|
-
}
|
|
425
|
-
return input[0].toUpperCase() + (input.length > 1 ? input.substring(1) : '')
|
|
426
|
-
}
|
|
@@ -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
|
package/src/move/types.ts
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
import { SPLITTER, VECTOR_STR } from './utils.js'
|
|
2
2
|
|
|
3
3
|
export class TypeDescriptor {
|
|
4
|
-
// type: string
|
|
5
|
-
|
|
6
|
-
// TODO add reference flag
|
|
7
|
-
|
|
8
|
-
// qualified name without type parameters
|
|
9
4
|
qname: string
|
|
10
5
|
reference: boolean
|
|
11
|
-
|
|
12
|
-
// module?: string
|
|
13
|
-
|
|
6
|
+
mutable: boolean
|
|
14
7
|
typeArgs: TypeDescriptor[]
|
|
15
8
|
|
|
16
9
|
constructor(symbol: string, typeParams?: TypeDescriptor[]) {
|
|
17
10
|
this.qname = symbol
|
|
11
|
+
this.reference = false
|
|
12
|
+
this.mutable = false
|
|
18
13
|
this.typeArgs = typeParams || []
|
|
19
14
|
}
|
|
20
15
|
|
|
@@ -97,20 +92,15 @@ export class TypeDescriptor {
|
|
|
97
92
|
}
|
|
98
93
|
|
|
99
94
|
export function parseMoveType(type: string): TypeDescriptor {
|
|
100
|
-
// type = type.replace('&', '')
|
|
101
|
-
|
|
102
|
-
type = type.replaceAll('&mut ', '&')
|
|
103
|
-
type = type.replaceAll('mut ', '')
|
|
104
|
-
|
|
105
|
-
// TODO replace ' ' is not exactly safe, need to double check this
|
|
106
|
-
type = type.replaceAll(' ', '')
|
|
107
|
-
|
|
108
95
|
const stack: TypeDescriptor[] = [new TypeDescriptor('')]
|
|
109
96
|
let buffer = []
|
|
110
97
|
|
|
111
98
|
// xxx:asdf<g1<a,<c,d>>, b, g2<a,b>, e>
|
|
112
99
|
for (let i = 0; i < type.length; i++) {
|
|
113
100
|
const ch = type[i]
|
|
101
|
+
if (ch === ' ') {
|
|
102
|
+
continue
|
|
103
|
+
}
|
|
114
104
|
if (ch === '<') {
|
|
115
105
|
// const symbol = type.slice(symbolStart, i)
|
|
116
106
|
// symbolStart =
|
|
@@ -121,7 +111,7 @@ export function parseMoveType(type: string): TypeDescriptor {
|
|
|
121
111
|
stack.push(new TypeDescriptor(''))
|
|
122
112
|
continue
|
|
123
113
|
}
|
|
124
|
-
if (ch === '>') {
|
|
114
|
+
if (ch === '>' || ch === ',') {
|
|
125
115
|
const typeParam = stack.pop()
|
|
126
116
|
if (!typeParam) {
|
|
127
117
|
throw Error('Unexpected stack size')
|
|
@@ -132,25 +122,11 @@ export function parseMoveType(type: string): TypeDescriptor {
|
|
|
132
122
|
}
|
|
133
123
|
adjustType(typeParam)
|
|
134
124
|
stack[stack.length - 1].typeArgs.push(typeParam)
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (ch === ',') {
|
|
138
|
-
const typeParam = stack.pop()
|
|
139
|
-
if (!typeParam) {
|
|
140
|
-
throw Error('Unexpected stack size')
|
|
141
|
-
}
|
|
142
|
-
if (buffer.length > 0) {
|
|
143
|
-
typeParam.qname = buffer.join('')
|
|
144
|
-
buffer = []
|
|
125
|
+
if (ch === ',') {
|
|
126
|
+
stack.push(new TypeDescriptor(''))
|
|
145
127
|
}
|
|
146
|
-
adjustType(typeParam)
|
|
147
|
-
|
|
148
|
-
stack[stack.length - 1].typeArgs.push(typeParam)
|
|
149
|
-
// continue parse next param
|
|
150
|
-
stack.push(new TypeDescriptor(''))
|
|
151
128
|
continue
|
|
152
129
|
}
|
|
153
|
-
|
|
154
130
|
buffer.push(ch)
|
|
155
131
|
}
|
|
156
132
|
|
|
@@ -171,4 +147,8 @@ function adjustType(type: TypeDescriptor) {
|
|
|
171
147
|
type.reference = true
|
|
172
148
|
type.qname = type.qname.slice(1)
|
|
173
149
|
}
|
|
150
|
+
if (type.qname.startsWith('mut')) {
|
|
151
|
+
type.mutable = true
|
|
152
|
+
type.qname = type.qname.slice(3)
|
|
153
|
+
}
|
|
174
154
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { SuiNetwork } from '../network.js'
|
|
2
2
|
import * as fs from 'fs'
|
|
3
3
|
import chalk from 'chalk'
|
|
4
|
-
import {
|
|
4
|
+
import { InternalMoveModule, InternalMoveStruct } from '../../move/internal-models.js'
|
|
5
5
|
import { AbstractCodegen } from '../../move/abstract-codegen.js'
|
|
6
6
|
import { JsonRpcProvider, SuiMoveNormalizedModules } from '@mysten/sui.js'
|
|
7
|
-
import {
|
|
7
|
+
import { toInternalModule } from '../move-types.js'
|
|
8
8
|
import { moduleQname, SPLITTER, TypeDescriptor } from '../../move/index.js'
|
|
9
9
|
|
|
10
10
|
export async function codegen(abisDir: string, outDir = 'src/types/sui') {
|
|
@@ -12,7 +12,7 @@ export async function codegen(abisDir: string, outDir = 'src/types/sui') {
|
|
|
12
12
|
return
|
|
13
13
|
}
|
|
14
14
|
console.log(chalk.green('Generated Types for Sui'))
|
|
15
|
-
const gen = new
|
|
15
|
+
const gen = new SuiCodegen()
|
|
16
16
|
await gen.generate(abisDir, outDir)
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -28,7 +28,7 @@ function getRpcClient(network: SuiNetwork): JsonRpcProvider {
|
|
|
28
28
|
return new JsonRpcProvider(getRpcEndpoint(network))
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
class
|
|
31
|
+
class SuiCodegen extends AbstractCodegen<SuiMoveNormalizedModules, SuiNetwork> {
|
|
32
32
|
ADDRESS_TYPE = 'SuiAddress'
|
|
33
33
|
MAIN_NET = SuiNetwork.MAIN_NET
|
|
34
34
|
TEST_NET = SuiNetwork.TEST_NET
|
|
@@ -44,13 +44,13 @@ class SuiCodeGen extends AbstractCodegen<SuiMoveNormalizedModules, SuiNetwork> {
|
|
|
44
44
|
return params.slice(0, params.length - 1)
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
return Object.values(modules).map(
|
|
47
|
+
toInternalModules(modules: SuiMoveNormalizedModules): InternalMoveModule[] {
|
|
48
|
+
return Object.values(modules).map(toInternalModule)
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
getEventStructs(module:
|
|
51
|
+
getEventStructs(module: InternalMoveModule) {
|
|
52
52
|
const qname = moduleQname(module)
|
|
53
|
-
const eventMap = new Map<string,
|
|
53
|
+
const eventMap = new Map<string, InternalMoveStruct>()
|
|
54
54
|
|
|
55
55
|
for (const struct of module.structs) {
|
|
56
56
|
const abilities = new Set(struct.abilities)
|
package/src/sui/move-coder.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TypedEventInstance, TypedEntryFunctionPayload } from './models.js'
|
|
2
2
|
import { AbstractMoveCoder } from '../move/abstract-move-coder.js'
|
|
3
3
|
import { MoveCall, MoveEvent, SuiMoveNormalizedModule } from '@mysten/sui.js'
|
|
4
|
-
import {
|
|
4
|
+
import { toInternalModule } from './move-types.js'
|
|
5
5
|
import { SPLITTER } from '../move/index.js'
|
|
6
6
|
|
|
7
7
|
export class MoveCoder extends AbstractMoveCoder<MoveEvent> {
|
|
@@ -9,7 +9,7 @@ export class MoveCoder extends AbstractMoveCoder<MoveEvent> {
|
|
|
9
9
|
if (this.contains(module.address, module.name)) {
|
|
10
10
|
return
|
|
11
11
|
}
|
|
12
|
-
this.
|
|
12
|
+
this.loadInternal(toInternalModule(module))
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
decodeEvent<T>(event: MoveEvent): TypedEventInstance<T> | undefined {
|