@sentio/sdk 2.4.0 → 2.5.0-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/aptos-processor.d.ts +1 -1
- package/lib/aptos/aptos-processor.js +1 -1
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/builtin/0x1.d.ts +16 -177
- package/lib/aptos/builtin/0x1.js +56 -538
- package/lib/aptos/builtin/0x1.js.map +1 -1
- package/lib/aptos/builtin/0x3.d.ts +2 -13
- package/lib/aptos/builtin/0x3.js +20 -48
- package/lib/aptos/builtin/0x3.js.map +1 -1
- package/lib/aptos/codegen/codegen.d.ts +0 -20
- package/lib/aptos/codegen/codegen.js +37 -357
- package/lib/aptos/codegen/codegen.js.map +1 -1
- package/lib/aptos/{types.test.d.ts → codegen/types.test.d.ts} +0 -0
- package/lib/aptos/codegen/types.test.js.map +1 -0
- package/lib/aptos/models.d.ts +0 -8
- package/lib/aptos/models.js.map +1 -1
- package/lib/aptos/move-coder.d.ts +4 -13
- package/lib/aptos/move-coder.js +13 -124
- package/lib/aptos/move-coder.js.map +1 -1
- package/lib/aptos/move-types.d.ts +6 -0
- package/lib/aptos/move-types.js +52 -1
- package/lib/aptos/move-types.js.map +1 -1
- package/lib/aptos/tests/souffl3.js +1 -1
- package/lib/aptos/tests/souffl3.js.map +1 -1
- package/lib/aptos/tests/types/reserved.d.ts +2 -8
- package/lib/aptos/tests/types/reserved.js +11 -24
- package/lib/aptos/tests/types/reserved.js.map +1 -1
- package/lib/aptos/tests/types/soffl3.d.ts +2 -14
- package/lib/aptos/tests/types/soffl3.js +15 -48
- package/lib/aptos/tests/types/soffl3.js.map +1 -1
- package/lib/aptos/tests/types/souffle.d.ts +2 -8
- package/lib/aptos/tests/types/souffle.js +11 -24
- package/lib/aptos/tests/types/souffle.js.map +1 -1
- package/lib/aptos/utils.d.ts +2 -7
- package/lib/aptos/utils.js +2 -15
- package/lib/aptos/utils.js.map +1 -1
- package/lib/eth/bind-options.js +6 -0
- package/lib/eth/bind-options.js.map +1 -1
- package/lib/eth/tests/codegen.test.js.map +1 -1
- package/lib/eth/tests/erc20.js +1 -1
- package/lib/eth/tests/erc20.js.map +1 -1
- package/lib/eth/tests/logger.test.js.map +1 -1
- package/lib/move/abstract-codegen.d.ts +44 -0
- package/lib/move/abstract-codegen.js +341 -0
- package/lib/move/abstract-codegen.js.map +1 -0
- package/lib/move/abstract-move-coder.d.ts +24 -0
- package/lib/move/abstract-move-coder.js +141 -0
- package/lib/move/abstract-move-coder.js.map +1 -0
- package/lib/move/account.d.ts +18 -0
- package/lib/{aptos/codegen/typegen.js → move/account.js} +20 -82
- package/lib/move/account.js.map +1 -0
- package/lib/move/filter.d.ts +25 -0
- package/lib/move/filter.js +11 -0
- package/lib/move/filter.js.map +1 -0
- package/lib/move/index.d.ts +5 -25
- package/lib/move/index.js +5 -10
- package/lib/move/index.js.map +1 -1
- package/lib/move/neutral-models.d.ts +34 -0
- package/lib/move/neutral-models.js +7 -0
- package/lib/move/neutral-models.js.map +1 -0
- package/lib/move/ts-type.d.ts +2 -0
- package/lib/move/ts-type.js +77 -0
- package/lib/move/ts-type.js.map +1 -0
- package/lib/{aptos/codegen/typegen.test.d.ts → move/ts-type.test.d.ts} +0 -0
- package/lib/move/ts-type.test.js.map +1 -0
- package/lib/{aptos → move}/types.d.ts +1 -0
- package/lib/{aptos → move}/types.js +26 -3
- package/lib/move/types.js.map +1 -0
- package/lib/move/utils.d.ts +9 -0
- package/lib/move/utils.js +20 -0
- package/lib/move/utils.js.map +1 -0
- package/lib/sui/builtin/0x1.d.ts +114 -0
- package/lib/sui/builtin/0x1.js +174 -0
- package/lib/sui/builtin/0x1.js.map +1 -0
- package/lib/sui/builtin/0x2.d.ts +1047 -0
- package/lib/sui/builtin/0x2.js +1295 -0
- package/lib/sui/builtin/0x2.js.map +1 -0
- package/lib/sui/builtin/index.d.ts +2 -0
- package/lib/sui/builtin/index.js +6 -0
- package/lib/sui/builtin/index.js.map +1 -0
- package/lib/sui/codegen/codegen.d.ts +1 -0
- package/lib/sui/codegen/codegen.js +61 -0
- package/lib/sui/codegen/codegen.js.map +1 -0
- package/lib/sui/codegen/index.d.ts +1 -0
- package/lib/sui/codegen/index.js +2 -0
- package/lib/sui/codegen/index.js.map +1 -0
- package/lib/sui/codegen/run.d.ts +1 -0
- package/lib/sui/codegen/run.js +12 -0
- package/lib/sui/codegen/run.js.map +1 -0
- package/lib/sui/index.d.ts +2 -0
- package/lib/sui/index.js +1 -0
- package/lib/sui/index.js.map +1 -1
- package/lib/sui/models.d.ts +7 -1
- package/lib/sui/models.js +0 -23
- package/lib/sui/models.js.map +1 -1
- package/lib/sui/move-coder.d.ts +11 -0
- package/lib/sui/move-coder.js +53 -0
- package/lib/sui/move-coder.js.map +1 -0
- package/lib/sui/move-types.d.ts +9 -0
- package/lib/sui/move-types.js +81 -0
- package/lib/sui/move-types.js.map +1 -0
- package/lib/sui/sui-processor.js +3 -3
- package/lib/sui/sui-processor.js.map +1 -1
- package/lib/sui/tests/sui.test.js.map +1 -1
- package/lib/sui/tests/types/index.d.ts +1 -0
- package/lib/sui/tests/types/index.js +5 -0
- package/lib/sui/tests/types/index.js.map +1 -0
- package/lib/sui/tests/types/testnet/index.d.ts +1 -0
- package/lib/sui/tests/types/testnet/index.js +5 -0
- package/lib/sui/tests/types/testnet/index.js.map +1 -0
- package/lib/sui/tests/types/testnet/swap.d.ts +249 -0
- package/lib/sui/tests/types/testnet/swap.js +310 -0
- package/lib/sui/tests/types/testnet/swap.js.map +1 -0
- package/lib/testing/aptos-facet.js +1 -1
- package/lib/testing/aptos-facet.js.map +1 -1
- package/lib/testing/sui-facet.js +3 -2
- package/lib/testing/sui-facet.js.map +1 -1
- package/package.json +8 -5
- package/src/aptos/aptos-processor.ts +1 -1
- package/src/aptos/builtin/0x1.ts +70 -652
- package/src/aptos/builtin/0x3.ts +24 -59
- package/src/aptos/codegen/codegen.ts +35 -421
- package/src/aptos/models.ts +0 -10
- package/src/aptos/move-coder.ts +16 -150
- package/src/aptos/move-types.ts +62 -0
- package/src/aptos/tests/souffl3.ts +1 -1
- package/src/aptos/tests/types/reserved.ts +15 -30
- package/src/aptos/tests/types/soffl3.ts +19 -58
- package/src/aptos/tests/types/souffle.ts +15 -30
- package/src/aptos/utils.ts +3 -21
- package/src/eth/bind-options.ts +6 -0
- package/src/eth/tests/erc20.ts +1 -1
- package/src/move/abstract-codegen.ts +426 -0
- package/src/move/abstract-move-coder.ts +170 -0
- package/src/move/account.ts +96 -0
- package/src/move/filter.ts +33 -0
- package/src/move/index.ts +5 -33
- package/src/move/neutral-models.ts +45 -0
- package/src/move/ts-type.ts +86 -0
- package/src/{aptos → move}/types.ts +28 -3
- package/src/move/utils.ts +25 -0
- package/src/sui/abis/0x1.json +1729 -1733
- package/src/sui/abis/0x2.json +13279 -13283
- package/src/sui/builtin/0x1.ts +307 -0
- package/src/sui/builtin/0x2.ts +2578 -0
- package/src/sui/builtin/index.ts +5 -0
- package/src/sui/codegen/codegen.ts +71 -0
- package/src/sui/codegen/index.ts +1 -0
- package/src/sui/codegen/run.ts +13 -0
- package/src/sui/index.ts +4 -0
- package/src/sui/models.ts +7 -28
- package/src/sui/move-coder.ts +63 -0
- package/src/sui/move-types.ts +109 -0
- package/src/sui/sui-processor.ts +3 -3
- package/src/sui/tests/abis/testnet/swap.json +1752 -0
- package/src/sui/tests/types/index.ts +3 -0
- package/src/sui/tests/types/testnet/index.ts +4 -0
- package/src/sui/tests/types/testnet/swap.ts +698 -0
- package/src/testing/aptos-facet.ts +1 -1
- package/src/testing/sui-facet.ts +3 -2
- package/lib/aptos/codegen/typegen.d.ts +0 -18
- package/lib/aptos/codegen/typegen.js.map +0 -1
- package/lib/aptos/codegen/typegen.test.js.map +0 -1
- package/lib/aptos/types.js.map +0 -1
- package/lib/aptos/types.test.js.map +0 -1
- package/lib/jest.config.d.ts +0 -9
- package/lib/jest.config.js +0 -9
- package/lib/jest.config.js.map +0 -1
- package/src/aptos/codegen/typegen.ts +0 -165
- package/src/jest.config.ts +0 -8
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { SuiNetwork } from '../network.js'
|
|
2
|
+
import * as fs from 'fs'
|
|
3
|
+
import chalk from 'chalk'
|
|
4
|
+
import { NeutralMoveModule, NeutralMoveStruct } from '../../move/neutral-models.js'
|
|
5
|
+
import { AbstractCodegen } from '../../move/abstract-codegen.js'
|
|
6
|
+
import { JsonRpcProvider, SuiMoveNormalizedModules } from '@mysten/sui.js'
|
|
7
|
+
import { toNeutralModule } from '../move-types.js'
|
|
8
|
+
import { moduleQname, SPLITTER, TypeDescriptor } from '../../move/index.js'
|
|
9
|
+
|
|
10
|
+
export async function codegen(abisDir: string, outDir = 'src/types/sui') {
|
|
11
|
+
if (!fs.existsSync(abisDir)) {
|
|
12
|
+
return
|
|
13
|
+
}
|
|
14
|
+
console.log(chalk.green('Generated Types for Sui'))
|
|
15
|
+
const gen = new SuiCodeGen()
|
|
16
|
+
await gen.generate(abisDir, outDir)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getRpcEndpoint(network: SuiNetwork): string {
|
|
20
|
+
switch (network) {
|
|
21
|
+
case SuiNetwork.TEST_NET:
|
|
22
|
+
return 'https://fullnode.testnet.sui.io/'
|
|
23
|
+
}
|
|
24
|
+
return 'https://fullnode.mainnet.sui.io/'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getRpcClient(network: SuiNetwork): JsonRpcProvider {
|
|
28
|
+
return new JsonRpcProvider(getRpcEndpoint(network))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
class SuiCodeGen extends AbstractCodegen<SuiMoveNormalizedModules, SuiNetwork> {
|
|
32
|
+
ADDRESS_TYPE = 'SuiAddress'
|
|
33
|
+
MAIN_NET = SuiNetwork.MAIN_NET
|
|
34
|
+
TEST_NET = SuiNetwork.TEST_NET
|
|
35
|
+
PREFIX = 'Sui'
|
|
36
|
+
STRUCT_FIELD_NAME = 'fields'
|
|
37
|
+
|
|
38
|
+
async fetchModules(account: string, network: SuiNetwork): Promise<SuiMoveNormalizedModules> {
|
|
39
|
+
const client = getRpcClient(network)
|
|
40
|
+
return await client.getNormalizedMoveModulesByPackage(account)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {
|
|
44
|
+
return params.slice(0, params.length - 1)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
toNeutral(modules: SuiMoveNormalizedModules): NeutralMoveModule[] {
|
|
48
|
+
return Object.values(modules).map(toNeutralModule)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
getEventStructs(module: NeutralMoveModule) {
|
|
52
|
+
const qname = moduleQname(module)
|
|
53
|
+
const eventMap = new Map<string, NeutralMoveStruct>()
|
|
54
|
+
|
|
55
|
+
for (const struct of module.structs) {
|
|
56
|
+
const abilities = new Set(struct.abilities)
|
|
57
|
+
if (abilities.has('Drop') && abilities.has('Copy')) {
|
|
58
|
+
eventMap.set(qname + SPLITTER + struct.name, struct)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return eventMap
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
readModulesFile(fullPath: string) {
|
|
65
|
+
const res = super.readModulesFile(fullPath)
|
|
66
|
+
if (res.result) {
|
|
67
|
+
return res.result
|
|
68
|
+
}
|
|
69
|
+
return res
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './codegen.js'
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// #!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { codegen } from './codegen.js'
|
|
4
|
+
|
|
5
|
+
if (process.argv.length > 3) {
|
|
6
|
+
const abisDir = process.argv[2]
|
|
7
|
+
const targetDir = process.argv[3]
|
|
8
|
+
|
|
9
|
+
await codegen(abisDir, targetDir)
|
|
10
|
+
} else {
|
|
11
|
+
console.error('Not enough argument')
|
|
12
|
+
process.exit(1)
|
|
13
|
+
}
|
package/src/sui/index.ts
CHANGED
package/src/sui/models.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import { MoveEvent } from '@mysten/sui.js'
|
|
1
|
+
import { MoveEvent, MoveCall } from '@mysten/sui.js'
|
|
2
2
|
|
|
3
|
-
// export type MoveEvent = MoveEvent & {
|
|
4
|
-
// }
|
|
5
|
-
|
|
6
|
-
//
|
|
7
3
|
export type TypedEventInstance<T> = MoveEvent & {
|
|
8
4
|
/**
|
|
9
5
|
* decoded data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch
|
|
@@ -13,26 +9,9 @@ export type TypedEventInstance<T> = MoveEvent & {
|
|
|
13
9
|
type_arguments: string[]
|
|
14
10
|
}
|
|
15
11
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// arguments_decoded: T
|
|
23
|
-
// }
|
|
24
|
-
//
|
|
25
|
-
// export type TypedMoveResource<T> = MoveResource & {
|
|
26
|
-
// data_decoded: T
|
|
27
|
-
// type_arguments: string[]
|
|
28
|
-
// }
|
|
29
|
-
//
|
|
30
|
-
// export interface StructWithTag {
|
|
31
|
-
// type: string
|
|
32
|
-
// data: any
|
|
33
|
-
// }
|
|
34
|
-
//
|
|
35
|
-
// export interface StructWithType<T> extends StructWithTag {
|
|
36
|
-
// data_decoded: T
|
|
37
|
-
// type_arguments: string[]
|
|
38
|
-
// }
|
|
12
|
+
export type TypedEntryFunctionPayload<T extends Array<any>> = MoveCall & {
|
|
13
|
+
/**
|
|
14
|
+
* decoded argument data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch
|
|
15
|
+
*/
|
|
16
|
+
arguments_decoded: T
|
|
17
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { TypedEventInstance, TypedEntryFunctionPayload } from './models.js'
|
|
2
|
+
import { AbstractMoveCoder } from '../move/abstract-move-coder.js'
|
|
3
|
+
import { MoveCall, MoveEvent, SuiMoveNormalizedModule } from '@mysten/sui.js'
|
|
4
|
+
import { toNeutralModule } from './move-types.js'
|
|
5
|
+
import { SPLITTER } from '../move/index.js'
|
|
6
|
+
|
|
7
|
+
export class MoveCoder extends AbstractMoveCoder<MoveEvent> {
|
|
8
|
+
load(module: SuiMoveNormalizedModule) {
|
|
9
|
+
if (this.contains(module.address, module.name)) {
|
|
10
|
+
return
|
|
11
|
+
}
|
|
12
|
+
this.loadNeutral(toNeutralModule(module))
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
decodeEvent<T>(event: MoveEvent): TypedEventInstance<T> | undefined {
|
|
16
|
+
const res = this.decodedInternal<T>({ ...event, data: event.fields })
|
|
17
|
+
return { ...event, fields_decoded: res?.data_decoded as T, type_arguments: res?.type_arguments || [] }
|
|
18
|
+
}
|
|
19
|
+
filterAndDecodeEvents<T>(typeQname: string, resources: MoveEvent[]): TypedEventInstance<T>[] {
|
|
20
|
+
const resp = this.filterAndDecodeInternal(
|
|
21
|
+
typeQname,
|
|
22
|
+
resources.map((event) => {
|
|
23
|
+
return { ...event, data: event.fields, type: event.type }
|
|
24
|
+
})
|
|
25
|
+
)
|
|
26
|
+
return resp.map((res) => {
|
|
27
|
+
delete res.data_decoded
|
|
28
|
+
const event = res as MoveEvent
|
|
29
|
+
return { ...event, fields_decoded: res?.data_decoded as T, type_arguments: res?.type_arguments || [] }
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
decodeFunctionPayload(payload: MoveCall): MoveCall {
|
|
34
|
+
// this.loadTypes(registry)
|
|
35
|
+
const argumentsTyped: any[] = []
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
const functionType = [payload.package.objectId, payload.module, payload.function].join(SPLITTER)
|
|
39
|
+
const func = this.getMoveFunction(functionType)
|
|
40
|
+
const params = func.params.slice(0, func.params.length - 1)
|
|
41
|
+
const args = payload.arguments || []
|
|
42
|
+
for (const [idx, arg] of args.entries()) {
|
|
43
|
+
// TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them
|
|
44
|
+
const argType = params[idx]
|
|
45
|
+
argumentsTyped.push(this.decode(arg, argType))
|
|
46
|
+
}
|
|
47
|
+
} catch (e) {
|
|
48
|
+
console.error('Decoding error for ', JSON.stringify(payload), e)
|
|
49
|
+
return payload
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
...payload,
|
|
54
|
+
arguments_decoded: argumentsTyped,
|
|
55
|
+
} as TypedEntryFunctionPayload<any>
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const MOVE_CODER = new MoveCoder()
|
|
60
|
+
|
|
61
|
+
export function defaultMoveCoder(): MoveCoder {
|
|
62
|
+
return MOVE_CODER
|
|
63
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SuiMoveNormalizedField,
|
|
3
|
+
SuiMoveNormalizedFunction,
|
|
4
|
+
SuiMoveNormalizedModule,
|
|
5
|
+
SuiMoveNormalizedStruct,
|
|
6
|
+
SuiMoveNormalizedType,
|
|
7
|
+
} from '@mysten/sui.js'
|
|
8
|
+
import {
|
|
9
|
+
NeutralMoveFunction,
|
|
10
|
+
NeutralMoveFunctionVisibility,
|
|
11
|
+
NeutralMoveModule,
|
|
12
|
+
NeutralMoveStruct,
|
|
13
|
+
NeutralMoveStructField,
|
|
14
|
+
} from '../move/neutral-models.js'
|
|
15
|
+
import { SPLITTER, TypeDescriptor } from '../move/index.js'
|
|
16
|
+
|
|
17
|
+
export type { SuiAddress } from '@mysten/sui.js'
|
|
18
|
+
|
|
19
|
+
export function toNeutralModule(module: SuiMoveNormalizedModule): NeutralMoveModule {
|
|
20
|
+
return {
|
|
21
|
+
address: module.address,
|
|
22
|
+
exposed_functions: Object.entries(module.exposed_functions).map(([n, f]) => toNeutralFunction(n, f)),
|
|
23
|
+
name: module.name,
|
|
24
|
+
structs: Object.entries(module.structs).map(([n, s]) => toNeutralStruct(n, s)),
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function toNeutralFunction(name: string, func: SuiMoveNormalizedFunction): NeutralMoveFunction {
|
|
29
|
+
let visibility
|
|
30
|
+
switch (func.visibility) {
|
|
31
|
+
case 'Private':
|
|
32
|
+
visibility = NeutralMoveFunctionVisibility.PRIVATE
|
|
33
|
+
break
|
|
34
|
+
case 'Public':
|
|
35
|
+
visibility = NeutralMoveFunctionVisibility.PUBLIC
|
|
36
|
+
break
|
|
37
|
+
case 'Friend':
|
|
38
|
+
visibility = NeutralMoveFunctionVisibility.FRIEND
|
|
39
|
+
break
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
generic_type_params: func.type_parameters.map((p) => {
|
|
43
|
+
return { constraints: p.abilities }
|
|
44
|
+
}),
|
|
45
|
+
is_entry: func.is_entry,
|
|
46
|
+
name: name,
|
|
47
|
+
params: func.parameters.map(convertToTypeDescriptor),
|
|
48
|
+
return: func.return_.map(convertToTypeDescriptor),
|
|
49
|
+
visibility: visibility,
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function toNeutralStruct(name: string, struct: SuiMoveNormalizedStruct): NeutralMoveStruct {
|
|
54
|
+
return {
|
|
55
|
+
abilities: struct.abilities.abilities,
|
|
56
|
+
fields: struct.fields.map(toNeutralField),
|
|
57
|
+
generic_type_params: struct.type_parameters.map((p) => {
|
|
58
|
+
return { constraints: p.constraints.abilities }
|
|
59
|
+
}),
|
|
60
|
+
is_native: false,
|
|
61
|
+
name: name,
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function toNeutralField(module: SuiMoveNormalizedField): NeutralMoveStructField {
|
|
66
|
+
return {
|
|
67
|
+
name: module.name,
|
|
68
|
+
type: convertToTypeDescriptor(module.type_),
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function convertToTypeDescriptor(normalizedType: SuiMoveNormalizedType): TypeDescriptor {
|
|
73
|
+
if (typeof normalizedType === 'string') {
|
|
74
|
+
return new TypeDescriptor(normalizedType)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if ('Struct' in normalizedType) {
|
|
78
|
+
// normalizedType.Struct.
|
|
79
|
+
// return normalizedType;
|
|
80
|
+
const qname = [normalizedType.Struct.address, normalizedType.Struct.module, normalizedType.Struct.name].join(
|
|
81
|
+
SPLITTER
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
const args = normalizedType.Struct.type_arguments.map(convertToTypeDescriptor)
|
|
85
|
+
|
|
86
|
+
return new TypeDescriptor(qname, args)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if ('Vector' in normalizedType) {
|
|
90
|
+
return new TypeDescriptor('vector', [convertToTypeDescriptor(normalizedType.Vector)])
|
|
91
|
+
}
|
|
92
|
+
if ('TypeParameter' in normalizedType) {
|
|
93
|
+
return new TypeDescriptor('T' + normalizedType.TypeParameter)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if ('Reference' in normalizedType) {
|
|
97
|
+
const res = convertToTypeDescriptor(normalizedType.Reference)
|
|
98
|
+
res.reference = true
|
|
99
|
+
return res
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if ('MutableReference' in normalizedType) {
|
|
103
|
+
const res = convertToTypeDescriptor(normalizedType.MutableReference)
|
|
104
|
+
res.reference = true
|
|
105
|
+
return res
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
throw new Error('Unexpected sui type')
|
|
109
|
+
}
|
package/src/sui/sui-processor.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { SuiContext } from './context.js'
|
|
|
6
6
|
import { MoveEvent, SuiTransactionResponse, getMoveCallTransaction, MoveCall } from '@mysten/sui.js'
|
|
7
7
|
import { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter } from '../move/index.js'
|
|
8
8
|
import { getMoveCalls } from './utils.js'
|
|
9
|
+
import { defaultMoveCoder } from './move-coder.js'
|
|
9
10
|
|
|
10
11
|
class IndexConfigure {
|
|
11
12
|
address: string
|
|
@@ -82,8 +83,7 @@ export class SuiBaseProcessor {
|
|
|
82
83
|
for (const evt of events) {
|
|
83
84
|
if ('moveEvent' in evt) {
|
|
84
85
|
const eventInstance = evt.moveEvent as MoveEvent
|
|
85
|
-
const decoded = eventInstance
|
|
86
|
-
// const decoded = MOVE_CODER.decodeEvent<any>(eventInstance)
|
|
86
|
+
const decoded = defaultMoveCoder().decodeEvent<any>(eventInstance)
|
|
87
87
|
await handler(decoded || eventInstance, ctx)
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -135,7 +135,7 @@ export class SuiBaseProcessor {
|
|
|
135
135
|
throw new ServerError(Status.INVALID_ARGUMENT, 'Unexpected number of call transactions ' + calls.length)
|
|
136
136
|
}
|
|
137
137
|
const payload = calls[0]
|
|
138
|
-
const decoded =
|
|
138
|
+
const decoded = defaultMoveCoder().decodeFunctionPayload(payload)
|
|
139
139
|
await handler(decoded, ctx)
|
|
140
140
|
}
|
|
141
141
|
return ctx.getProcessResult()
|