@sentio/sdk 1.23.1 → 1.25.0
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 +0 -2
- package/lib/aptos/aptos-processor.js +9 -55
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/context.d.ts +1 -1
- package/lib/aptos/context.js +1 -0
- package/lib/aptos/context.js.map +1 -1
- package/lib/aptos/index.d.ts +3 -2
- package/lib/aptos/index.js +5 -1
- package/lib/aptos/index.js.map +1 -1
- package/lib/aptos/network.d.ts +3 -1
- package/lib/aptos/network.js +8 -3
- package/lib/aptos/network.js.map +1 -1
- package/lib/aptos/types.d.ts +13 -2
- package/lib/aptos/types.js +64 -2
- package/lib/aptos/types.js.map +1 -1
- package/lib/aptos-codegen/codegen.js +1 -2
- package/lib/aptos-codegen/codegen.js.map +1 -1
- package/lib/cli/cli.js +5 -5
- package/lib/cli/cli.js.map +1 -1
- package/lib/cli/commands/run-create.js +31 -11
- package/lib/cli/commands/run-create.js.map +1 -1
- package/lib/cli/commands/run-login.js +1 -1
- package/lib/cli/commands/run-login.js.map +1 -1
- package/lib/cli/config.d.ts +0 -1
- package/lib/cli/config.js.map +1 -1
- package/lib/core/base-processor.js +6 -25
- package/lib/core/base-processor.js.map +1 -1
- package/lib/core/context.d.ts +7 -5
- package/lib/core/context.js +15 -0
- package/lib/core/context.js.map +1 -1
- package/lib/core/event-tracker.d.ts +22 -0
- package/lib/core/event-tracker.js +53 -0
- package/lib/core/event-tracker.js.map +1 -0
- package/lib/core/index.d.ts +1 -0
- package/lib/core/index.js +4 -1
- package/lib/core/index.js.map +1 -1
- package/lib/core/solana-processor.js +1 -5
- package/lib/core/solana-processor.js.map +1 -1
- package/lib/core/sui-processor.js +1 -5
- package/lib/core/sui-processor.js.map +1 -1
- package/lib/gen/processor/protos/processor.d.ts +72 -0
- package/lib/gen/processor/protos/processor.js +481 -2
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/processor-state.d.ts +4 -0
- package/lib/processor-state.js +2 -0
- package/lib/processor-state.js.map +1 -1
- package/lib/service.d.ts +2 -0
- package/lib/service.js +24 -1
- package/lib/service.js.map +1 -1
- package/lib/tests/erc20.js +3 -0
- package/lib/tests/erc20.js.map +1 -1
- package/lib/tests/souffl3.js +5 -7
- package/lib/tests/souffl3.js.map +1 -1
- package/package.json +2 -2
- package/src/aptos/aptos-processor.ts +10 -65
- package/src/aptos/context.ts +2 -1
- package/src/aptos/index.ts +3 -2
- package/src/aptos/network.ts +6 -1
- package/src/aptos/types.ts +84 -2
- package/src/aptos-codegen/codegen.ts +2 -3
- package/src/cli/cli.ts +5 -5
- package/src/cli/commands/run-create.ts +33 -11
- package/src/cli/commands/run-login.ts +1 -1
- package/src/cli/config.ts +1 -1
- package/src/core/base-processor.ts +5 -25
- package/src/core/context.ts +29 -5
- package/src/core/event-tracker.ts +66 -0
- package/src/core/index.ts +1 -0
- package/src/core/solana-processor.ts +1 -5
- package/src/core/sui-processor.ts +1 -5
- package/src/gen/processor/protos/processor.ts +600 -1
- package/src/processor-state.ts +6 -0
- package/src/service.ts +28 -1
- package/src/tests/erc20.ts +4 -0
- package/src/tests/souffl3.ts +5 -7
- package/{template → templates/aptos}/.gitignore +0 -0
- package/templates/aptos/abis/aptos/souffle.json +389 -0
- package/{template → templates/aptos}/jest.config.js +0 -0
- package/templates/aptos/package.json +20 -0
- package/templates/aptos/sentio.yaml +1 -0
- package/templates/aptos/src/processor.test.ts +14 -0
- package/templates/aptos/src/processor.ts +13 -0
- package/{template → templates/aptos}/tsconfig.json +0 -0
- package/templates/evm/.gitignore +107 -0
- package/{template → templates/evm}/abis/evm/x2y2.json +0 -0
- package/templates/evm/jest.config.js +7 -0
- package/{template → templates/evm}/package.json +1 -1
- package/{template → templates/evm}/sentio.yaml +0 -0
- package/{template → templates/evm}/src/processor.test.ts +0 -0
- package/{template → templates/evm}/src/processor.ts +0 -0
- package/templates/evm/tsconfig.json +20 -0
- package/templates/raw/.gitignore +107 -0
- package/templates/raw/jest.config.js +7 -0
- package/templates/raw/package.json +20 -0
- package/templates/raw/sentio.yaml +3 -0
- package/templates/raw/src/processor.test.ts +14 -0
- package/templates/raw/src/processor.ts +0 -0
- package/templates/raw/tsconfig.json +20 -0
- package/templates/raw/yarn.lock +4095 -0
package/src/aptos/types.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
MoveModule,
|
|
5
5
|
MoveStruct,
|
|
6
6
|
TransactionPayload_EntryFunctionPayload,
|
|
7
|
+
MoveResource,
|
|
7
8
|
} from 'aptos-sdk/src/generated'
|
|
8
9
|
import { moduleQname, SPLITTER, VECTOR_STR } from './utils'
|
|
9
10
|
import { parseMoveType } from '../aptos-codegen/typegen'
|
|
@@ -26,6 +27,21 @@ export type TypedEntryFunctionPayload<T extends Array<any>> = TransactionPayload
|
|
|
26
27
|
arguments_typed: T
|
|
27
28
|
}
|
|
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
|
+
}
|
|
44
|
+
|
|
29
45
|
export class TypeDescriptor {
|
|
30
46
|
// type: string
|
|
31
47
|
|
|
@@ -206,7 +222,73 @@ export class TypeRegistry {
|
|
|
206
222
|
return typedData
|
|
207
223
|
}
|
|
208
224
|
|
|
209
|
-
|
|
225
|
+
decodeEvent<T>(event: Event): TypedEventInstance<T> | undefined {
|
|
226
|
+
return this.decodedInternal<T>(event) as TypedEventInstance<T>
|
|
227
|
+
}
|
|
228
|
+
filterAndDecodeEvents<T>(typePrefix: string, resources: Event[]): TypedEventInstance<T>[] {
|
|
229
|
+
return this.filterAndDecodeInternal(typePrefix, resources) as TypedEventInstance<T>[]
|
|
230
|
+
}
|
|
231
|
+
decodeResource<T>(res: MoveResource): TypedMoveResource<T> | undefined {
|
|
232
|
+
return this.decodedInternal<T>(res)
|
|
233
|
+
}
|
|
234
|
+
filterAndDecodeResources<T>(typePrefix: string, resources: MoveResource[]): TypedMoveResource<T>[] {
|
|
235
|
+
return this.filterAndDecodeInternal(typePrefix, resources)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
private filterAndDecodeInternal<T>(typePrefix: string, structs: StructWithTag[]): StructWithType<T>[] {
|
|
239
|
+
if (!structs) {
|
|
240
|
+
return []
|
|
241
|
+
}
|
|
242
|
+
const results: StructWithType<T>[] = []
|
|
243
|
+
for (const resource of structs) {
|
|
244
|
+
if (!resource.type.startsWith(typePrefix)) {
|
|
245
|
+
continue
|
|
246
|
+
}
|
|
247
|
+
const result = this.decodedInternal(resource)
|
|
248
|
+
if (result) {
|
|
249
|
+
results.push(result as StructWithType<T>)
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return results
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
private decodedInternal<T>(typeStruct: StructWithTag): StructWithType<T> | undefined {
|
|
256
|
+
const registry = TYPE_REGISTRY
|
|
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))
|
|
268
|
+
return undefined
|
|
269
|
+
}
|
|
270
|
+
return { ...typeStruct, data_typed: dataTyped, type_arguments: typeArguments } as StructWithType<T>
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
decodeFunctionPayload(payload: TransactionPayload_EntryFunctionPayload): TransactionPayload_EntryFunctionPayload {
|
|
274
|
+
const registry = TYPE_REGISTRY
|
|
275
|
+
// this.loadTypes(registry)
|
|
276
|
+
const argumentsTyped: any[] = []
|
|
277
|
+
|
|
278
|
+
try {
|
|
279
|
+
const func = registry.getMoveFunction(payload.function)
|
|
280
|
+
for (const [idx, arg] of payload.arguments.entries()) {
|
|
281
|
+
// TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them
|
|
282
|
+
const argType = parseMoveType(func.params[idx + 1])
|
|
283
|
+
argumentsTyped.push(registry.decode(arg, argType))
|
|
284
|
+
}
|
|
285
|
+
} catch (e) {
|
|
286
|
+
console.error('Decoding error for ', JSON.stringify(payload))
|
|
287
|
+
return payload
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return { ...payload, arguments_typed: argumentsTyped } as TypedEntryFunctionPayload<any>
|
|
291
|
+
}
|
|
210
292
|
}
|
|
211
293
|
|
|
212
|
-
export const
|
|
294
|
+
export const TYPE_REGISTRY = new TypeRegistry()
|
|
@@ -5,8 +5,7 @@ import { MoveFunction, MoveModule, MoveModuleBytecode, MoveStruct } from 'aptos-
|
|
|
5
5
|
import { AccountModulesImportInfo, AccountRegister, generateType } from './typegen'
|
|
6
6
|
import { isFrameworkAccount } from '../aptos/utils'
|
|
7
7
|
import chalk from 'chalk'
|
|
8
|
-
import { AptosNetwork, getChainName,
|
|
9
|
-
import { AptosClient } from 'aptos-sdk'
|
|
8
|
+
import { AptosNetwork, getChainName, getRpcClient } from '../aptos/network'
|
|
10
9
|
|
|
11
10
|
export async function generate(srcDir: string, outputDir: string) {
|
|
12
11
|
await generateForNetwork(srcDir, outputDir, AptosNetwork.MAIN_NET)
|
|
@@ -32,7 +31,7 @@ export async function generateForNetwork(srcDir: string, outputDir: string, netw
|
|
|
32
31
|
loader.accountImports.set('0x1', new AccountModulesImportInfo('0x1', '0x1'))
|
|
33
32
|
loader.accountImports.set('0x2', new AccountModulesImportInfo('0x2', '0x2'))
|
|
34
33
|
loader.accountImports.set('0x3', new AccountModulesImportInfo('0x3', '0x3'))
|
|
35
|
-
const client =
|
|
34
|
+
const client = getRpcClient(network)
|
|
36
35
|
|
|
37
36
|
for (const file of files) {
|
|
38
37
|
if (!file.endsWith('.json')) {
|
package/src/cli/cli.ts
CHANGED
|
@@ -35,7 +35,7 @@ if (mainOptions.command === 'login') {
|
|
|
35
35
|
// TODO move them to their own modules
|
|
36
36
|
|
|
37
37
|
// Process configs
|
|
38
|
-
let processorConfig: SentioProjectConfig = { host: '', project: '',
|
|
38
|
+
let processorConfig: SentioProjectConfig = { host: '', project: '', build: true }
|
|
39
39
|
// Fist step, read from project yaml file
|
|
40
40
|
try {
|
|
41
41
|
console.log(chalk.blue('Loading Process config'))
|
|
@@ -65,9 +65,9 @@ if (mainOptions.command === 'login') {
|
|
|
65
65
|
processorConfig.host = 'prod'
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
if (!processorConfig.source) {
|
|
69
|
-
|
|
70
|
-
}
|
|
68
|
+
// if (!processorConfig.source) {
|
|
69
|
+
// processorConfig.source = 'src/processor.ts'
|
|
70
|
+
// }
|
|
71
71
|
// if (!processorConfig.targets) {
|
|
72
72
|
// console.warn('targets is not defined, use EVM as the default target')
|
|
73
73
|
// processorConfig.targets = []
|
|
@@ -158,7 +158,7 @@ function usage() {
|
|
|
158
158
|
{
|
|
159
159
|
header: 'Usage',
|
|
160
160
|
content: [
|
|
161
|
-
'sentio
|
|
161
|
+
'sentio <command> --help\t\tshow detail usage of specific command',
|
|
162
162
|
'sentio login --api-key=xx\t\tsave credential to local',
|
|
163
163
|
'sentio create\t\t\t\tcreate a template project',
|
|
164
164
|
'sentio upload\t\t\t\tbuild and upload processor to sentio',
|
|
@@ -26,23 +26,45 @@ export function runCreate(argv: string[]) {
|
|
|
26
26
|
description: '(Optional) The root direct new project will be created, default current working dir',
|
|
27
27
|
type: String,
|
|
28
28
|
},
|
|
29
|
+
{
|
|
30
|
+
name: 'chain-type',
|
|
31
|
+
alias: 'c',
|
|
32
|
+
description:
|
|
33
|
+
'The type of project you want to create, can be evm, aptos, raw (if you want to start from scratch and support multiple types of chains)',
|
|
34
|
+
type: String,
|
|
35
|
+
defaultValue: 'evm',
|
|
36
|
+
},
|
|
29
37
|
]
|
|
30
38
|
|
|
31
39
|
const options = commandLineArgs(optionDefinitions, { argv })
|
|
40
|
+
const usage = commandLineUsage([
|
|
41
|
+
{
|
|
42
|
+
header: 'Create a template project',
|
|
43
|
+
content: 'sentio create <name>',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
header: 'Options',
|
|
47
|
+
optionList: optionDefinitions,
|
|
48
|
+
},
|
|
49
|
+
])
|
|
50
|
+
|
|
32
51
|
if (options.help || !options.name) {
|
|
33
|
-
const usage = commandLineUsage([
|
|
34
|
-
{
|
|
35
|
-
header: 'Create a template project',
|
|
36
|
-
content: 'sentio create $NAME',
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
header: 'Options',
|
|
40
|
-
optionList: optionDefinitions,
|
|
41
|
-
},
|
|
42
|
-
])
|
|
43
52
|
console.log(usage)
|
|
44
53
|
} else {
|
|
45
|
-
const
|
|
54
|
+
const chainType: string = options['chain-type'].toLowerCase()
|
|
55
|
+
switch (chainType) {
|
|
56
|
+
case 'evm':
|
|
57
|
+
break
|
|
58
|
+
case 'aptos':
|
|
59
|
+
break
|
|
60
|
+
case 'raw':
|
|
61
|
+
break
|
|
62
|
+
default:
|
|
63
|
+
console.error(chalk.red('non supported chain-type for template creation, use --help for more information.'))
|
|
64
|
+
console.log(usage)
|
|
65
|
+
process.exit(1)
|
|
66
|
+
}
|
|
67
|
+
const templateFolder = path.resolve(__dirname, '../../../templates', chainType)
|
|
46
68
|
const projectName = options.name || 'default'
|
|
47
69
|
|
|
48
70
|
const rootDir = options.directory || process.cwd()
|
package/src/cli/config.ts
CHANGED
|
@@ -98,17 +98,9 @@ export abstract class BaseProcessor<
|
|
|
98
98
|
|
|
99
99
|
// TODO fix this bug
|
|
100
100
|
await handler(event, ctx)
|
|
101
|
-
return
|
|
102
|
-
gauges: ctx.gauges,
|
|
103
|
-
counters: ctx.counters,
|
|
104
|
-
logs: ctx.logs,
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return {
|
|
108
|
-
gauges: [],
|
|
109
|
-
counters: [],
|
|
110
|
-
logs: [],
|
|
101
|
+
return ctx.getProcessResult()
|
|
111
102
|
}
|
|
103
|
+
return ProcessResult.fromPartial({})
|
|
112
104
|
},
|
|
113
105
|
})
|
|
114
106
|
return this
|
|
@@ -128,11 +120,7 @@ export abstract class BaseProcessor<
|
|
|
128
120
|
undefined
|
|
129
121
|
)
|
|
130
122
|
await handler(block, ctx)
|
|
131
|
-
return
|
|
132
|
-
gauges: ctx.gauges,
|
|
133
|
-
counters: ctx.counters,
|
|
134
|
-
logs: ctx.logs,
|
|
135
|
-
}
|
|
123
|
+
return ctx.getProcessResult()
|
|
136
124
|
})
|
|
137
125
|
return this
|
|
138
126
|
}
|
|
@@ -163,11 +151,7 @@ export abstract class BaseProcessor<
|
|
|
163
151
|
const contractInterface = contractView.rawContract.interface
|
|
164
152
|
const fragment = contractInterface.getFunction(signature)
|
|
165
153
|
if (!trace.action.input) {
|
|
166
|
-
return {
|
|
167
|
-
gauges: [],
|
|
168
|
-
counters: [],
|
|
169
|
-
logs: [],
|
|
170
|
-
}
|
|
154
|
+
return ProcessResult.fromPartial({})
|
|
171
155
|
}
|
|
172
156
|
const traceData = '0x' + trace.action.input.slice(10)
|
|
173
157
|
trace.args = contractInterface._abiCoder.decode(fragment.inputs, traceData)
|
|
@@ -181,11 +165,7 @@ export abstract class BaseProcessor<
|
|
|
181
165
|
trace
|
|
182
166
|
)
|
|
183
167
|
await handler(trace, ctx)
|
|
184
|
-
return
|
|
185
|
-
gauges: ctx.gauges,
|
|
186
|
-
counters: ctx.counters,
|
|
187
|
-
logs: ctx.logs,
|
|
188
|
-
}
|
|
168
|
+
return ctx.getProcessResult()
|
|
189
169
|
},
|
|
190
170
|
})
|
|
191
171
|
return this
|
package/src/core/context.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
CounterResult,
|
|
3
|
+
GaugeResult,
|
|
4
|
+
LogResult,
|
|
5
|
+
DataDescriptor,
|
|
6
|
+
RecordMetaData,
|
|
7
|
+
EventTrackingResult,
|
|
8
|
+
ProcessResult,
|
|
9
|
+
} from '../gen'
|
|
2
10
|
import { BaseContract, EventFilter } from 'ethers'
|
|
3
11
|
import { Block, Log } from '@ethersproject/abstract-provider'
|
|
4
12
|
import { Meter, normalizeLabels } from './meter'
|
|
@@ -12,6 +20,7 @@ export abstract class BaseContext {
|
|
|
12
20
|
gauges: GaugeResult[] = []
|
|
13
21
|
counters: CounterResult[] = []
|
|
14
22
|
logs: LogResult[] = []
|
|
23
|
+
events: EventTrackingResult[] = []
|
|
15
24
|
meter: Meter
|
|
16
25
|
logger: Logger
|
|
17
26
|
|
|
@@ -20,7 +29,17 @@ export abstract class BaseContext {
|
|
|
20
29
|
this.logger = new Logger(this)
|
|
21
30
|
}
|
|
22
31
|
|
|
23
|
-
|
|
32
|
+
getProcessResult(): ProcessResult {
|
|
33
|
+
const res: ProcessResult = {
|
|
34
|
+
gauges: this.gauges,
|
|
35
|
+
counters: this.counters,
|
|
36
|
+
logs: this.logs,
|
|
37
|
+
events: this.events,
|
|
38
|
+
}
|
|
39
|
+
return res
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
abstract getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData
|
|
24
43
|
}
|
|
25
44
|
|
|
26
45
|
export abstract class EthContext extends BaseContext {
|
|
@@ -72,7 +91,7 @@ export class ContractContext<
|
|
|
72
91
|
this.contract = view
|
|
73
92
|
}
|
|
74
93
|
|
|
75
|
-
getMetaData(descriptor: DataDescriptor
|
|
94
|
+
getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData {
|
|
76
95
|
if (this.log) {
|
|
77
96
|
return {
|
|
78
97
|
address: this.contract.rawContract.address,
|
|
@@ -83,6 +102,7 @@ export class ContractContext<
|
|
|
83
102
|
logIndex: this.log.logIndex,
|
|
84
103
|
chainId: this.chainId.toString(),
|
|
85
104
|
dataDescriptor: descriptor,
|
|
105
|
+
name: descriptor.name,
|
|
86
106
|
labels: normalizeLabels(labels),
|
|
87
107
|
}
|
|
88
108
|
}
|
|
@@ -96,6 +116,7 @@ export class ContractContext<
|
|
|
96
116
|
logIndex: -1,
|
|
97
117
|
chainId: this.chainId.toString(),
|
|
98
118
|
dataDescriptor: descriptor,
|
|
119
|
+
name: descriptor.name,
|
|
99
120
|
labels: normalizeLabels(labels),
|
|
100
121
|
}
|
|
101
122
|
}
|
|
@@ -109,6 +130,7 @@ export class ContractContext<
|
|
|
109
130
|
logIndex: -1,
|
|
110
131
|
chainId: this.chainId.toString(),
|
|
111
132
|
dataDescriptor: descriptor,
|
|
133
|
+
name: descriptor.name,
|
|
112
134
|
labels: normalizeLabels(labels),
|
|
113
135
|
}
|
|
114
136
|
}
|
|
@@ -168,7 +190,7 @@ export class SolanaContext extends BaseContext {
|
|
|
168
190
|
this.blockNumber = slot
|
|
169
191
|
}
|
|
170
192
|
|
|
171
|
-
getMetaData(descriptor: DataDescriptor
|
|
193
|
+
getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData {
|
|
172
194
|
return {
|
|
173
195
|
address: this.address,
|
|
174
196
|
contractName: this.programName,
|
|
@@ -178,6 +200,7 @@ export class SolanaContext extends BaseContext {
|
|
|
178
200
|
logIndex: 0,
|
|
179
201
|
chainId: SOL_MAINMET_ID, // TODO set in context
|
|
180
202
|
dataDescriptor: descriptor,
|
|
203
|
+
name: descriptor.name,
|
|
181
204
|
labels: normalizeLabels(labels),
|
|
182
205
|
}
|
|
183
206
|
}
|
|
@@ -194,7 +217,7 @@ export class SuiContext extends BaseContext {
|
|
|
194
217
|
this.blockNumber = slot
|
|
195
218
|
}
|
|
196
219
|
|
|
197
|
-
getMetaData(descriptor: DataDescriptor
|
|
220
|
+
getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData {
|
|
198
221
|
return {
|
|
199
222
|
address: this.address,
|
|
200
223
|
contractName: this.moduleName,
|
|
@@ -204,6 +227,7 @@ export class SuiContext extends BaseContext {
|
|
|
204
227
|
logIndex: 0,
|
|
205
228
|
chainId: SUI_DEVNET_ID, // TODO set in context
|
|
206
229
|
dataDescriptor: descriptor,
|
|
230
|
+
name: descriptor.name,
|
|
207
231
|
labels: normalizeLabels(labels),
|
|
208
232
|
}
|
|
209
233
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { BaseContext } from './context'
|
|
2
|
+
import { DataDescriptor, EventTrackingResult } from '@sentio/sdk'
|
|
3
|
+
|
|
4
|
+
export interface Event {
|
|
5
|
+
// The unique identifier of main identity associate with an event
|
|
6
|
+
// .e.g user id / toekn address / account address / contract address id
|
|
7
|
+
//
|
|
8
|
+
distinctId: string
|
|
9
|
+
payload?: Record<string, string>
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface TrackerOptions {
|
|
13
|
+
totalByDay?: boolean
|
|
14
|
+
unique?: boolean
|
|
15
|
+
distinctByDays?: number[]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Track Event with an identity associate with it
|
|
19
|
+
export class EventTracker {
|
|
20
|
+
static DEFAULT_OPTIONS: TrackerOptions = {
|
|
21
|
+
totalByDay: true,
|
|
22
|
+
unique: true,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static register(eventName: string, options?: TrackerOptions) {
|
|
26
|
+
const tracker = new EventTracker(eventName, { ...EventTracker.DEFAULT_OPTIONS, ...options })
|
|
27
|
+
global.PROCESSOR_STATE.eventTrackers.push(tracker)
|
|
28
|
+
return tracker
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
eventName: string
|
|
32
|
+
options: TrackerOptions
|
|
33
|
+
protected constructor(eventName: string, options: TrackerOptions) {
|
|
34
|
+
this.eventName = eventName
|
|
35
|
+
this.options = options
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
trackEvent(ctx: BaseContext, event: Event) {
|
|
39
|
+
const res: EventTrackingResult = {
|
|
40
|
+
metadata: ctx.getMetaData(DataDescriptor.fromPartial({ name: this.eventName }), {}),
|
|
41
|
+
distinctEntityId: event.distinctId,
|
|
42
|
+
attributes: JSON.stringify({}),
|
|
43
|
+
runtimeInfo: undefined,
|
|
44
|
+
}
|
|
45
|
+
ctx.events.push(res)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export class AccountEventTracker extends EventTracker {
|
|
50
|
+
static DEFAULT_OPTIONS: TrackerOptions = {
|
|
51
|
+
totalByDay: true,
|
|
52
|
+
unique: true,
|
|
53
|
+
distinctByDays: [1, 7, 30],
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static register(eventName?: string, options?: TrackerOptions) {
|
|
57
|
+
if (eventName) {
|
|
58
|
+
;['user', eventName].join('.')
|
|
59
|
+
} else {
|
|
60
|
+
eventName = 'user'
|
|
61
|
+
}
|
|
62
|
+
const tracker = new AccountEventTracker(eventName, { ...AccountEventTracker.DEFAULT_OPTIONS, ...options })
|
|
63
|
+
global.PROCESSOR_STATE.eventTrackers.push(tracker)
|
|
64
|
+
return tracker
|
|
65
|
+
}
|
|
66
|
+
}
|
package/src/core/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { BigDecimal } from './big-decimal'
|
|
2
2
|
export { ContractContext, ContractView, BoundContractView, SolanaContext } from './context'
|
|
3
3
|
export { CounterBinding, Meter, GaugeBinding, Counter, Gauge, MetricDescriptorOptions } from './meter'
|
|
4
|
+
export { EventTracker, AccountEventTracker } from './event-tracker'
|
|
4
5
|
export { type Numberish, toBigInteger, toMetricValue } from './numberish'
|
|
5
6
|
|
|
6
7
|
export { BindOptions, SolanaBindOptions } from './bind-options'
|
|
@@ -80,11 +80,7 @@ export class SolanaBaseProcessor {
|
|
|
80
80
|
): ProcessResult {
|
|
81
81
|
const ctx = new SolanaContext(this.contractName, this.address, slot)
|
|
82
82
|
handler(parsedInstruction, ctx, accounts)
|
|
83
|
-
return
|
|
84
|
-
gauges: ctx.gauges,
|
|
85
|
-
counters: ctx.counters,
|
|
86
|
-
logs: ctx.logs,
|
|
87
|
-
}
|
|
83
|
+
return ctx.getProcessResult()
|
|
88
84
|
}
|
|
89
85
|
|
|
90
86
|
public isBind() {
|
|
@@ -39,11 +39,7 @@ export class SuiBaseProcessor {
|
|
|
39
39
|
if (txn) {
|
|
40
40
|
this.transactionHanlder(txn, ctx)
|
|
41
41
|
}
|
|
42
|
-
return
|
|
43
|
-
gauges: ctx.gauges,
|
|
44
|
-
counters: ctx.counters,
|
|
45
|
-
logs: ctx.logs,
|
|
46
|
-
}
|
|
42
|
+
return ctx.getProcessResult()
|
|
47
43
|
}
|
|
48
44
|
|
|
49
45
|
public startSlot(startSlot: Long | number) {
|