@sentio/sdk 2.13.0-rc.1 → 2.13.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/aptos/aptos-chain-adapter.d.ts +11 -0
- package/lib/aptos/aptos-chain-adapter.js +56 -0
- package/lib/aptos/aptos-chain-adapter.js.map +1 -0
- package/lib/aptos/aptos-processor.d.ts +2 -2
- package/lib/aptos/aptos-processor.js +4 -7
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/builtin/0x1.d.ts +62 -62
- package/lib/aptos/builtin/0x1.js.map +1 -1
- package/lib/aptos/builtin/0x3.d.ts +21 -21
- package/lib/aptos/builtin/0x3.js.map +1 -1
- package/lib/aptos/codegen/codegen.js +4 -45
- package/lib/aptos/codegen/codegen.js.map +1 -1
- package/lib/aptos/move-coder.d.ts +3 -3
- package/lib/aptos/move-coder.js +8 -6
- package/lib/aptos/move-coder.js.map +1 -1
- package/lib/move/abstract-codegen.d.ts +3 -4
- package/lib/move/abstract-codegen.js +11 -7
- package/lib/move/abstract-codegen.js.map +1 -1
- package/lib/move/abstract-move-coder.d.ts +5 -2
- package/lib/move/abstract-move-coder.js +7 -1
- package/lib/move/abstract-move-coder.js.map +1 -1
- package/lib/move/chain-adapter.d.ts +9 -0
- package/lib/move/chain-adapter.js +3 -0
- package/lib/move/chain-adapter.js.map +1 -0
- package/lib/move/index.d.ts +1 -0
- package/lib/move/index.js +1 -0
- package/lib/move/index.js.map +1 -1
- package/lib/sui/builtin/0x1.d.ts +6 -6
- package/lib/sui/builtin/0x1.js.map +1 -1
- package/lib/sui/builtin/0x2.d.ts +19 -19
- package/lib/sui/builtin/0x2.js.map +1 -1
- package/lib/sui/builtin/0x3.d.ts +9 -9
- package/lib/sui/builtin/0x3.js.map +1 -1
- package/lib/sui/codegen/codegen.js +4 -34
- package/lib/sui/codegen/codegen.js.map +1 -1
- package/lib/sui/context.d.ts +2 -1
- package/lib/sui/context.js +3 -1
- package/lib/sui/context.js.map +1 -1
- package/lib/sui/move-coder.d.ts +4 -3
- package/lib/sui/move-coder.js +8 -6
- package/lib/sui/move-coder.js.map +1 -1
- package/lib/sui/sui-chain-adapter.d.ts +11 -0
- package/lib/sui/sui-chain-adapter.js +43 -0
- package/lib/sui/sui-chain-adapter.js.map +1 -0
- package/lib/sui/sui-processor.js +13 -10
- package/lib/sui/sui-processor.js.map +1 -1
- package/lib/sui/utils.d.ts +0 -2
- package/lib/sui/utils.js +0 -6
- package/lib/sui/utils.js.map +1 -1
- package/lib/testing/sui-facet.d.ts +2 -2
- package/lib/testing/sui-facet.js +16 -26
- package/lib/testing/sui-facet.js.map +1 -1
- package/package.json +4 -4
- package/src/aptos/aptos-chain-adapter.ts +65 -0
- package/src/aptos/aptos-processor.ts +6 -10
- package/src/aptos/builtin/0x1.ts +62 -62
- package/src/aptos/builtin/0x3.ts +21 -21
- package/src/aptos/codegen/codegen.ts +5 -54
- package/src/aptos/move-coder.ts +11 -10
- package/src/move/abstract-codegen.ts +13 -14
- package/src/move/abstract-move-coder.ts +10 -3
- package/src/move/chain-adapter.ts +14 -0
- package/src/move/index.ts +1 -0
- package/src/sui/builtin/0x1.ts +6 -6
- package/src/sui/builtin/0x2.ts +19 -19
- package/src/sui/builtin/0x3.ts +9 -9
- package/src/sui/codegen/codegen.ts +5 -40
- package/src/sui/context.ts +4 -1
- package/src/sui/move-coder.ts +12 -9
- package/src/sui/sui-chain-adapter.ts +50 -0
- package/src/sui/sui-processor.ts +23 -18
- package/src/sui/utils.ts +0 -8
- package/src/testing/sui-facet.ts +15 -30
- package/lib/aptos/utils.d.ts +0 -2
- package/lib/aptos/utils.js +0 -10
- package/lib/aptos/utils.js.map +0 -1
- package/src/aptos/utils.ts +0 -11
package/src/aptos/builtin/0x3.ts
CHANGED
@@ -201,7 +201,7 @@ export class token extends AptosBaseProcessor {
|
|
201
201
|
event: token.CreateCollectionEventInstance,
|
202
202
|
ctx: AptosContext
|
203
203
|
) => void,
|
204
|
-
fetchConfig?: MoveFetchConfig
|
204
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
205
205
|
): token {
|
206
206
|
this.onMoveEvent(
|
207
207
|
func,
|
@@ -218,7 +218,7 @@ export class token extends AptosBaseProcessor {
|
|
218
218
|
event: token.CreateTokenDataEventInstance,
|
219
219
|
ctx: AptosContext
|
220
220
|
) => void,
|
221
|
-
fetchConfig?: MoveFetchConfig
|
221
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
222
222
|
): token {
|
223
223
|
this.onMoveEvent(
|
224
224
|
func,
|
@@ -232,7 +232,7 @@ export class token extends AptosBaseProcessor {
|
|
232
232
|
|
233
233
|
onEventMintTokenEvent(
|
234
234
|
func: (event: token.MintTokenEventInstance, ctx: AptosContext) => void,
|
235
|
-
fetchConfig?: MoveFetchConfig
|
235
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
236
236
|
): token {
|
237
237
|
this.onMoveEvent(
|
238
238
|
func,
|
@@ -246,7 +246,7 @@ export class token extends AptosBaseProcessor {
|
|
246
246
|
|
247
247
|
onEventDepositEvent(
|
248
248
|
func: (event: token.DepositEventInstance, ctx: AptosContext) => void,
|
249
|
-
fetchConfig?: MoveFetchConfig
|
249
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
250
250
|
): token {
|
251
251
|
this.onMoveEvent(
|
252
252
|
func,
|
@@ -260,7 +260,7 @@ export class token extends AptosBaseProcessor {
|
|
260
260
|
|
261
261
|
onEventWithdrawEvent(
|
262
262
|
func: (event: token.WithdrawEventInstance, ctx: AptosContext) => void,
|
263
|
-
fetchConfig?: MoveFetchConfig
|
263
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
264
264
|
): token {
|
265
265
|
this.onMoveEvent(
|
266
266
|
func,
|
@@ -274,7 +274,7 @@ export class token extends AptosBaseProcessor {
|
|
274
274
|
|
275
275
|
onEventBurnTokenEvent(
|
276
276
|
func: (event: token.BurnTokenEventInstance, ctx: AptosContext) => void,
|
277
|
-
fetchConfig?: MoveFetchConfig
|
277
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
278
278
|
): token {
|
279
279
|
this.onMoveEvent(
|
280
280
|
func,
|
@@ -291,7 +291,7 @@ export class token extends AptosBaseProcessor {
|
|
291
291
|
event: token.MutateTokenPropertyMapEventInstance,
|
292
292
|
ctx: AptosContext
|
293
293
|
) => void,
|
294
|
-
fetchConfig?: MoveFetchConfig
|
294
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
295
295
|
): token {
|
296
296
|
this.onMoveEvent(
|
297
297
|
func,
|
@@ -668,7 +668,7 @@ export class token_coin_swap extends AptosBaseProcessor {
|
|
668
668
|
event: token_coin_swap.TokenListingEventInstance,
|
669
669
|
ctx: AptosContext
|
670
670
|
) => void,
|
671
|
-
fetchConfig?: MoveFetchConfig
|
671
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
672
672
|
): token_coin_swap {
|
673
673
|
this.onMoveEvent(
|
674
674
|
func,
|
@@ -685,7 +685,7 @@ export class token_coin_swap extends AptosBaseProcessor {
|
|
685
685
|
event: token_coin_swap.TokenSwapEventInstance,
|
686
686
|
ctx: AptosContext
|
687
687
|
) => void,
|
688
|
-
fetchConfig?: MoveFetchConfig
|
688
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
689
689
|
): token_coin_swap {
|
690
690
|
this.onMoveEvent(
|
691
691
|
func,
|
@@ -845,7 +845,7 @@ export class token_transfers extends AptosBaseProcessor {
|
|
845
845
|
event: token_transfers.TokenOfferEventInstance,
|
846
846
|
ctx: AptosContext
|
847
847
|
) => void,
|
848
|
-
fetchConfig?: MoveFetchConfig
|
848
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
849
849
|
): token_transfers {
|
850
850
|
this.onMoveEvent(
|
851
851
|
func,
|
@@ -862,7 +862,7 @@ export class token_transfers extends AptosBaseProcessor {
|
|
862
862
|
event: token_transfers.TokenCancelOfferEventInstance,
|
863
863
|
ctx: AptosContext
|
864
864
|
) => void,
|
865
|
-
fetchConfig?: MoveFetchConfig
|
865
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
866
866
|
): token_transfers {
|
867
867
|
this.onMoveEvent(
|
868
868
|
func,
|
@@ -879,7 +879,7 @@ export class token_transfers extends AptosBaseProcessor {
|
|
879
879
|
event: token_transfers.TokenClaimEventInstance,
|
880
880
|
ctx: AptosContext
|
881
881
|
) => void,
|
882
|
-
fetchConfig?: MoveFetchConfig
|
882
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
883
883
|
): token_transfers {
|
884
884
|
this.onMoveEvent(
|
885
885
|
func,
|
@@ -1000,7 +1000,7 @@ export class token_event_store extends AptosBaseProcessor {
|
|
1000
1000
|
event: token_event_store.CollectionUriMutateEventInstance,
|
1001
1001
|
ctx: AptosContext
|
1002
1002
|
) => void,
|
1003
|
-
fetchConfig?: MoveFetchConfig
|
1003
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
1004
1004
|
): token_event_store {
|
1005
1005
|
this.onMoveEvent(
|
1006
1006
|
func,
|
@@ -1017,7 +1017,7 @@ export class token_event_store extends AptosBaseProcessor {
|
|
1017
1017
|
event: token_event_store.CollectionMaxiumMutateEventInstance,
|
1018
1018
|
ctx: AptosContext
|
1019
1019
|
) => void,
|
1020
|
-
fetchConfig?: MoveFetchConfig
|
1020
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
1021
1021
|
): token_event_store {
|
1022
1022
|
this.onMoveEvent(
|
1023
1023
|
func,
|
@@ -1034,7 +1034,7 @@ export class token_event_store extends AptosBaseProcessor {
|
|
1034
1034
|
event: token_event_store.CollectionDescriptionMutateEventInstance,
|
1035
1035
|
ctx: AptosContext
|
1036
1036
|
) => void,
|
1037
|
-
fetchConfig?: MoveFetchConfig
|
1037
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
1038
1038
|
): token_event_store {
|
1039
1039
|
this.onMoveEvent(
|
1040
1040
|
func,
|
@@ -1051,7 +1051,7 @@ export class token_event_store extends AptosBaseProcessor {
|
|
1051
1051
|
event: token_event_store.OptInTransferEventInstance,
|
1052
1052
|
ctx: AptosContext
|
1053
1053
|
) => void,
|
1054
|
-
fetchConfig?: MoveFetchConfig
|
1054
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
1055
1055
|
): token_event_store {
|
1056
1056
|
this.onMoveEvent(
|
1057
1057
|
func,
|
@@ -1068,7 +1068,7 @@ export class token_event_store extends AptosBaseProcessor {
|
|
1068
1068
|
event: token_event_store.UriMutationEventInstance,
|
1069
1069
|
ctx: AptosContext
|
1070
1070
|
) => void,
|
1071
|
-
fetchConfig?: MoveFetchConfig
|
1071
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
1072
1072
|
): token_event_store {
|
1073
1073
|
this.onMoveEvent(
|
1074
1074
|
func,
|
@@ -1085,7 +1085,7 @@ export class token_event_store extends AptosBaseProcessor {
|
|
1085
1085
|
event: token_event_store.DefaultPropertyMutateEventInstance,
|
1086
1086
|
ctx: AptosContext
|
1087
1087
|
) => void,
|
1088
|
-
fetchConfig?: MoveFetchConfig
|
1088
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
1089
1089
|
): token_event_store {
|
1090
1090
|
this.onMoveEvent(
|
1091
1091
|
func,
|
@@ -1102,7 +1102,7 @@ export class token_event_store extends AptosBaseProcessor {
|
|
1102
1102
|
event: token_event_store.DescriptionMutateEventInstance,
|
1103
1103
|
ctx: AptosContext
|
1104
1104
|
) => void,
|
1105
|
-
fetchConfig?: MoveFetchConfig
|
1105
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
1106
1106
|
): token_event_store {
|
1107
1107
|
this.onMoveEvent(
|
1108
1108
|
func,
|
@@ -1119,7 +1119,7 @@ export class token_event_store extends AptosBaseProcessor {
|
|
1119
1119
|
event: token_event_store.RoyaltyMutateEventInstance,
|
1120
1120
|
ctx: AptosContext
|
1121
1121
|
) => void,
|
1122
|
-
fetchConfig?: MoveFetchConfig
|
1122
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
1123
1123
|
): token_event_store {
|
1124
1124
|
this.onMoveEvent(
|
1125
1125
|
func,
|
@@ -1136,7 +1136,7 @@ export class token_event_store extends AptosBaseProcessor {
|
|
1136
1136
|
event: token_event_store.MaxiumMutateEventInstance,
|
1137
1137
|
ctx: AptosContext
|
1138
1138
|
) => void,
|
1139
|
-
fetchConfig?: MoveFetchConfig
|
1139
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
1140
1140
|
): token_event_store {
|
1141
1141
|
this.onMoveEvent(
|
1142
1142
|
func,
|
@@ -1,13 +1,10 @@
|
|
1
1
|
import * as fs from 'fs'
|
2
|
-
import { MoveModuleBytecode
|
3
|
-
import { moduleQname, SPLITTER, TypeDescriptor } from '../../move/index.js'
|
2
|
+
import { MoveModuleBytecode } from '../move-types.js'
|
4
3
|
import chalk from 'chalk'
|
5
4
|
import { AptosNetwork } from '../network.js'
|
6
|
-
import {
|
7
|
-
import {
|
8
|
-
import { InternalMoveModule, InternalMoveStruct } from '../../move/internal-models.js'
|
5
|
+
import { join } from 'path'
|
6
|
+
import { AptosChainAdapter } from '../aptos-chain-adapter.js'
|
9
7
|
import { AbstractCodegen } from '../../move/abstract-codegen.js'
|
10
|
-
import {join} from "path";
|
11
8
|
|
12
9
|
export async function codegen(abisDir: string, outDir = join('src', 'types', 'aptos'), genExample = false) {
|
13
10
|
if (!fs.existsSync(abisDir)) {
|
@@ -18,59 +15,13 @@ export async function codegen(abisDir: string, outDir = join('src', 'types', 'ap
|
|
18
15
|
console.log(chalk.green(`Generated ${numFiles} for Aptos`))
|
19
16
|
}
|
20
17
|
|
21
|
-
function getRpcEndpoint(network: AptosNetwork): string {
|
22
|
-
switch (network) {
|
23
|
-
case AptosNetwork.TEST_NET:
|
24
|
-
return 'https://testnet.aptoslabs.com/'
|
25
|
-
}
|
26
|
-
return 'https://mainnet.aptoslabs.com/'
|
27
|
-
}
|
28
|
-
|
29
|
-
function getRpcClient(network: AptosNetwork): AptosClient {
|
30
|
-
return new AptosClient(getRpcEndpoint(network))
|
31
|
-
}
|
32
|
-
|
33
18
|
class AptosCodegen extends AbstractCodegen<MoveModuleBytecode[], AptosNetwork> {
|
34
19
|
ADDRESS_TYPE = 'Address'
|
35
20
|
MAIN_NET = AptosNetwork.MAIN_NET
|
36
21
|
TEST_NET = AptosNetwork.TEST_NET
|
37
22
|
PREFIX = 'Aptos'
|
38
23
|
|
39
|
-
|
40
|
-
|
41
|
-
return await client.getAccountModules(account)
|
42
|
-
}
|
43
|
-
|
44
|
-
toInternalModules(modules: MoveModuleBytecode[]): InternalMoveModule[] {
|
45
|
-
return modules.flatMap((m) => (m.abi ? [toInternalModule(m)] : []))
|
46
|
-
}
|
47
|
-
|
48
|
-
getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {
|
49
|
-
return getMeaningfulFunctionParams(params)
|
50
|
-
}
|
51
|
-
|
52
|
-
getEventStructs(module: InternalMoveModule) {
|
53
|
-
const qname = moduleQname(module)
|
54
|
-
const structMap = new Map<string, InternalMoveStruct>()
|
55
|
-
const eventMap = new Map<string, InternalMoveStruct>()
|
56
|
-
|
57
|
-
for (const struct of module.structs) {
|
58
|
-
structMap.set(qname + SPLITTER + struct.name, struct)
|
59
|
-
}
|
60
|
-
|
61
|
-
for (const struct of module.structs) {
|
62
|
-
for (const field of struct.fields) {
|
63
|
-
const t = field.type
|
64
|
-
if (t.qname === '0x1::event::EventHandle') {
|
65
|
-
const event = t.typeArgs[0].qname
|
66
|
-
const eventStruct = structMap.get(event)
|
67
|
-
if (eventStruct) {
|
68
|
-
eventMap.set(event, eventStruct)
|
69
|
-
}
|
70
|
-
}
|
71
|
-
}
|
72
|
-
}
|
73
|
-
|
74
|
-
return eventMap
|
24
|
+
constructor() {
|
25
|
+
super(AptosChainAdapter.INSTANCE)
|
75
26
|
}
|
76
27
|
}
|
package/src/aptos/move-coder.ts
CHANGED
@@ -6,12 +6,17 @@ import {
|
|
6
6
|
TransactionPayload_EntryFunctionPayload,
|
7
7
|
} from './move-types.js'
|
8
8
|
|
9
|
-
import { TypedEventInstance,
|
10
|
-
import { getMeaningfulFunctionParams } from './utils.js'
|
9
|
+
import { TypedEventInstance, TypedFunctionPayload, TypedMoveResource } from './models.js'
|
11
10
|
import { AbstractMoveCoder } from '../move/abstract-move-coder.js'
|
12
|
-
import {
|
11
|
+
import { AptosNetwork } from './network.js'
|
12
|
+
import { AptosChainAdapter } from './aptos-chain-adapter.js'
|
13
|
+
|
14
|
+
export class MoveCoder extends AbstractMoveCoder<AptosNetwork, MoveModuleBytecode[], Event | MoveResource> {
|
15
|
+
constructor(network: AptosNetwork) {
|
16
|
+
super(network)
|
17
|
+
this.adapter = new AptosChainAdapter()
|
18
|
+
}
|
13
19
|
|
14
|
-
export class MoveCoder extends AbstractMoveCoder<Event | MoveResource> {
|
15
20
|
load(module: MoveModuleBytecode) {
|
16
21
|
if (!module.abi) {
|
17
22
|
throw Error('Module without abi')
|
@@ -35,13 +40,9 @@ export class MoveCoder extends AbstractMoveCoder<Event | MoveResource> {
|
|
35
40
|
return this.filterAndDecodeStruct(typeQname, resources) as any
|
36
41
|
}
|
37
42
|
|
38
|
-
getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {
|
39
|
-
return getMeaningfulFunctionParams(params)
|
40
|
-
}
|
41
|
-
|
42
43
|
decodeFunctionPayload(payload: TransactionPayload_EntryFunctionPayload): TransactionPayload_EntryFunctionPayload {
|
43
44
|
const func = this.getMoveFunction(payload.function)
|
44
|
-
const params = getMeaningfulFunctionParams(func.params)
|
45
|
+
const params = this.adapter.getMeaningfulFunctionParams(func.params)
|
45
46
|
const argumentsDecoded = this.decodeArray(payload.arguments, params)
|
46
47
|
|
47
48
|
return {
|
@@ -51,7 +52,7 @@ export class MoveCoder extends AbstractMoveCoder<Event | MoveResource> {
|
|
51
52
|
}
|
52
53
|
}
|
53
54
|
|
54
|
-
export const MOVE_CODER = new MoveCoder()
|
55
|
+
export const MOVE_CODER = new MoveCoder(AptosNetwork.MAIN_NET)
|
55
56
|
|
56
57
|
export function defaultMoveCoder(): MoveCoder {
|
57
58
|
return MOVE_CODER
|
@@ -12,6 +12,7 @@ import { format } from 'prettier'
|
|
12
12
|
import { isFrameworkAccount, moduleQname, normalizeToJSName, SPLITTER, VECTOR_STR } from './utils.js'
|
13
13
|
import { camelCase, upperFirst } from 'lodash-es'
|
14
14
|
import { TypeDescriptor } from './types.js'
|
15
|
+
import { ChainAdapter } from './chain-adapter.js'
|
15
16
|
|
16
17
|
interface OutputFile {
|
17
18
|
fileName: string
|
@@ -34,13 +35,11 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
34
35
|
GENERATE_ON_ENTRY = true
|
35
36
|
PAYLOAD_OPTIONAL = false
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
// Aptos first signer and Sui's last TxContext are no use
|
43
|
-
abstract getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[]
|
38
|
+
chainAdapter: ChainAdapter<NetworkType, ModuleTypes>
|
39
|
+
|
40
|
+
protected constructor(chainAdapter: ChainAdapter<NetworkType, ModuleTypes>) {
|
41
|
+
this.chainAdapter = chainAdapter
|
42
|
+
}
|
44
43
|
|
45
44
|
readModulesFile(fullPath: string) {
|
46
45
|
return JSON.parse(fs.readFileSync(fullPath, 'utf-8'))
|
@@ -81,7 +80,7 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
81
80
|
}
|
82
81
|
const fullPath = path.resolve(srcDir, file)
|
83
82
|
const abi = this.readModulesFile(fullPath)
|
84
|
-
const modules = this.toInternalModules(abi)
|
83
|
+
const modules = this.chainAdapter.toInternalModules(abi)
|
85
84
|
|
86
85
|
for (const module of modules) {
|
87
86
|
loader.register(module, path.basename(file, '.json'))
|
@@ -100,8 +99,8 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
100
99
|
console.log(`download dependent module for account ${account} at ${network}`)
|
101
100
|
|
102
101
|
try {
|
103
|
-
const rawModules = await this.fetchModules(account, network)
|
104
|
-
const modules = this.toInternalModules(rawModules)
|
102
|
+
const rawModules = await this.chainAdapter.fetchModules(account, network)
|
103
|
+
const modules = this.chainAdapter.toInternalModules(rawModules)
|
105
104
|
|
106
105
|
fs.writeFileSync(path.resolve(srcDir, account + '.json'), JSON.stringify(rawModules, null, '\t'))
|
107
106
|
for (const module of modules) {
|
@@ -163,7 +162,7 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
163
162
|
const clientFunctions = this.GENERATE_CLIENT
|
164
163
|
? module.exposedFunctions.map((f) => this.generateClientFunctions(module, f)).filter((s) => s !== '')
|
165
164
|
: []
|
166
|
-
const eventStructs = this.getEventStructs(module)
|
165
|
+
const eventStructs = this.chainAdapter.getEventStructs(module)
|
167
166
|
const eventTypes = new Set(eventStructs.keys())
|
168
167
|
const events = Array.from(eventStructs.values())
|
169
168
|
.map((e) => this.generateOnEvents(module, e))
|
@@ -282,7 +281,7 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
282
281
|
return
|
283
282
|
}
|
284
283
|
|
285
|
-
const fields = this.getMeaningfulFunctionParams(func.params).map((param) => {
|
284
|
+
const fields = this.chainAdapter.getMeaningfulFunctionParams(func.params).map((param) => {
|
286
285
|
return this.generateTypeForDescriptor(param, module.address) + (this.PAYLOAD_OPTIONAL ? ' | undefined' : '')
|
287
286
|
})
|
288
287
|
|
@@ -307,7 +306,7 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
307
306
|
}
|
308
307
|
// const moduleName = normalizeToJSName(module.name)
|
309
308
|
const funcName = camelCase(func.name)
|
310
|
-
const fields = this.getMeaningfulFunctionParams(func.params).map((param) => {
|
309
|
+
const fields = this.chainAdapter.getMeaningfulFunctionParams(func.params).map((param) => {
|
311
310
|
return this.generateTypeForDescriptor(param, module.address)
|
312
311
|
})
|
313
312
|
const genericString = this.generateFunctionTypeParameters(func)
|
@@ -359,7 +358,7 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
359
358
|
const source = `
|
360
359
|
onEvent${struct.name}(func: (event: ${moduleName}.${normalizeToJSName(struct.name)}Instance, ctx: ${
|
361
360
|
this.PREFIX
|
362
|
-
}Context) => void, fetchConfig?: MoveFetchConfig): ${moduleName} {
|
361
|
+
}Context) => void, fetchConfig?: Partial<MoveFetchConfig>): ${moduleName} {
|
363
362
|
this.onMoveEvent(func, {
|
364
363
|
type: '${module.name}::${struct.name}'
|
365
364
|
},
|
@@ -2,6 +2,7 @@ import { moduleQname, SPLITTER, VECTOR_STR } from './utils.js'
|
|
2
2
|
import { parseMoveType, TypeDescriptor } from './types.js'
|
3
3
|
import { InternalMoveFunction, InternalMoveModule, InternalMoveStruct } from './internal-models.js'
|
4
4
|
import { bytesToBigInt } from '../utils/index.js'
|
5
|
+
import { ChainAdapter } from './chain-adapter.js'
|
5
6
|
|
6
7
|
export type StructWithTag<Base> = {
|
7
8
|
type: string
|
@@ -13,16 +14,22 @@ export type DecodedStructWithTag<B, T> = StructWithTag<B> & {
|
|
13
14
|
type_arguments: string[]
|
14
15
|
}
|
15
16
|
|
16
|
-
export abstract class AbstractMoveCoder<StructType> {
|
17
|
+
export abstract class AbstractMoveCoder<Network, ModuleTypes, StructType> {
|
17
18
|
private moduleMapping = new Map<string, InternalMoveModule>()
|
18
19
|
private typeMapping = new Map<string, InternalMoveStruct>()
|
19
20
|
private funcMapping = new Map<string, InternalMoveFunction>()
|
21
|
+
network: Network
|
22
|
+
adapter: ChainAdapter<Network, ModuleTypes>
|
23
|
+
|
24
|
+
protected constructor(network: Network) {
|
25
|
+
this.network = network
|
26
|
+
}
|
20
27
|
|
21
28
|
contains(account: string, name: string) {
|
22
29
|
return this.moduleMapping.has(account + '::' + name)
|
23
30
|
}
|
24
31
|
|
25
|
-
protected abstract getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[]
|
32
|
+
// protected abstract getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[]
|
26
33
|
|
27
34
|
protected toStructWithTag(val: StructType): StructWithTag<StructType> {
|
28
35
|
return val as any
|
@@ -232,7 +239,7 @@ export abstract class AbstractMoveCoder<StructType> {
|
|
232
239
|
|
233
240
|
encodeCallArgs(args: any[], func: string): any[] {
|
234
241
|
const f = this.getMoveFunction(func)
|
235
|
-
return this.encodeArray(args, this.getMeaningfulFunctionParams(f.params))
|
242
|
+
return this.encodeArray(args, this.adapter.getMeaningfulFunctionParams(f.params))
|
236
243
|
}
|
237
244
|
|
238
245
|
decodeCallResult(res: any[], func: string): any[] {
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { InternalMoveModule, InternalMoveStruct } from './internal-models.js'
|
2
|
+
import { TypeDescriptor } from './types.js'
|
3
|
+
|
4
|
+
export abstract class ChainAdapter<NetworkType, ModuleTypes> {
|
5
|
+
abstract fetchModules(account: string, network: NetworkType): Promise<ModuleTypes>
|
6
|
+
|
7
|
+
abstract fetchModules(account: string, network: NetworkType): Promise<ModuleTypes>
|
8
|
+
abstract toInternalModules(modules: ModuleTypes): InternalMoveModule[]
|
9
|
+
// Get the structs that represent Events
|
10
|
+
abstract getEventStructs(module: InternalMoveModule): Map<string, InternalMoveStruct>
|
11
|
+
// Get the parameters that actually have arguments in runtime
|
12
|
+
// Aptos first signer and Sui's last TxContext are no use
|
13
|
+
abstract getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[]
|
14
|
+
}
|
package/src/move/index.ts
CHANGED
package/src/sui/builtin/0x1.ts
CHANGED
@@ -35,7 +35,7 @@ export class ascii extends SuiBaseProcessor {
|
|
35
35
|
|
36
36
|
onEventChar(
|
37
37
|
func: (event: ascii.CharInstance, ctx: SuiContext) => void,
|
38
|
-
fetchConfig?: MoveFetchConfig
|
38
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
39
39
|
): ascii {
|
40
40
|
this.onMoveEvent(
|
41
41
|
func,
|
@@ -49,7 +49,7 @@ export class ascii extends SuiBaseProcessor {
|
|
49
49
|
|
50
50
|
onEventString(
|
51
51
|
func: (event: ascii.StringInstance, ctx: SuiContext) => void,
|
52
|
-
fetchConfig?: MoveFetchConfig
|
52
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
53
53
|
): ascii {
|
54
54
|
this.onMoveEvent(
|
55
55
|
func,
|
@@ -101,7 +101,7 @@ export class bit_vector extends SuiBaseProcessor {
|
|
101
101
|
|
102
102
|
onEventBitVector(
|
103
103
|
func: (event: bit_vector.BitVectorInstance, ctx: SuiContext) => void,
|
104
|
-
fetchConfig?: MoveFetchConfig
|
104
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
105
105
|
): bit_vector {
|
106
106
|
this.onMoveEvent(
|
107
107
|
func,
|
@@ -144,7 +144,7 @@ export class fixed_point32 extends SuiBaseProcessor {
|
|
144
144
|
|
145
145
|
onEventFixedPoint32(
|
146
146
|
func: (event: fixed_point32.FixedPoint32Instance, ctx: SuiContext) => void,
|
147
|
-
fetchConfig?: MoveFetchConfig
|
147
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
148
148
|
): fixed_point32 {
|
149
149
|
this.onMoveEvent(
|
150
150
|
func,
|
@@ -191,7 +191,7 @@ export class string_ extends SuiBaseProcessor {
|
|
191
191
|
|
192
192
|
onEventString(
|
193
193
|
func: (event: string_.StringInstance, ctx: SuiContext) => void,
|
194
|
-
fetchConfig?: MoveFetchConfig
|
194
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
195
195
|
): string_ {
|
196
196
|
this.onMoveEvent(
|
197
197
|
func,
|
@@ -231,7 +231,7 @@ export class type_name extends SuiBaseProcessor {
|
|
231
231
|
|
232
232
|
onEventTypeName(
|
233
233
|
func: (event: type_name.TypeNameInstance, ctx: SuiContext) => void,
|
234
|
-
fetchConfig?: MoveFetchConfig
|
234
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
235
235
|
): type_name {
|
236
236
|
this.onMoveEvent(
|
237
237
|
func,
|
package/src/sui/builtin/0x2.ts
CHANGED
@@ -57,7 +57,7 @@ export class bcs extends SuiBaseProcessor {
|
|
57
57
|
|
58
58
|
onEventBCS(
|
59
59
|
func: (event: bcs.BCSInstance, ctx: SuiContext) => void,
|
60
|
-
fetchConfig?: MoveFetchConfig
|
60
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
61
61
|
): bcs {
|
62
62
|
this.onMoveEvent(
|
63
63
|
func,
|
@@ -233,7 +233,7 @@ export class coin extends SuiBaseProcessor {
|
|
233
233
|
|
234
234
|
onEventCurrencyCreated(
|
235
235
|
func: (event: coin.CurrencyCreatedInstance, ctx: SuiContext) => void,
|
236
|
-
fetchConfig?: MoveFetchConfig
|
236
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
237
237
|
): coin {
|
238
238
|
this.onMoveEvent(
|
239
239
|
func,
|
@@ -444,7 +444,7 @@ export class display extends SuiBaseProcessor {
|
|
444
444
|
|
445
445
|
onEventDisplayCreated(
|
446
446
|
func: (event: display.DisplayCreatedInstance, ctx: SuiContext) => void,
|
447
|
-
fetchConfig?: MoveFetchConfig
|
447
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
448
448
|
): display {
|
449
449
|
this.onMoveEvent(
|
450
450
|
func,
|
@@ -458,7 +458,7 @@ export class display extends SuiBaseProcessor {
|
|
458
458
|
|
459
459
|
onEventVersionUpdated(
|
460
460
|
func: (event: display.VersionUpdatedInstance, ctx: SuiContext) => void,
|
461
|
-
fetchConfig?: MoveFetchConfig
|
461
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
462
462
|
): display {
|
463
463
|
this.onMoveEvent(
|
464
464
|
func,
|
@@ -572,7 +572,7 @@ export class dynamic_object_field extends SuiBaseProcessor {
|
|
572
572
|
event: dynamic_object_field.WrapperInstance,
|
573
573
|
ctx: SuiContext
|
574
574
|
) => void,
|
575
|
-
fetchConfig?: MoveFetchConfig
|
575
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
576
576
|
): dynamic_object_field {
|
577
577
|
this.onMoveEvent(
|
578
578
|
func,
|
@@ -622,7 +622,7 @@ export class groth16 extends SuiBaseProcessor {
|
|
622
622
|
|
623
623
|
onEventCurve(
|
624
624
|
func: (event: groth16.CurveInstance, ctx: SuiContext) => void,
|
625
|
-
fetchConfig?: MoveFetchConfig
|
625
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
626
626
|
): groth16 {
|
627
627
|
this.onMoveEvent(
|
628
628
|
func,
|
@@ -639,7 +639,7 @@ export class groth16 extends SuiBaseProcessor {
|
|
639
639
|
event: groth16.PreparedVerifyingKeyInstance,
|
640
640
|
ctx: SuiContext
|
641
641
|
) => void,
|
642
|
-
fetchConfig?: MoveFetchConfig
|
642
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
643
643
|
): groth16 {
|
644
644
|
this.onMoveEvent(
|
645
645
|
func,
|
@@ -653,7 +653,7 @@ export class groth16 extends SuiBaseProcessor {
|
|
653
653
|
|
654
654
|
onEventProofPoints(
|
655
655
|
func: (event: groth16.ProofPointsInstance, ctx: SuiContext) => void,
|
656
|
-
fetchConfig?: MoveFetchConfig
|
656
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
657
657
|
): groth16 {
|
658
658
|
this.onMoveEvent(
|
659
659
|
func,
|
@@ -667,7 +667,7 @@ export class groth16 extends SuiBaseProcessor {
|
|
667
667
|
|
668
668
|
onEventPublicProofInputs(
|
669
669
|
func: (event: groth16.PublicProofInputsInstance, ctx: SuiContext) => void,
|
670
|
-
fetchConfig?: MoveFetchConfig
|
670
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
671
671
|
): groth16 {
|
672
672
|
this.onMoveEvent(
|
673
673
|
func,
|
@@ -748,7 +748,7 @@ export class kiosk extends SuiBaseProcessor {
|
|
748
748
|
|
749
749
|
onEventItem(
|
750
750
|
func: (event: kiosk.ItemInstance, ctx: SuiContext) => void,
|
751
|
-
fetchConfig?: MoveFetchConfig
|
751
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
752
752
|
): kiosk {
|
753
753
|
this.onMoveEvent(
|
754
754
|
func,
|
@@ -762,7 +762,7 @@ export class kiosk extends SuiBaseProcessor {
|
|
762
762
|
|
763
763
|
onEventItemListed(
|
764
764
|
func: (event: kiosk.ItemListedInstance, ctx: SuiContext) => void,
|
765
|
-
fetchConfig?: MoveFetchConfig
|
765
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
766
766
|
): kiosk {
|
767
767
|
this.onMoveEvent(
|
768
768
|
func,
|
@@ -776,7 +776,7 @@ export class kiosk extends SuiBaseProcessor {
|
|
776
776
|
|
777
777
|
onEventListing(
|
778
778
|
func: (event: kiosk.ListingInstance, ctx: SuiContext) => void,
|
779
|
-
fetchConfig?: MoveFetchConfig
|
779
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
780
780
|
): kiosk {
|
781
781
|
this.onMoveEvent(
|
782
782
|
func,
|
@@ -790,7 +790,7 @@ export class kiosk extends SuiBaseProcessor {
|
|
790
790
|
|
791
791
|
onEventLock(
|
792
792
|
func: (event: kiosk.LockInstance, ctx: SuiContext) => void,
|
793
|
-
fetchConfig?: MoveFetchConfig
|
793
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
794
794
|
): kiosk {
|
795
795
|
this.onMoveEvent(
|
796
796
|
func,
|
@@ -1296,7 +1296,7 @@ export class transfer_policy extends SuiBaseProcessor {
|
|
1296
1296
|
|
1297
1297
|
onEventRuleKey(
|
1298
1298
|
func: (event: transfer_policy.RuleKeyInstance, ctx: SuiContext) => void,
|
1299
|
-
fetchConfig?: MoveFetchConfig
|
1299
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
1300
1300
|
): transfer_policy {
|
1301
1301
|
this.onMoveEvent(
|
1302
1302
|
func,
|
@@ -1313,7 +1313,7 @@ export class transfer_policy extends SuiBaseProcessor {
|
|
1313
1313
|
event: transfer_policy.TransferPolicyCreatedInstance,
|
1314
1314
|
ctx: SuiContext
|
1315
1315
|
) => void,
|
1316
|
-
fetchConfig?: MoveFetchConfig
|
1316
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
1317
1317
|
): transfer_policy {
|
1318
1318
|
this.onMoveEvent(
|
1319
1319
|
func,
|
@@ -1398,7 +1398,7 @@ export class url extends SuiBaseProcessor {
|
|
1398
1398
|
|
1399
1399
|
onEventUrl(
|
1400
1400
|
func: (event: url.UrlInstance, ctx: SuiContext) => void,
|
1401
|
-
fetchConfig?: MoveFetchConfig
|
1401
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
1402
1402
|
): url {
|
1403
1403
|
this.onMoveEvent(
|
1404
1404
|
func,
|
@@ -1438,7 +1438,7 @@ export class vec_map extends SuiBaseProcessor {
|
|
1438
1438
|
|
1439
1439
|
onEventEntry(
|
1440
1440
|
func: (event: vec_map.EntryInstance, ctx: SuiContext) => void,
|
1441
|
-
fetchConfig?: MoveFetchConfig
|
1441
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
1442
1442
|
): vec_map {
|
1443
1443
|
this.onMoveEvent(
|
1444
1444
|
func,
|
@@ -1452,7 +1452,7 @@ export class vec_map extends SuiBaseProcessor {
|
|
1452
1452
|
|
1453
1453
|
onEventVecMap(
|
1454
1454
|
func: (event: vec_map.VecMapInstance, ctx: SuiContext) => void,
|
1455
|
-
fetchConfig?: MoveFetchConfig
|
1455
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
1456
1456
|
): vec_map {
|
1457
1457
|
this.onMoveEvent(
|
1458
1458
|
func,
|
@@ -1503,7 +1503,7 @@ export class vec_set extends SuiBaseProcessor {
|
|
1503
1503
|
|
1504
1504
|
onEventVecSet(
|
1505
1505
|
func: (event: vec_set.VecSetInstance, ctx: SuiContext) => void,
|
1506
|
-
fetchConfig?: MoveFetchConfig
|
1506
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
1507
1507
|
): vec_set {
|
1508
1508
|
this.onMoveEvent(
|
1509
1509
|
func,
|