@sentio/sdk 2.0.0-rc.14 → 2.0.0-rc.15
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/api.d.ts +5 -0
- package/lib/aptos/api.js +21 -0
- package/lib/aptos/api.js.map +1 -0
- package/lib/aptos/aptos-plugin.d.ts +14 -0
- package/lib/aptos/aptos-plugin.js +146 -0
- package/lib/aptos/aptos-plugin.js.map +1 -0
- package/lib/aptos/aptos-processor.d.ts +72 -0
- package/lib/aptos/aptos-processor.js +201 -0
- package/lib/aptos/aptos-processor.js.map +1 -0
- package/lib/aptos/builtin/0x1.d.ts +2140 -0
- package/lib/aptos/builtin/0x1.js +2727 -0
- package/lib/aptos/builtin/0x1.js.map +1 -0
- package/lib/aptos/builtin/0x3.d.ts +573 -0
- package/lib/aptos/builtin/0x3.js +496 -0
- package/lib/aptos/builtin/0x3.js.map +1 -0
- package/lib/aptos/builtin/index.d.ts +2 -0
- package/lib/aptos/builtin/index.js +6 -0
- package/lib/aptos/builtin/index.js.map +1 -0
- package/lib/aptos/codegen/codegen.d.ts +23 -0
- package/lib/aptos/codegen/codegen.js +388 -0
- package/lib/aptos/codegen/codegen.js.map +1 -0
- package/lib/aptos/codegen/index.d.ts +1 -0
- package/lib/aptos/codegen/index.js +2 -0
- package/lib/aptos/codegen/index.js.map +1 -0
- package/lib/aptos/codegen/typegen.d.ts +18 -0
- package/lib/aptos/codegen/typegen.js +145 -0
- package/lib/aptos/codegen/typegen.js.map +1 -0
- package/lib/aptos/codegen/typegen.test.d.ts +1 -0
- package/lib/aptos/codegen/typegen.test.js.map +1 -0
- package/lib/aptos/context.d.ts +21 -0
- package/lib/aptos/context.js +59 -0
- package/lib/aptos/context.js.map +1 -0
- package/lib/aptos/index.d.ts +9 -0
- package/lib/aptos/index.js +8 -0
- package/lib/aptos/index.js.map +1 -0
- package/lib/aptos/models.d.ts +37 -0
- package/lib/aptos/models.js +2 -0
- package/lib/aptos/models.js.map +1 -0
- package/lib/aptos/move-coder.d.ts +22 -0
- package/lib/aptos/move-coder.js +164 -0
- package/lib/aptos/move-coder.js.map +1 -0
- package/lib/aptos/move-types.d.ts +10 -0
- package/lib/aptos/move-types.js +2 -0
- package/lib/aptos/move-types.js.map +1 -0
- package/lib/aptos/network.d.ts +11 -0
- package/lib/aptos/network.js +27 -0
- package/lib/aptos/network.js.map +1 -0
- package/lib/aptos/run-codegen.d.ts +1 -0
- package/lib/aptos/run-codegen.js +12 -0
- package/lib/aptos/run-codegen.js.map +1 -0
- package/lib/aptos/tests/aptos.test.d.ts +1 -0
- package/lib/aptos/tests/aptos.test.js.map +1 -0
- package/lib/aptos/tests/souffl3.d.ts +1 -0
- package/lib/aptos/tests/souffl3.js +44 -0
- package/lib/aptos/tests/souffl3.js.map +1 -0
- package/lib/aptos/tests/types/index.d.ts +3 -0
- package/lib/aptos/tests/types/index.js +7 -0
- package/lib/aptos/tests/types/index.js.map +1 -0
- package/lib/aptos/tests/types/reserved.d.ts +445 -0
- package/lib/aptos/tests/types/reserved.js +301 -0
- package/lib/aptos/tests/types/reserved.js.map +1 -0
- package/lib/aptos/tests/types/soffl3.d.ts +1065 -0
- package/lib/aptos/tests/types/soffl3.js +548 -0
- package/lib/aptos/tests/types/soffl3.js.map +1 -0
- package/lib/aptos/tests/types/souffle.d.ts +440 -0
- package/lib/aptos/tests/types/souffle.js +295 -0
- package/lib/aptos/tests/types/souffle.js.map +1 -0
- package/lib/aptos/types.d.ts +9 -0
- package/lib/aptos/types.js +130 -0
- package/lib/aptos/types.js.map +1 -0
- package/lib/aptos/types.test.d.ts +1 -0
- package/lib/aptos/types.test.js.map +1 -0
- package/lib/aptos/utils.d.ts +7 -0
- package/lib/aptos/utils.js +20 -0
- package/lib/aptos/utils.js.map +1 -0
- package/lib/{utils/chain.d.ts → chain.d.ts} +0 -0
- package/lib/{utils/chain.js → chain.js} +0 -0
- package/lib/chain.js.map +1 -0
- package/lib/core/context.js +1 -1
- package/lib/core/context.js.map +1 -1
- package/lib/core/sui-plugin.js +1 -1
- package/lib/core/sui-plugin.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/solana/builtin/index.d.ts +1 -0
- package/lib/solana/builtin/index.js +2 -0
- package/lib/solana/builtin/index.js.map +1 -0
- package/lib/solana/builtin/spl-token-processor.d.ts +39 -0
- package/lib/solana/builtin/spl-token-processor.js +254 -0
- package/lib/solana/builtin/spl-token-processor.js.map +1 -0
- package/lib/solana/builtin/types.d.ts +427 -0
- package/lib/solana/builtin/types.js +200 -0
- package/lib/solana/builtin/types.js.map +1 -0
- package/lib/solana/codegen/codegen.d.ts +1 -0
- package/lib/solana/codegen/codegen.js +122 -0
- package/lib/solana/codegen/codegen.js.map +1 -0
- package/lib/solana/codegen/index.d.ts +1 -0
- package/lib/solana/codegen/index.js +2 -0
- package/lib/solana/codegen/index.js.map +1 -0
- package/lib/solana/index.d.ts +4 -0
- package/lib/solana/index.js +5 -0
- package/lib/solana/index.js.map +1 -0
- package/lib/solana/run-codegen.d.ts +2 -0
- package/lib/solana/run-codegen.js +12 -0
- package/lib/solana/run-codegen.js.map +1 -0
- package/lib/solana/solana-context.d.ts +9 -0
- package/lib/solana/solana-context.js +28 -0
- package/lib/solana/solana-context.js.map +1 -0
- package/lib/solana/solana-options.d.ts +10 -0
- package/lib/solana/solana-options.js +10 -0
- package/lib/solana/solana-options.js.map +1 -0
- package/lib/solana/solana-plugin.d.ts +9 -0
- package/lib/solana/solana-plugin.js +87 -0
- package/lib/solana/solana-plugin.js.map +1 -0
- package/lib/solana/solana-processor.d.ts +43 -0
- package/lib/solana/solana-processor.js +72 -0
- package/lib/solana/solana-processor.js.map +1 -0
- package/lib/solana/tests/solana.test.d.ts +1 -0
- package/lib/solana/tests/solana.test.js.map +1 -0
- package/lib/solana/tests/types/basic_1.d.ts +26 -0
- package/lib/solana/tests/types/basic_1.js +63 -0
- package/lib/solana/tests/types/basic_1.js.map +1 -0
- package/lib/solana/tests/types/basic_1_processor.d.ts +21 -0
- package/lib/solana/tests/types/basic_1_processor.js +35 -0
- package/lib/solana/tests/types/basic_1_processor.js.map +1 -0
- package/lib/solana/tests/types/token_bridge.d.ts +29 -0
- package/lib/solana/tests/types/token_bridge.js +938 -0
- package/lib/solana/tests/types/token_bridge.js.map +1 -0
- package/lib/solana/tests/types/token_bridge_processor.d.ts +212 -0
- package/lib/solana/tests/types/token_bridge_processor.js +134 -0
- package/lib/solana/tests/types/token_bridge_processor.js.map +1 -0
- package/lib/solana/tests/wormhole-token-bridge.d.ts +15 -0
- package/lib/solana/tests/wormhole-token-bridge.js +79 -0
- package/lib/solana/tests/wormhole-token-bridge.js.map +1 -0
- package/lib/testing/test-processor-server.js +1 -1
- package/lib/testing/test-processor-server.js.map +1 -1
- package/lib/testing/test-provider.js +1 -1
- package/lib/testing/test-provider.js.map +1 -1
- package/lib/utils/index.d.ts +0 -1
- package/lib/utils/index.js +0 -1
- package/lib/utils/index.js.map +1 -1
- package/package.json +33 -11
- package/src/aptos/abis/0x1.json +9205 -0
- package/src/aptos/abis/0x3.json +1515 -0
- package/src/aptos/api.ts +23 -0
- package/src/aptos/aptos-plugin.ts +183 -0
- package/src/aptos/aptos-processor.ts +331 -0
- package/src/aptos/builtin/0x1.ts +4911 -0
- package/src/aptos/builtin/0x3.ts +1092 -0
- package/src/aptos/builtin/index.ts +5 -0
- package/src/aptos/codegen/codegen.ts +470 -0
- package/src/aptos/codegen/index.ts +1 -0
- package/src/aptos/codegen/tsconfig.json +8 -0
- package/src/aptos/codegen/typegen.ts +165 -0
- package/src/aptos/context.ts +72 -0
- package/src/aptos/index.ts +10 -0
- package/src/aptos/models.ts +47 -0
- package/src/aptos/move-coder.ts +201 -0
- package/src/aptos/move-types.ts +11 -0
- package/src/aptos/network.ts +29 -0
- package/src/aptos/run-codegen.ts +13 -0
- package/src/aptos/tests/abis/reserved.json +402 -0
- package/src/aptos/tests/abis/soffl3.json +1411 -0
- package/src/aptos/tests/abis/souffle.json +389 -0
- package/src/aptos/tests/souffl3.ts +57 -0
- package/src/aptos/tests/types/index.ts +6 -0
- package/src/aptos/tests/types/reserved.ts +881 -0
- package/src/aptos/tests/types/soffl3.ts +1820 -0
- package/src/aptos/tests/types/souffle.ts +880 -0
- package/src/aptos/types.ts +149 -0
- package/src/aptos/utils.ts +26 -0
- package/src/{utils/chain.ts → chain.ts} +0 -0
- package/src/core/context.ts +1 -1
- package/src/core/sui-plugin.ts +1 -1
- package/src/index.ts +1 -1
- package/src/solana/builtin/index.ts +1 -0
- package/src/solana/builtin/spl-token-processor.ts +298 -0
- package/src/solana/builtin/types.ts +279 -0
- package/src/solana/codegen/codegen.ts +140 -0
- package/src/solana/codegen/index.ts +1 -0
- package/src/solana/codegen/tsconfig.json +8 -0
- package/src/solana/index.ts +4 -0
- package/src/solana/run-codegen.ts +13 -0
- package/src/solana/solana-context.ts +30 -0
- package/src/solana/solana-options.ts +11 -0
- package/src/solana/solana-plugin.ts +103 -0
- package/src/solana/solana-processor.ts +102 -0
- package/src/solana/tests/abis/basic_1.json +62 -0
- package/src/solana/tests/abis/token_bridge.json +937 -0
- package/src/solana/tests/types/basic_1.ts +62 -0
- package/src/solana/tests/types/basic_1_processor.ts +42 -0
- package/src/solana/tests/types/token_bridge.ts +937 -0
- package/src/solana/tests/types/token_bridge_processor.ts +150 -0
- package/src/solana/tests/wormhole-token-bridge.ts +96 -0
- package/src/testing/test-processor-server.ts +1 -1
- package/src/testing/test-provider.ts +1 -1
- package/src/utils/index.ts +0 -1
- package/lib/utils/chain.js.map +0 -1
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { RecordMetaData } from '@sentio/protos'
|
|
2
|
+
import { type Labels, BaseContext, normalizeLabels } from '@sentio/sdk'
|
|
3
|
+
import { Transaction_UserTransaction } from './move-types.js'
|
|
4
|
+
import { AptosNetwork, getChainId } from './network.js'
|
|
5
|
+
|
|
6
|
+
export class AptosContext extends BaseContext {
|
|
7
|
+
address: string
|
|
8
|
+
network: AptosNetwork
|
|
9
|
+
moduleName: string
|
|
10
|
+
version: bigint
|
|
11
|
+
transaction: Transaction_UserTransaction
|
|
12
|
+
|
|
13
|
+
constructor(
|
|
14
|
+
moduleName: string,
|
|
15
|
+
network: AptosNetwork,
|
|
16
|
+
address: string,
|
|
17
|
+
version: bigint,
|
|
18
|
+
transaction?: Transaction_UserTransaction
|
|
19
|
+
) {
|
|
20
|
+
super()
|
|
21
|
+
this.address = address
|
|
22
|
+
this.network = network
|
|
23
|
+
this.moduleName = moduleName
|
|
24
|
+
this.version = version
|
|
25
|
+
if (transaction) {
|
|
26
|
+
this.transaction = transaction
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getMetaData(name: string, labels: Labels): RecordMetaData {
|
|
31
|
+
return {
|
|
32
|
+
address: this.address,
|
|
33
|
+
contractName: this.moduleName,
|
|
34
|
+
blockNumber: this.version,
|
|
35
|
+
transactionIndex: 0,
|
|
36
|
+
transactionHash: this.transaction?.hash || '', // TODO
|
|
37
|
+
logIndex: 0,
|
|
38
|
+
chainId: getChainId(this.network),
|
|
39
|
+
name: name,
|
|
40
|
+
labels: normalizeLabels(labels),
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export class AptosResourceContext extends BaseContext {
|
|
46
|
+
address: string
|
|
47
|
+
network: AptosNetwork
|
|
48
|
+
version: bigint
|
|
49
|
+
timestampInMicros: number
|
|
50
|
+
|
|
51
|
+
constructor(network: AptosNetwork, address: string, version: bigint, timestampInMicros: number) {
|
|
52
|
+
super()
|
|
53
|
+
this.address = address
|
|
54
|
+
this.network = network
|
|
55
|
+
this.version = version
|
|
56
|
+
this.timestampInMicros = timestampInMicros
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
getMetaData(name: string, labels: Labels): RecordMetaData {
|
|
60
|
+
return {
|
|
61
|
+
address: this.address,
|
|
62
|
+
contractName: 'resources',
|
|
63
|
+
blockNumber: this.version,
|
|
64
|
+
transactionIndex: 0,
|
|
65
|
+
transactionHash: '',
|
|
66
|
+
logIndex: 0,
|
|
67
|
+
chainId: getChainId(this.network),
|
|
68
|
+
name: name,
|
|
69
|
+
labels: normalizeLabels(labels),
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './move-types.js'
|
|
2
|
+
export type { EventInstance, TypedEventInstance, TypedEntryFunctionPayload, TypedMoveResource } from './models.js'
|
|
3
|
+
export { defaultMoveCoder, MoveCoder } from './move-coder.js'
|
|
4
|
+
export type { FunctionNameAndCallFilter, EventFilter, CallFilter, ArgumentsFilter } from './aptos-processor.js'
|
|
5
|
+
export { AptosBaseProcessor, AptosAccountProcessor } from './aptos-processor.js'
|
|
6
|
+
export { AptosContext, AptosResourceContext } from './context.js'
|
|
7
|
+
export { AptosBindOptions, AptosNetwork } from './network.js'
|
|
8
|
+
export * from './api.js'
|
|
9
|
+
|
|
10
|
+
export { AptosPlugin } from './aptos-plugin.js'
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Event, MoveResource, TransactionPayload_EntryFunctionPayload } from './move-types.js'
|
|
2
|
+
|
|
3
|
+
export type EventInstance = Event & {
|
|
4
|
+
version: string
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export type TypedEventInstance<T> = EventInstance & {
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated use {@link data_decoded} instead
|
|
10
|
+
*/
|
|
11
|
+
data_typed: T
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* decoded data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch
|
|
15
|
+
*/
|
|
16
|
+
data_decoded: T
|
|
17
|
+
|
|
18
|
+
type_arguments: string[]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Don't use intermediate type to make IDE happier
|
|
22
|
+
export type TypedEntryFunctionPayload<T extends Array<any>> = TransactionPayload_EntryFunctionPayload & {
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated use {@link arguments_decoded} instead
|
|
25
|
+
*/
|
|
26
|
+
arguments_typed: T
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* decoded argument data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch
|
|
30
|
+
*/
|
|
31
|
+
arguments_decoded: T
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type TypedMoveResource<T> = MoveResource & {
|
|
35
|
+
data_typed: T
|
|
36
|
+
type_arguments: string[]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface StructWithTag {
|
|
40
|
+
type: string
|
|
41
|
+
data: any
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface StructWithType<T> extends StructWithTag {
|
|
45
|
+
data_typed: T
|
|
46
|
+
type_arguments: string[]
|
|
47
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Event,
|
|
3
|
+
MoveFunction,
|
|
4
|
+
MoveModule,
|
|
5
|
+
MoveResource,
|
|
6
|
+
MoveStruct,
|
|
7
|
+
TransactionPayload_EntryFunctionPayload,
|
|
8
|
+
} from './move-types.js'
|
|
9
|
+
|
|
10
|
+
import { getMeaningfulFunctionParams, moduleQname, SPLITTER, VECTOR_STR } from './utils.js'
|
|
11
|
+
import { parseMoveType, TypeDescriptor } from './types.js'
|
|
12
|
+
import {
|
|
13
|
+
TypedEventInstance,
|
|
14
|
+
TypedMoveResource,
|
|
15
|
+
StructWithTag,
|
|
16
|
+
StructWithType,
|
|
17
|
+
TypedEntryFunctionPayload,
|
|
18
|
+
} from './models.js'
|
|
19
|
+
|
|
20
|
+
export class MoveCoder {
|
|
21
|
+
private moduleMapping = new Map<string, MoveModule>()
|
|
22
|
+
private typeMapping = new Map<string, MoveStruct>()
|
|
23
|
+
private funcMapping = new Map<string, MoveFunction>()
|
|
24
|
+
|
|
25
|
+
contains(account: string, name: string) {
|
|
26
|
+
return this.moduleMapping.has(account + '::' + name)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
load(module: MoveModule) {
|
|
30
|
+
if (this.contains(module.address, module.name)) {
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
this.moduleMapping.set(moduleQname(module), module)
|
|
34
|
+
|
|
35
|
+
for (const struct of module.structs) {
|
|
36
|
+
// TODO move to util
|
|
37
|
+
const key = [module.address, module.name, struct.name].join(SPLITTER)
|
|
38
|
+
this.typeMapping.set(key, struct)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
for (const func of module.exposed_functions) {
|
|
42
|
+
if (!func.is_entry) {
|
|
43
|
+
continue
|
|
44
|
+
}
|
|
45
|
+
const key = [module.address, module.name, func.name].join(SPLITTER)
|
|
46
|
+
this.funcMapping.set(key, func)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
getMoveStruct(type: string): MoveStruct {
|
|
51
|
+
const struct = this.typeMapping.get(type)
|
|
52
|
+
if (!struct) {
|
|
53
|
+
throw new Error('Failed to load type' + type)
|
|
54
|
+
}
|
|
55
|
+
return struct
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
getMoveFunction(type: string): MoveFunction {
|
|
59
|
+
const func = this.funcMapping.get(type)
|
|
60
|
+
if (!func) {
|
|
61
|
+
throw new Error('Failed to load function' + type)
|
|
62
|
+
}
|
|
63
|
+
return func
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
decode(data: any, type: TypeDescriptor): any {
|
|
67
|
+
// process simple type
|
|
68
|
+
if (type.qname.startsWith('&')) {
|
|
69
|
+
return data
|
|
70
|
+
}
|
|
71
|
+
switch (type.qname) {
|
|
72
|
+
case 'signer': // TODO check this
|
|
73
|
+
case 'address':
|
|
74
|
+
case '0x1::string::String':
|
|
75
|
+
case 'bool':
|
|
76
|
+
case 'u8':
|
|
77
|
+
case 'u16':
|
|
78
|
+
case 'u32':
|
|
79
|
+
return data
|
|
80
|
+
case 'u64':
|
|
81
|
+
case 'u128':
|
|
82
|
+
return BigInt(data)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// process vector
|
|
86
|
+
if (type.qname === VECTOR_STR) {
|
|
87
|
+
// vector<u8> as hex string
|
|
88
|
+
if (type.typeArgs[0].qname === 'u8') {
|
|
89
|
+
return data
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const res = []
|
|
93
|
+
for (const entry of data) {
|
|
94
|
+
res.push(this.decode(entry, type.typeArgs[0]))
|
|
95
|
+
}
|
|
96
|
+
return res
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Process complex type
|
|
100
|
+
const struct = this.getMoveStruct(type.qname)
|
|
101
|
+
|
|
102
|
+
const typeCtx = new Map<string, TypeDescriptor>()
|
|
103
|
+
for (const [idx, typeArg] of type.typeArgs.entries()) {
|
|
104
|
+
typeCtx.set('T' + idx, typeArg)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const typedData: any = {}
|
|
108
|
+
|
|
109
|
+
for (const field of struct.fields) {
|
|
110
|
+
let filedType = parseMoveType(field.type)
|
|
111
|
+
filedType = filedType.applyTypeArgs(typeCtx)
|
|
112
|
+
const value = this.decode(data[field.name], filedType)
|
|
113
|
+
typedData[field.name] = value
|
|
114
|
+
}
|
|
115
|
+
return typedData
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
decodeEvent<T>(event: Event): TypedEventInstance<T> | undefined {
|
|
119
|
+
return this.decodedInternal<T>(event) as TypedEventInstance<T>
|
|
120
|
+
}
|
|
121
|
+
filterAndDecodeEvents<T>(typeQname: string, resources: Event[]): TypedEventInstance<T>[] {
|
|
122
|
+
return this.filterAndDecodeInternal(typeQname, resources) as TypedEventInstance<T>[]
|
|
123
|
+
}
|
|
124
|
+
decodeResource<T>(res: MoveResource): TypedMoveResource<T> | undefined {
|
|
125
|
+
return this.decodedInternal<T>(res)
|
|
126
|
+
}
|
|
127
|
+
filterAndDecodeResources<T>(typeQname: string, resources: MoveResource[]): TypedMoveResource<T>[] {
|
|
128
|
+
return this.filterAndDecodeInternal(typeQname, resources)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private filterAndDecodeInternal<T>(typeQname: string, structs: StructWithTag[]): StructWithType<T>[] {
|
|
132
|
+
if (!structs) {
|
|
133
|
+
return []
|
|
134
|
+
}
|
|
135
|
+
const results: StructWithType<T>[] = []
|
|
136
|
+
for (const resource of structs) {
|
|
137
|
+
if (resource.type.split('<')[0] !== typeQname) {
|
|
138
|
+
continue
|
|
139
|
+
}
|
|
140
|
+
const result = this.decodedInternal(resource)
|
|
141
|
+
if (result) {
|
|
142
|
+
results.push(result as StructWithType<T>)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return results
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private decodedInternal<T>(typeStruct: StructWithTag): StructWithType<T> | undefined {
|
|
149
|
+
const registry = MOVE_CODER
|
|
150
|
+
// this.loadTypes(registry)
|
|
151
|
+
// TODO check if module is not loaded
|
|
152
|
+
|
|
153
|
+
const typeDescriptor = parseMoveType(typeStruct.type)
|
|
154
|
+
const typeArguments = typeDescriptor.typeArgs.map((t) => t.getSignature())
|
|
155
|
+
|
|
156
|
+
let dataTyped = undefined
|
|
157
|
+
try {
|
|
158
|
+
dataTyped = registry.decode(typeStruct.data, typeDescriptor)
|
|
159
|
+
} catch (e) {
|
|
160
|
+
console.error('Decoding error for ', JSON.stringify(typeStruct), e)
|
|
161
|
+
return undefined
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
...typeStruct,
|
|
165
|
+
data_typed: dataTyped,
|
|
166
|
+
data_decoded: dataTyped,
|
|
167
|
+
type_arguments: typeArguments,
|
|
168
|
+
} as StructWithType<T>
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
decodeFunctionPayload(payload: TransactionPayload_EntryFunctionPayload): TransactionPayload_EntryFunctionPayload {
|
|
172
|
+
const registry = MOVE_CODER
|
|
173
|
+
// this.loadTypes(registry)
|
|
174
|
+
const argumentsTyped: any[] = []
|
|
175
|
+
|
|
176
|
+
try {
|
|
177
|
+
const func = registry.getMoveFunction(payload.function)
|
|
178
|
+
const params = getMeaningfulFunctionParams(func)
|
|
179
|
+
for (const [idx, arg] of payload.arguments.entries()) {
|
|
180
|
+
// TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them
|
|
181
|
+
const argType = parseMoveType(params[idx])
|
|
182
|
+
argumentsTyped.push(registry.decode(arg, argType))
|
|
183
|
+
}
|
|
184
|
+
} catch (e) {
|
|
185
|
+
console.error('Decoding error for ', JSON.stringify(payload), e)
|
|
186
|
+
return payload
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
...payload,
|
|
191
|
+
arguments_typed: argumentsTyped,
|
|
192
|
+
arguments_decoded: argumentsTyped,
|
|
193
|
+
} as TypedEntryFunctionPayload<any>
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export const MOVE_CODER = new MoveCoder()
|
|
198
|
+
|
|
199
|
+
export function defaultMoveCoder(): MoveCoder {
|
|
200
|
+
return MOVE_CODER
|
|
201
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Types } from 'aptos-sdk'
|
|
2
|
+
|
|
3
|
+
export type Address = Types.Address
|
|
4
|
+
export type Event = Types.Event
|
|
5
|
+
export type MoveFunction = Types.MoveFunction
|
|
6
|
+
export type MoveModule = Types.MoveModule
|
|
7
|
+
export type MoveResource = Types.MoveResource
|
|
8
|
+
export type MoveStruct = Types.MoveStruct
|
|
9
|
+
export type MoveModuleBytecode = Types.MoveModuleBytecode
|
|
10
|
+
export type TransactionPayload_EntryFunctionPayload = Types.TransactionPayload_EntryFunctionPayload
|
|
11
|
+
export type Transaction_UserTransaction = Types.Transaction_UserTransaction
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { CHAIN_IDS, getChainName } from '../chain.js'
|
|
2
|
+
|
|
3
|
+
export enum AptosNetwork {
|
|
4
|
+
MAIN_NET = 1,
|
|
5
|
+
TEST_NET = 2,
|
|
6
|
+
// DEV_NET,
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function getChainId(network: AptosNetwork): string {
|
|
10
|
+
switch (network) {
|
|
11
|
+
case AptosNetwork.TEST_NET:
|
|
12
|
+
return CHAIN_IDS.APTOS_TESTNET
|
|
13
|
+
}
|
|
14
|
+
return CHAIN_IDS.APTOS_MAINNET
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getAptosChainName(network: AptosNetwork): string {
|
|
18
|
+
switch (network) {
|
|
19
|
+
case AptosNetwork.TEST_NET:
|
|
20
|
+
return getChainName(CHAIN_IDS.APTOS_TESTNET)
|
|
21
|
+
}
|
|
22
|
+
return getChainName(CHAIN_IDS.APTOS_MAINNET)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class AptosBindOptions {
|
|
26
|
+
address: string
|
|
27
|
+
network?: AptosNetwork = AptosNetwork.MAIN_NET
|
|
28
|
+
startVersion?: bigint | number
|
|
29
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// #!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { codeGenAptosProcessor } from './codegen/codegen.js'
|
|
4
|
+
|
|
5
|
+
if (process.argv.length > 3) {
|
|
6
|
+
const abisDir = process.argv[2]
|
|
7
|
+
const targetDir = process.argv[3]
|
|
8
|
+
|
|
9
|
+
await codeGenAptosProcessor(abisDir, targetDir)
|
|
10
|
+
} else {
|
|
11
|
+
console.error('Not enough argument')
|
|
12
|
+
process.exit(1)
|
|
13
|
+
}
|