@sentio/sdk 1.28.0 → 1.29.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/aptos/api.d.ts +2 -0
- package/lib/aptos/api.js +14 -0
- package/lib/aptos/api.js.map +1 -0
- package/lib/aptos/aptos-processor.d.ts +5 -4
- package/lib/aptos/aptos-processor.js +8 -9
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/context.d.ts +3 -2
- package/lib/aptos/context.js +3 -3
- package/lib/aptos/context.js.map +1 -1
- package/lib/aptos/index.d.ts +3 -2
- package/lib/aptos/index.js +18 -3
- package/lib/aptos/index.js.map +1 -1
- package/lib/aptos/models.d.ts +23 -0
- package/lib/aptos/models.js +3 -0
- package/lib/aptos/models.js.map +1 -0
- package/lib/aptos/type-registry.d.ts +21 -0
- package/lib/aptos/type-registry.js +156 -0
- package/lib/aptos/type-registry.js.map +1 -0
- package/lib/aptos/types.d.ts +1 -33
- package/lib/aptos/types.js +49 -142
- package/lib/aptos/types.js.map +1 -1
- package/lib/aptos/types.test.js.map +1 -1
- package/lib/aptos/utils.d.ts +0 -2
- package/lib/aptos/utils.js +1 -8
- package/lib/aptos/utils.js.map +1 -1
- package/lib/aptos-codegen/codegen.js +2 -1
- package/lib/aptos-codegen/codegen.js.map +1 -1
- package/lib/aptos-codegen/typegen.d.ts +0 -1
- package/lib/aptos-codegen/typegen.js +3 -61
- package/lib/aptos-codegen/typegen.js.map +1 -1
- package/lib/cli/upload.js +2 -1
- package/lib/cli/upload.js.map +1 -1
- package/lib/core/base-context.d.ts +12 -0
- package/lib/core/base-context.js +25 -0
- package/lib/core/base-context.js.map +1 -0
- package/lib/core/base-processor.d.ts +1 -2
- package/lib/core/base-processor.js.map +1 -1
- package/lib/core/context.d.ts +2 -11
- package/lib/core/context.js +5 -24
- package/lib/core/context.js.map +1 -1
- package/lib/core/event-tracker.d.ts +1 -1
- package/lib/core/event-tracker.js +2 -2
- package/lib/core/event-tracker.js.map +1 -1
- package/lib/core/exporter.d.ts +1 -1
- package/lib/core/exporter.js.map +1 -1
- package/lib/core/generic-processor.test.js.map +1 -1
- package/lib/core/logger.d.ts +1 -1
- package/lib/core/logger.js.map +1 -1
- package/lib/core/meter.d.ts +3 -1
- package/lib/core/meter.js +12 -0
- package/lib/core/meter.js.map +1 -1
- package/lib/endpoints.d.ts +6 -0
- package/lib/endpoints.js +11 -0
- package/lib/endpoints.js.map +1 -0
- package/lib/processor-runner.js +6 -0
- package/lib/processor-runner.js.map +1 -1
- package/lib/processor-state.d.ts +2 -6
- package/lib/processor-state.js +0 -2
- package/lib/processor-state.js.map +1 -1
- package/lib/provider.js +5 -5
- package/lib/provider.js.map +1 -1
- package/lib/testing/test-processor-server.d.ts +4 -1
- package/lib/testing/test-processor-server.js +15 -7
- package/lib/testing/test-processor-server.js.map +1 -1
- package/lib/utils/conversion.d.ts +2 -1
- package/lib/utils/conversion.js +3 -3
- package/lib/utils/conversion.js.map +1 -1
- package/lib/utils/dex-price.test.js.map +1 -1
- package/lib/utils/erc20.test.js.map +1 -1
- package/lib/utils/price.d.ts +9 -1
- package/lib/utils/price.js +49 -1
- package/lib/utils/price.js.map +1 -1
- package/lib/utils/token.d.ts +1 -1
- package/lib/utils/token.js +2 -2
- package/lib/utils/token.js.map +1 -1
- package/package.json +5 -2
- package/src/aptos/api.ts +11 -0
- package/src/aptos/aptos-processor.ts +7 -10
- package/src/aptos/context.ts +3 -3
- package/src/aptos/index.ts +3 -2
- package/src/aptos/models.ts +34 -0
- package/src/aptos/type-registry.ts +187 -0
- package/src/aptos/types.ts +53 -199
- package/src/aptos/utils.ts +0 -9
- package/src/aptos-codegen/codegen.ts +2 -1
- package/src/aptos-codegen/typegen.ts +1 -67
- package/src/cli/upload.ts +2 -1
- package/src/core/base-context.ts +28 -0
- package/src/core/base-processor.ts +1 -2
- package/src/core/context.ts +2 -26
- package/src/core/event-tracker.ts +2 -2
- package/src/core/exporter.ts +1 -1
- package/src/core/logger.ts +1 -1
- package/src/core/meter.ts +15 -1
- package/src/endpoints.ts +9 -0
- package/src/processor-runner.ts +6 -0
- package/src/processor-state.ts +2 -7
- package/src/provider.ts +5 -5
- package/src/testing/test-processor-server.ts +10 -6
- package/src/utils/conversion.ts +2 -1
- package/src/utils/price.ts +51 -1
- package/src/utils/token.ts +1 -1
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Event,
|
|
3
|
+
MoveFunction,
|
|
4
|
+
MoveModule,
|
|
5
|
+
MoveResource,
|
|
6
|
+
MoveStruct,
|
|
7
|
+
TransactionPayload_EntryFunctionPayload,
|
|
8
|
+
} from 'aptos-sdk/src/generated'
|
|
9
|
+
import { getMeaningfulFunctionParams, moduleQname, SPLITTER, VECTOR_STR } from './utils'
|
|
10
|
+
import { parseMoveType, TypeDescriptor } from './types'
|
|
11
|
+
import {
|
|
12
|
+
TypedEventInstance,
|
|
13
|
+
TypedMoveResource,
|
|
14
|
+
StructWithTag,
|
|
15
|
+
StructWithType,
|
|
16
|
+
TypedEntryFunctionPayload,
|
|
17
|
+
} from './models'
|
|
18
|
+
|
|
19
|
+
export class TypeRegistry {
|
|
20
|
+
moduleMapping = new Map<string, MoveModule>()
|
|
21
|
+
typeMapping = new Map<string, MoveStruct>()
|
|
22
|
+
funcMapping = new Map<string, MoveFunction>()
|
|
23
|
+
|
|
24
|
+
contains(account: string, name: string) {
|
|
25
|
+
return this.moduleMapping.has(account + '::' + name)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
load(module: MoveModule) {
|
|
29
|
+
if (this.contains(module.address, module.name)) {
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
this.moduleMapping.set(moduleQname(module), module)
|
|
33
|
+
|
|
34
|
+
for (const struct of module.structs) {
|
|
35
|
+
// TODO move to util
|
|
36
|
+
const key = [module.address, module.name, struct.name].join(SPLITTER)
|
|
37
|
+
this.typeMapping.set(key, struct)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
for (const func of module.exposed_functions) {
|
|
41
|
+
if (!func.is_entry) {
|
|
42
|
+
continue
|
|
43
|
+
}
|
|
44
|
+
const key = [module.address, module.name, func.name].join(SPLITTER)
|
|
45
|
+
this.funcMapping.set(key, func)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
getMoveStruct(type: string): MoveStruct {
|
|
50
|
+
const struct = this.typeMapping.get(type)
|
|
51
|
+
if (!struct) {
|
|
52
|
+
throw new Error('Failed to load type' + type)
|
|
53
|
+
}
|
|
54
|
+
return struct
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
getMoveFunction(type: string): MoveFunction {
|
|
58
|
+
const func = this.funcMapping.get(type)
|
|
59
|
+
if (!func) {
|
|
60
|
+
throw new Error('Failed to load function' + type)
|
|
61
|
+
}
|
|
62
|
+
return func
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
decode(data: any, type: TypeDescriptor): any {
|
|
66
|
+
// process simple type
|
|
67
|
+
if (type.qname.startsWith('&')) {
|
|
68
|
+
return data
|
|
69
|
+
}
|
|
70
|
+
switch (type.qname) {
|
|
71
|
+
case 'signer': // TODO check this
|
|
72
|
+
case 'address':
|
|
73
|
+
case '0x1::string::String':
|
|
74
|
+
case 'bool':
|
|
75
|
+
case 'u8':
|
|
76
|
+
case 'u16':
|
|
77
|
+
case 'u32':
|
|
78
|
+
return data
|
|
79
|
+
case 'u64':
|
|
80
|
+
case 'u128':
|
|
81
|
+
return BigInt(data)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// process vector
|
|
85
|
+
if (type.qname === VECTOR_STR) {
|
|
86
|
+
// vector<u8> as hex string
|
|
87
|
+
if (type.typeArgs[0].qname === 'u8') {
|
|
88
|
+
return data
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const res = []
|
|
92
|
+
for (const entry of data) {
|
|
93
|
+
res.push(this.decode(entry, type.typeArgs[0]))
|
|
94
|
+
}
|
|
95
|
+
return res
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Process complex type
|
|
99
|
+
const struct = this.getMoveStruct(type.qname)
|
|
100
|
+
|
|
101
|
+
const typeCtx = new Map<string, TypeDescriptor>()
|
|
102
|
+
for (const [idx, typeArg] of type.typeArgs.entries()) {
|
|
103
|
+
typeCtx.set('T' + idx, typeArg)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const typedData: any = {}
|
|
107
|
+
|
|
108
|
+
for (const field of struct.fields) {
|
|
109
|
+
let filedType = parseMoveType(field.type)
|
|
110
|
+
filedType = filedType.applyTypeArgs(typeCtx)
|
|
111
|
+
const value = this.decode(data[field.name], filedType)
|
|
112
|
+
typedData[field.name] = value
|
|
113
|
+
}
|
|
114
|
+
return typedData
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
decodeEvent<T>(event: Event): TypedEventInstance<T> | undefined {
|
|
118
|
+
return this.decodedInternal<T>(event) as TypedEventInstance<T>
|
|
119
|
+
}
|
|
120
|
+
filterAndDecodeEvents<T>(typeQname: string, resources: Event[]): TypedEventInstance<T>[] {
|
|
121
|
+
return this.filterAndDecodeInternal(typeQname, resources) as TypedEventInstance<T>[]
|
|
122
|
+
}
|
|
123
|
+
decodeResource<T>(res: MoveResource): TypedMoveResource<T> | undefined {
|
|
124
|
+
return this.decodedInternal<T>(res)
|
|
125
|
+
}
|
|
126
|
+
filterAndDecodeResources<T>(typeQname: string, resources: MoveResource[]): TypedMoveResource<T>[] {
|
|
127
|
+
return this.filterAndDecodeInternal(typeQname, resources)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private filterAndDecodeInternal<T>(typeQname: string, structs: StructWithTag[]): StructWithType<T>[] {
|
|
131
|
+
if (!structs) {
|
|
132
|
+
return []
|
|
133
|
+
}
|
|
134
|
+
const results: StructWithType<T>[] = []
|
|
135
|
+
for (const resource of structs) {
|
|
136
|
+
if (resource.type.split('<')[0] !== typeQname) {
|
|
137
|
+
continue
|
|
138
|
+
}
|
|
139
|
+
const result = this.decodedInternal(resource)
|
|
140
|
+
if (result) {
|
|
141
|
+
results.push(result as StructWithType<T>)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return results
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private decodedInternal<T>(typeStruct: StructWithTag): StructWithType<T> | undefined {
|
|
148
|
+
const registry = TYPE_REGISTRY
|
|
149
|
+
// this.loadTypes(registry)
|
|
150
|
+
// TODO check if module is not loaded
|
|
151
|
+
|
|
152
|
+
const typeDescriptor = parseMoveType(typeStruct.type)
|
|
153
|
+
const typeArguments = typeDescriptor.typeArgs.map((t) => t.getSignature())
|
|
154
|
+
|
|
155
|
+
let dataTyped = undefined
|
|
156
|
+
try {
|
|
157
|
+
dataTyped = registry.decode(typeStruct.data, typeDescriptor)
|
|
158
|
+
} catch (e) {
|
|
159
|
+
console.error('Decoding error for ', JSON.stringify(typeStruct), e)
|
|
160
|
+
return undefined
|
|
161
|
+
}
|
|
162
|
+
return { ...typeStruct, data_typed: dataTyped, type_arguments: typeArguments } as StructWithType<T>
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
decodeFunctionPayload(payload: TransactionPayload_EntryFunctionPayload): TransactionPayload_EntryFunctionPayload {
|
|
166
|
+
const registry = TYPE_REGISTRY
|
|
167
|
+
// this.loadTypes(registry)
|
|
168
|
+
const argumentsTyped: any[] = []
|
|
169
|
+
|
|
170
|
+
try {
|
|
171
|
+
const func = registry.getMoveFunction(payload.function)
|
|
172
|
+
const params = getMeaningfulFunctionParams(func)
|
|
173
|
+
for (const [idx, arg] of payload.arguments.entries()) {
|
|
174
|
+
// TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them
|
|
175
|
+
const argType = parseMoveType(params[idx])
|
|
176
|
+
argumentsTyped.push(registry.decode(arg, argType))
|
|
177
|
+
}
|
|
178
|
+
} catch (e) {
|
|
179
|
+
console.error('Decoding error for ', JSON.stringify(payload), e)
|
|
180
|
+
return payload
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return { ...payload, arguments_typed: argumentsTyped } as TypedEntryFunctionPayload<any>
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export const TYPE_REGISTRY = new TypeRegistry()
|
package/src/aptos/types.ts
CHANGED
|
@@ -1,46 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Event,
|
|
3
|
-
MoveFunction,
|
|
4
|
-
MoveModule,
|
|
5
|
-
MoveStruct,
|
|
6
|
-
TransactionPayload_EntryFunctionPayload,
|
|
7
|
-
MoveResource,
|
|
8
|
-
} from 'aptos-sdk/src/generated'
|
|
9
|
-
import { getMeaningfulFunctionParams, moduleQname, SPLITTER, VECTOR_STR } from './utils'
|
|
10
|
-
import { parseMoveType } from '../aptos-codegen/typegen'
|
|
11
|
-
|
|
12
|
-
export type EventInstance = Event & {
|
|
13
|
-
version: string
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type TypedEventInstance<T> = EventInstance & {
|
|
17
|
-
// Typed data converted from ABI
|
|
18
|
-
// undefined if there is converting error, usually because the ABI/data
|
|
19
|
-
// mismatch
|
|
20
|
-
data_typed: T
|
|
21
|
-
|
|
22
|
-
type_arguments: string[]
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Don't use intermedidate type to make IDE happier
|
|
26
|
-
export type TypedEntryFunctionPayload<T extends Array<any>> = TransactionPayload_EntryFunctionPayload & {
|
|
27
|
-
arguments_typed: T
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export type TypedMoveResource<T> = MoveResource & {
|
|
31
|
-
data_typed: T
|
|
32
|
-
type_arguments: string[]
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
interface StructWithTag {
|
|
36
|
-
type: string
|
|
37
|
-
data: any
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
interface StructWithType<T> extends StructWithTag {
|
|
41
|
-
data_typed: T
|
|
42
|
-
type_arguments: string[]
|
|
43
|
-
}
|
|
1
|
+
import { SPLITTER, VECTOR_STR } from './utils'
|
|
44
2
|
|
|
45
3
|
export class TypeDescriptor {
|
|
46
4
|
// type: string
|
|
@@ -124,172 +82,68 @@ export class TypeDescriptor {
|
|
|
124
82
|
}
|
|
125
83
|
}
|
|
126
84
|
|
|
127
|
-
export
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
85
|
+
export function parseMoveType(type: string): TypeDescriptor {
|
|
86
|
+
// type = type.replace('&', '')
|
|
87
|
+
|
|
88
|
+
type = type.replaceAll('&mut ', '&')
|
|
89
|
+
type = type.replaceAll('mut ', '')
|
|
90
|
+
|
|
91
|
+
// TODO replace ' ' is not exactly safe, need to double check this
|
|
92
|
+
type = type.replaceAll(' ', '')
|
|
93
|
+
|
|
94
|
+
const stack: TypeDescriptor[] = [new TypeDescriptor('')]
|
|
95
|
+
let buffer = []
|
|
96
|
+
|
|
97
|
+
// xxx:asdf<g1<a,<c,d>>, b, g2<a,b>, e>
|
|
98
|
+
for (let i = 0; i < type.length; i++) {
|
|
99
|
+
const ch = type[i]
|
|
100
|
+
if (ch === '<') {
|
|
101
|
+
// const symbol = type.slice(symbolStart, i)
|
|
102
|
+
// symbolStart =
|
|
103
|
+
const symbol = buffer.join('')
|
|
104
|
+
buffer = []
|
|
105
|
+
stack[stack.length - 1].qname = symbol
|
|
106
|
+
stack.push(new TypeDescriptor(''))
|
|
107
|
+
continue
|
|
108
|
+
}
|
|
109
|
+
if (ch === '>') {
|
|
110
|
+
const typeParam = stack.pop()
|
|
111
|
+
if (!typeParam) {
|
|
112
|
+
throw Error('Uxpectecd stack size')
|
|
151
113
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const struct = this.typeMapping.get(type)
|
|
159
|
-
if (!struct) {
|
|
160
|
-
throw new Error('Failed to load type' + type)
|
|
161
|
-
}
|
|
162
|
-
return struct
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
getMoveFunction(type: string): MoveFunction {
|
|
166
|
-
const func = this.funcMapping.get(type)
|
|
167
|
-
if (!func) {
|
|
168
|
-
throw new Error('Failed to load function' + type)
|
|
169
|
-
}
|
|
170
|
-
return func
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
decode(data: any, type: TypeDescriptor): any {
|
|
174
|
-
// process simple type
|
|
175
|
-
if (type.qname.startsWith('&')) {
|
|
176
|
-
return data
|
|
177
|
-
}
|
|
178
|
-
switch (type.qname) {
|
|
179
|
-
case 'signer': // TODO check this
|
|
180
|
-
case 'address':
|
|
181
|
-
case '0x1::string::String':
|
|
182
|
-
case 'bool':
|
|
183
|
-
case 'u8':
|
|
184
|
-
case 'u16':
|
|
185
|
-
case 'u32':
|
|
186
|
-
return data
|
|
187
|
-
case 'u64':
|
|
188
|
-
case 'u128':
|
|
189
|
-
return BigInt(data)
|
|
114
|
+
if (buffer.length > 0) {
|
|
115
|
+
typeParam.qname = buffer.join('')
|
|
116
|
+
buffer = []
|
|
117
|
+
}
|
|
118
|
+
stack[stack.length - 1].typeArgs.push(typeParam)
|
|
119
|
+
continue
|
|
190
120
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
if (type.typeArgs[0].qname === 'u8') {
|
|
196
|
-
return data
|
|
121
|
+
if (ch === ',') {
|
|
122
|
+
const typeParam = stack.pop()
|
|
123
|
+
if (!typeParam) {
|
|
124
|
+
throw Error('Uxpectecd stack size')
|
|
197
125
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
res.push(this.decode(entry, type.typeArgs[0]))
|
|
126
|
+
if (buffer.length > 0) {
|
|
127
|
+
typeParam.qname = buffer.join('')
|
|
128
|
+
buffer = []
|
|
202
129
|
}
|
|
203
|
-
return res
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// Process complex type
|
|
207
|
-
const struct = this.getMoveStruct(type.qname)
|
|
208
|
-
|
|
209
|
-
const typeCtx = new Map<string, TypeDescriptor>()
|
|
210
|
-
for (const [idx, typeArg] of type.typeArgs.entries()) {
|
|
211
|
-
typeCtx.set('T' + idx, typeArg)
|
|
212
|
-
}
|
|
213
130
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
filedType = filedType.applyTypeArgs(typeCtx)
|
|
219
|
-
const value = this.decode(data[field.name], filedType)
|
|
220
|
-
typedData[field.name] = value
|
|
131
|
+
stack[stack.length - 1].typeArgs.push(typeParam)
|
|
132
|
+
// continue parse next param
|
|
133
|
+
stack.push(new TypeDescriptor(''))
|
|
134
|
+
continue
|
|
221
135
|
}
|
|
222
|
-
return typedData
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
decodeEvent<T>(event: Event): TypedEventInstance<T> | undefined {
|
|
226
|
-
return this.decodedInternal<T>(event) as TypedEventInstance<T>
|
|
227
|
-
}
|
|
228
|
-
filterAndDecodeEvents<T>(typeQname: string, resources: Event[]): TypedEventInstance<T>[] {
|
|
229
|
-
return this.filterAndDecodeInternal(typeQname, resources) as TypedEventInstance<T>[]
|
|
230
|
-
}
|
|
231
|
-
decodeResource<T>(res: MoveResource): TypedMoveResource<T> | undefined {
|
|
232
|
-
return this.decodedInternal<T>(res)
|
|
233
|
-
}
|
|
234
|
-
filterAndDecodeResources<T>(typeQname: string, resources: MoveResource[]): TypedMoveResource<T>[] {
|
|
235
|
-
return this.filterAndDecodeInternal(typeQname, resources)
|
|
236
|
-
}
|
|
237
136
|
|
|
238
|
-
|
|
239
|
-
if (!structs) {
|
|
240
|
-
return []
|
|
241
|
-
}
|
|
242
|
-
const results: StructWithType<T>[] = []
|
|
243
|
-
for (const resource of structs) {
|
|
244
|
-
if (resource.type.split('<')[0] !== typeQname) {
|
|
245
|
-
continue
|
|
246
|
-
}
|
|
247
|
-
const result = this.decodedInternal(resource)
|
|
248
|
-
if (result) {
|
|
249
|
-
results.push(result as StructWithType<T>)
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
return results
|
|
137
|
+
buffer.push(ch)
|
|
253
138
|
}
|
|
254
139
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
// this.loadTypes(registry)
|
|
258
|
-
// TODO check if module is not loaded
|
|
259
|
-
|
|
260
|
-
const typeDescriptor = parseMoveType(typeStruct.type)
|
|
261
|
-
const typeArguments = typeDescriptor.typeArgs.map((t) => t.getSignature())
|
|
262
|
-
|
|
263
|
-
let dataTyped = undefined
|
|
264
|
-
try {
|
|
265
|
-
dataTyped = registry.decode(typeStruct.data, typeDescriptor)
|
|
266
|
-
} catch (e) {
|
|
267
|
-
console.error('Decoding error for ', JSON.stringify(typeStruct), e)
|
|
268
|
-
return undefined
|
|
269
|
-
}
|
|
270
|
-
return { ...typeStruct, data_typed: dataTyped, type_arguments: typeArguments } as StructWithType<T>
|
|
140
|
+
if (buffer.length > 0) {
|
|
141
|
+
stack[stack.length - 1].qname = buffer.join('')
|
|
271
142
|
}
|
|
272
143
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const argumentsTyped: any[] = []
|
|
277
|
-
|
|
278
|
-
try {
|
|
279
|
-
const func = registry.getMoveFunction(payload.function)
|
|
280
|
-
const params = getMeaningfulFunctionParams(func)
|
|
281
|
-
for (const [idx, arg] of payload.arguments.entries()) {
|
|
282
|
-
// TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them
|
|
283
|
-
const argType = parseMoveType(params[idx])
|
|
284
|
-
argumentsTyped.push(registry.decode(arg, argType))
|
|
285
|
-
}
|
|
286
|
-
} catch (e) {
|
|
287
|
-
console.error('Decoding error for ', JSON.stringify(payload), e)
|
|
288
|
-
return payload
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
return { ...payload, arguments_typed: argumentsTyped } as TypedEntryFunctionPayload<any>
|
|
144
|
+
const res = stack.pop()
|
|
145
|
+
if (!res || stack.length > 0) {
|
|
146
|
+
throw Error('Uxpectecd stack size')
|
|
292
147
|
}
|
|
148
|
+
return res
|
|
293
149
|
}
|
|
294
|
-
|
|
295
|
-
export const TYPE_REGISTRY = new TypeRegistry()
|
package/src/aptos/utils.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { MoveFunction, MoveModule } from 'aptos-sdk/src/generated'
|
|
2
2
|
|
|
3
|
-
import { createChannel, createClient } from 'nice-grpc'
|
|
4
|
-
import { AptosQueryClient, AptosQueryDefinition } from '../gen/chainquery/protos/chainquery'
|
|
5
|
-
|
|
6
3
|
export const SPLITTER = '::'
|
|
7
4
|
|
|
8
5
|
export const VECTOR_STR = 'vector'
|
|
@@ -20,12 +17,6 @@ export function moduleQnameForType(type: string): [string, string] {
|
|
|
20
17
|
return [parts[0], parts[1]]
|
|
21
18
|
}
|
|
22
19
|
|
|
23
|
-
export function getChainQueryClient(address = 'chainquery-server.chain-sync:6809'): AptosQueryClient {
|
|
24
|
-
const channel = createChannel(address)
|
|
25
|
-
|
|
26
|
-
return createClient(AptosQueryDefinition, channel)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
20
|
export function getMeaningfulFunctionParams(func: MoveFunction): string[] {
|
|
30
21
|
let params = func.params
|
|
31
22
|
if (func.params[0] === '&signer') {
|
|
@@ -2,10 +2,11 @@ import fs from 'fs'
|
|
|
2
2
|
import path from 'path'
|
|
3
3
|
import prettier from 'prettier'
|
|
4
4
|
import { MoveFunction, MoveModule, MoveModuleBytecode, MoveStruct } from 'aptos-sdk/src/generated'
|
|
5
|
-
import { AccountModulesImportInfo, AccountRegister, generateType
|
|
5
|
+
import { AccountModulesImportInfo, AccountRegister, generateType } from './typegen'
|
|
6
6
|
import { getMeaningfulFunctionParams, isFrameworkAccount, moduleQname, SPLITTER } from '../aptos/utils'
|
|
7
7
|
import chalk from 'chalk'
|
|
8
8
|
import { AptosNetwork, getChainName, getRpcClient } from '../aptos/network'
|
|
9
|
+
import { parseMoveType } from '../aptos/types'
|
|
9
10
|
|
|
10
11
|
export async function generate(srcDir: string, outputDir: string) {
|
|
11
12
|
await generateForNetwork(srcDir, outputDir, AptosNetwork.MAIN_NET)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MoveModule } from 'aptos-sdk/src/generated'
|
|
2
|
-
import { TypeDescriptor } from '../aptos/types'
|
|
2
|
+
import { parseMoveType, TypeDescriptor } from '../aptos/types'
|
|
3
3
|
import { moduleQname, moduleQnameForType, SPLITTER, VECTOR_STR } from '../aptos/utils'
|
|
4
4
|
|
|
5
5
|
function generateTypeForDescriptor(type: TypeDescriptor, currentAddress: string): string {
|
|
@@ -62,72 +62,6 @@ function generateSimpleType(type: string, currentAddress: string): string {
|
|
|
62
62
|
return '_' + parts.join('.')
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
export function parseMoveType(type: string): TypeDescriptor {
|
|
66
|
-
// type = type.replace('&', '')
|
|
67
|
-
|
|
68
|
-
type = type.replaceAll('&mut ', '&')
|
|
69
|
-
type = type.replaceAll('mut ', '')
|
|
70
|
-
|
|
71
|
-
// TODO replace ' ' is not exactly safe, need to double check this
|
|
72
|
-
type = type.replaceAll(' ', '')
|
|
73
|
-
|
|
74
|
-
const stack: TypeDescriptor[] = [new TypeDescriptor('')]
|
|
75
|
-
let buffer = []
|
|
76
|
-
|
|
77
|
-
// xxx:asdf<g1<a,<c,d>>, b, g2<a,b>, e>
|
|
78
|
-
for (let i = 0; i < type.length; i++) {
|
|
79
|
-
const ch = type[i]
|
|
80
|
-
if (ch === '<') {
|
|
81
|
-
// const symbol = type.slice(symbolStart, i)
|
|
82
|
-
// symbolStart =
|
|
83
|
-
const symbol = buffer.join('')
|
|
84
|
-
buffer = []
|
|
85
|
-
stack[stack.length - 1].qname = symbol
|
|
86
|
-
stack.push(new TypeDescriptor(''))
|
|
87
|
-
continue
|
|
88
|
-
}
|
|
89
|
-
if (ch === '>') {
|
|
90
|
-
const typeParam = stack.pop()
|
|
91
|
-
if (!typeParam) {
|
|
92
|
-
throw Error('Uxpectecd stack size')
|
|
93
|
-
}
|
|
94
|
-
if (buffer.length > 0) {
|
|
95
|
-
typeParam.qname = buffer.join('')
|
|
96
|
-
buffer = []
|
|
97
|
-
}
|
|
98
|
-
stack[stack.length - 1].typeArgs.push(typeParam)
|
|
99
|
-
continue
|
|
100
|
-
}
|
|
101
|
-
if (ch === ',') {
|
|
102
|
-
const typeParam = stack.pop()
|
|
103
|
-
if (!typeParam) {
|
|
104
|
-
throw Error('Uxpectecd stack size')
|
|
105
|
-
}
|
|
106
|
-
if (buffer.length > 0) {
|
|
107
|
-
typeParam.qname = buffer.join('')
|
|
108
|
-
buffer = []
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
stack[stack.length - 1].typeArgs.push(typeParam)
|
|
112
|
-
// continue parse next param
|
|
113
|
-
stack.push(new TypeDescriptor(''))
|
|
114
|
-
continue
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
buffer.push(ch)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (buffer.length > 0) {
|
|
121
|
-
stack[stack.length - 1].qname = buffer.join('')
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const res = stack.pop()
|
|
125
|
-
if (!res || stack.length > 0) {
|
|
126
|
-
throw Error('Uxpectecd stack size')
|
|
127
|
-
}
|
|
128
|
-
return res
|
|
129
|
-
}
|
|
130
|
-
|
|
131
65
|
// TODO ctx need to have type parameters
|
|
132
66
|
export function generateType(type: string, currentAddress: string): string {
|
|
133
67
|
return generateTypeForDescriptor(parseMoveType(type), currentAddress)
|
package/src/cli/upload.ts
CHANGED
|
@@ -13,12 +13,13 @@ import { getCliVersion } from './utils'
|
|
|
13
13
|
|
|
14
14
|
async function createProject(options: SentioProjectConfig, apiKey: string) {
|
|
15
15
|
const url = new URL('/api/v1/projects', options.host)
|
|
16
|
+
const [ownerName, slug] = options.project.includes('/') ? options.project.split('/') : [undefined, options.project]
|
|
16
17
|
return fetch(url, {
|
|
17
18
|
method: 'POST',
|
|
18
19
|
headers: {
|
|
19
20
|
'api-key': apiKey,
|
|
20
21
|
},
|
|
21
|
-
body: JSON.stringify({ slug
|
|
22
|
+
body: JSON.stringify({ slug, ownerName, visibility: 'PRIVATE' }),
|
|
22
23
|
})
|
|
23
24
|
}
|
|
24
25
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DataDescriptor, ProcessResult, RecordMetaData } from '../gen'
|
|
2
|
+
import { Logger } from './logger'
|
|
3
|
+
import { Labels } from './metadata'
|
|
4
|
+
import { Meter } from './meter'
|
|
5
|
+
|
|
6
|
+
export abstract class BaseContext {
|
|
7
|
+
meter: Meter
|
|
8
|
+
logger: Logger
|
|
9
|
+
|
|
10
|
+
res: ProcessResult = {
|
|
11
|
+
counters: [],
|
|
12
|
+
events: [],
|
|
13
|
+
exports: [],
|
|
14
|
+
gauges: [],
|
|
15
|
+
logs: [],
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
protected constructor() {
|
|
19
|
+
this.meter = new Meter(this)
|
|
20
|
+
this.logger = new Logger(this)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
getProcessResult(): ProcessResult {
|
|
24
|
+
return this.res
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
abstract getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData
|
|
28
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Event } from '@ethersproject/contracts'
|
|
2
1
|
import { BytesLike } from '@ethersproject/bytes'
|
|
3
2
|
import { Block, Log, getNetwork } from '@ethersproject/providers'
|
|
4
|
-
import { BaseContract, EventFilter } from '@ethersproject/contracts'
|
|
3
|
+
import { BaseContract, Event, EventFilter } from '@ethersproject/contracts'
|
|
5
4
|
import Long from 'long'
|
|
6
5
|
|
|
7
6
|
import { BoundContractView, ContractContext, ContractView } from './context'
|
package/src/core/context.ts
CHANGED
|
@@ -1,36 +1,12 @@
|
|
|
1
1
|
import { DataDescriptor, RecordMetaData, ProcessResult } from '../gen'
|
|
2
2
|
import { BaseContract, EventFilter } from 'ethers'
|
|
3
3
|
import { Block, Log } from '@ethersproject/abstract-provider'
|
|
4
|
-
import {
|
|
4
|
+
import { normalizeLabels } from './meter'
|
|
5
5
|
import Long from 'long'
|
|
6
6
|
import { Trace } from './trace'
|
|
7
|
-
import { Logger } from './logger'
|
|
8
7
|
import { Labels } from './metadata'
|
|
9
8
|
import { SOL_MAINMET_ID, SUI_DEVNET_ID } from '../utils/chain'
|
|
10
|
-
|
|
11
|
-
export abstract class BaseContext {
|
|
12
|
-
meter: Meter
|
|
13
|
-
logger: Logger
|
|
14
|
-
|
|
15
|
-
res: ProcessResult = {
|
|
16
|
-
counters: [],
|
|
17
|
-
events: [],
|
|
18
|
-
exports: [],
|
|
19
|
-
gauges: [],
|
|
20
|
-
logs: [],
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
protected constructor() {
|
|
24
|
-
this.meter = new Meter(this)
|
|
25
|
-
this.logger = new Logger(this)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
getProcessResult(): ProcessResult {
|
|
29
|
-
return this.res
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
abstract getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData
|
|
33
|
-
}
|
|
9
|
+
import { BaseContext } from './base-context'
|
|
34
10
|
|
|
35
11
|
export abstract class EthContext extends BaseContext {
|
|
36
12
|
chainId: number
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BaseContext } from './context'
|
|
2
|
-
import { DataDescriptor, EventTrackingResult } from '
|
|
1
|
+
import { BaseContext } from './base-context'
|
|
2
|
+
import { DataDescriptor, EventTrackingResult } from '../gen'
|
|
3
3
|
|
|
4
4
|
export interface Event {
|
|
5
5
|
// The unique identifier of main identity associate with an event
|
package/src/core/exporter.ts
CHANGED