@sentio/runtime 4.0.0-rc.1 → 4.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/chunk-OLNJTVP4.js +15167 -0
- package/lib/chunk-OLNJTVP4.js.map +1 -0
- package/lib/chunk-VVWSRCNO.js +4988 -0
- package/lib/chunk-VVWSRCNO.js.map +1 -0
- package/lib/index.d.ts +1407 -566
- package/lib/index.js +21290 -40
- package/lib/index.js.map +1 -1
- package/lib/plugin-D-rx1WCp.d.ts +108 -0
- package/lib/processor-runner.js +25516 -525
- package/lib/processor-runner.js.map +1 -1
- package/package.json +1 -1
- package/src/action-server.ts +3 -2
- package/src/db-context.ts +58 -45
- package/src/full-service.ts +18 -400
- package/src/gen/google/type/money_pb.ts +41 -0
- package/src/gen/processor/protos/processor_pb.ts +3855 -0
- package/src/gen/service/common/protos/common_pb.ts +4456 -0
- package/src/global-config.ts +3 -2
- package/src/index.ts +1 -1
- package/src/plugin.ts +26 -16
- package/src/processor-runner.ts +25 -35
- package/src/service-v3.ts +57 -59
- package/src/utils.ts +29 -12
- package/lib/chunk-GUQLAUIA.js +0 -67172
- package/lib/chunk-GUQLAUIA.js.map +0 -1
- package/lib/chunk-KOMGWSWU.js +0 -25311
- package/lib/chunk-KOMGWSWU.js.map +0 -1
- package/lib/processor-StqZovMW.d.ts +0 -554
- package/src/gen/google/protobuf/empty.ts +0 -71
- package/src/gen/google/protobuf/struct.ts +0 -561
- package/src/gen/google/protobuf/timestamp.ts +0 -113
- package/src/gen/google/type/money.ts +0 -134
- package/src/gen/processor/protos/processor.ts +0 -15354
- package/src/gen/service/common/protos/common.ts +0 -16525
- package/src/service.ts +0 -549
package/package.json
CHANGED
package/src/action-server.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PluginManager } from './plugin.js'
|
|
2
|
-
import {
|
|
2
|
+
import { ProcessConfigResponseSchema } from '@sentio/protos'
|
|
3
|
+
import { create } from '@bufbuild/protobuf'
|
|
3
4
|
|
|
4
5
|
export class ActionServer {
|
|
5
6
|
constructor(readonly loader: () => Promise<void>) {}
|
|
@@ -7,7 +8,7 @@ export class ActionServer {
|
|
|
7
8
|
async listen(port: number) {
|
|
8
9
|
const pluginManager = PluginManager.INSTANCE
|
|
9
10
|
await this.loader()
|
|
10
|
-
await pluginManager.configure(
|
|
11
|
+
await pluginManager.configure(create(ProcessConfigResponseSchema))
|
|
11
12
|
console.log('Starting Action Server at:', port)
|
|
12
13
|
await pluginManager.startServer(port)
|
|
13
14
|
}
|
package/src/db-context.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { Subject } from 'rxjs'
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
DBRequest_DBUpsert,
|
|
5
|
-
DBResponse,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
TemplateInstance,
|
|
11
|
-
TimeseriesResult
|
|
3
|
+
DBRequestSchema,
|
|
4
|
+
type DBRequest_DBUpsert,
|
|
5
|
+
type DBResponse,
|
|
6
|
+
DBResponseSchema,
|
|
7
|
+
ProcessResultSchema,
|
|
8
|
+
ProcessStreamResponseSchema,
|
|
9
|
+
ProcessStreamResponseV3Schema,
|
|
10
|
+
type TemplateInstance,
|
|
11
|
+
type TimeseriesResult
|
|
12
12
|
} from '@sentio/protos'
|
|
13
|
+
import { create, type MessageInitShape } from '@bufbuild/protobuf'
|
|
13
14
|
import * as process from 'node:process'
|
|
14
15
|
import { dbMetrics } from './metrics.js'
|
|
15
16
|
|
|
@@ -26,13 +27,19 @@ const STORE_BATCH_IDLE = process.env['STORE_BATCH_MAX_IDLE'] ? parseInt(process.
|
|
|
26
27
|
const STORE_BATCH_SIZE = process.env['STORE_BATCH_SIZE'] ? parseInt(process.env['STORE_BATCH_SIZE']) : 10
|
|
27
28
|
const STORE_UPSERT_NO_WAIT = process.env['STORE_UPSERT_NO_WAIT'] === 'true'
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
type
|
|
30
|
+
// Init-shapes carried over the rxjs Subject before being yielded by connect.
|
|
31
|
+
type ProcessStreamResponseInit = MessageInitShape<typeof ProcessStreamResponseSchema>
|
|
32
|
+
type ProcessStreamResponseV3Init = MessageInitShape<typeof ProcessStreamResponseV3Schema>
|
|
33
|
+
|
|
34
|
+
// The DBRequest oneof selection (without the op_id), e.g. { case: 'upsert', value: {...} }.
|
|
35
|
+
// protobuf-es moved the per-op flat fields under the `op` oneof.
|
|
36
|
+
type Request = NonNullable<MessageInitShape<typeof DBRequestSchema>['op']>
|
|
37
|
+
type RequestType = NonNullable<Request['case']>
|
|
31
38
|
|
|
32
39
|
export const timeoutError = new Error('timeout')
|
|
33
40
|
|
|
34
41
|
export interface IStoreContext {
|
|
35
|
-
sendRequest(request:
|
|
42
|
+
sendRequest(request: Request, timeoutSecs?: number): Promise<DBResponse>
|
|
36
43
|
|
|
37
44
|
result(dbResult: DBResponse): void
|
|
38
45
|
|
|
@@ -64,15 +71,15 @@ export abstract class AbstractStoreContext implements IStoreContext {
|
|
|
64
71
|
})
|
|
65
72
|
}
|
|
66
73
|
|
|
67
|
-
abstract doSend(resp:
|
|
74
|
+
abstract doSend(resp: ProcessStreamResponseInit | ProcessStreamResponseV3Init): void
|
|
68
75
|
|
|
69
|
-
sendRequest(request:
|
|
70
|
-
if (STORE_BATCH_IDLE > 0 && STORE_BATCH_SIZE > 1 && request.upsert) {
|
|
76
|
+
sendRequest(request: Request, timeoutSecs?: number): Promise<DBResponse> {
|
|
77
|
+
if (STORE_BATCH_IDLE > 0 && STORE_BATCH_SIZE > 1 && request.case === 'upsert') {
|
|
71
78
|
// batch upsert if possible
|
|
72
|
-
return this.sendUpsertInBatch(request.
|
|
79
|
+
return this.sendUpsertInBatch(request.value as DBRequest_DBUpsert)
|
|
73
80
|
}
|
|
74
81
|
|
|
75
|
-
const requestType =
|
|
82
|
+
const requestType = request.case as RequestType
|
|
76
83
|
const opId = StoreContext.opCounter++
|
|
77
84
|
const promise = this.newPromise<DBResponse>(opId, requestType)
|
|
78
85
|
|
|
@@ -88,9 +95,12 @@ export abstract class AbstractStoreContext implements IStoreContext {
|
|
|
88
95
|
}
|
|
89
96
|
|
|
90
97
|
this.doSend({
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
98
|
+
value: {
|
|
99
|
+
case: 'dbRequest',
|
|
100
|
+
value: {
|
|
101
|
+
op: request,
|
|
102
|
+
opId
|
|
103
|
+
}
|
|
94
104
|
}
|
|
95
105
|
})
|
|
96
106
|
|
|
@@ -98,9 +108,7 @@ export abstract class AbstractStoreContext implements IStoreContext {
|
|
|
98
108
|
|
|
99
109
|
if (requestType === 'upsert' && STORE_UPSERT_NO_WAIT) {
|
|
100
110
|
this.pendings.push(promise)
|
|
101
|
-
return Promise.resolve({
|
|
102
|
-
opId
|
|
103
|
-
} as DBResponse)
|
|
111
|
+
return Promise.resolve(create(DBResponseSchema, { opId }))
|
|
104
112
|
}
|
|
105
113
|
|
|
106
114
|
return Promise.race(promises)
|
|
@@ -130,8 +138,8 @@ export abstract class AbstractStoreContext implements IStoreContext {
|
|
|
130
138
|
if (defer.requestType) {
|
|
131
139
|
recv_counts[defer.requestType]?.add(1)
|
|
132
140
|
}
|
|
133
|
-
if (dbResult.error) {
|
|
134
|
-
defer.reject(new Error(dbResult.
|
|
141
|
+
if (dbResult.value.case === 'error') {
|
|
142
|
+
defer.reject(new Error(dbResult.value.value))
|
|
135
143
|
} else {
|
|
136
144
|
defer.resolve(dbResult)
|
|
137
145
|
}
|
|
@@ -143,12 +151,12 @@ export abstract class AbstractStoreContext implements IStoreContext {
|
|
|
143
151
|
error(processId: number, e: any) {
|
|
144
152
|
const stack = e.stack
|
|
145
153
|
console.error('process error', processId, e, stack)
|
|
146
|
-
const errorResult =
|
|
154
|
+
const errorResult = create(ProcessResultSchema, {
|
|
147
155
|
states: {
|
|
148
156
|
error: e?.toString() + (stack ? `\n${stack}` : '')
|
|
149
157
|
}
|
|
150
158
|
})
|
|
151
|
-
this.doSend({ result: errorResult, processId })
|
|
159
|
+
this.doSend({ value: { case: 'result', value: errorResult }, processId })
|
|
152
160
|
}
|
|
153
161
|
|
|
154
162
|
close() {
|
|
@@ -182,9 +190,7 @@ export abstract class AbstractStoreContext implements IStoreContext {
|
|
|
182
190
|
this.sendBatch()
|
|
183
191
|
}
|
|
184
192
|
if (STORE_UPSERT_NO_WAIT) {
|
|
185
|
-
return {
|
|
186
|
-
opId
|
|
187
|
-
}
|
|
193
|
+
return create(DBResponseSchema, { opId })
|
|
188
194
|
}
|
|
189
195
|
|
|
190
196
|
return promise
|
|
@@ -207,9 +213,7 @@ export abstract class AbstractStoreContext implements IStoreContext {
|
|
|
207
213
|
|
|
208
214
|
if (STORE_UPSERT_NO_WAIT) {
|
|
209
215
|
this.pendings.push(promise)
|
|
210
|
-
return {
|
|
211
|
-
opId: this.upsertBatch.opId
|
|
212
|
-
}
|
|
216
|
+
return create(DBResponseSchema, { opId: this.upsertBatch.opId })
|
|
213
217
|
} else {
|
|
214
218
|
return promise
|
|
215
219
|
}
|
|
@@ -223,9 +227,12 @@ export abstract class AbstractStoreContext implements IStoreContext {
|
|
|
223
227
|
clearTimeout(timer)
|
|
224
228
|
this.upsertBatch = undefined
|
|
225
229
|
this.doSend({
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
230
|
+
value: {
|
|
231
|
+
case: 'dbRequest',
|
|
232
|
+
value: {
|
|
233
|
+
op: { case: 'upsert', value: request },
|
|
234
|
+
opId
|
|
235
|
+
}
|
|
229
236
|
}
|
|
230
237
|
})
|
|
231
238
|
send_counts['upsert']?.add(1)
|
|
@@ -241,13 +248,13 @@ export abstract class AbstractStoreContext implements IStoreContext {
|
|
|
241
248
|
|
|
242
249
|
export class StoreContext extends AbstractStoreContext {
|
|
243
250
|
constructor(
|
|
244
|
-
readonly subject: Subject<
|
|
251
|
+
readonly subject: Subject<ProcessStreamResponseInit>,
|
|
245
252
|
processId: number
|
|
246
253
|
) {
|
|
247
254
|
super(processId)
|
|
248
255
|
}
|
|
249
256
|
|
|
250
|
-
doSend(resp:
|
|
257
|
+
doSend(resp: ProcessStreamResponseInit) {
|
|
251
258
|
this.subject.next({
|
|
252
259
|
...resp,
|
|
253
260
|
processId: this.processId
|
|
@@ -259,7 +266,7 @@ export class StoreContext extends AbstractStoreContext {
|
|
|
259
266
|
export class DataBindingContext extends AbstractStoreContext implements IDataBindingContext {
|
|
260
267
|
constructor(
|
|
261
268
|
readonly processId: number,
|
|
262
|
-
readonly subject: Subject<
|
|
269
|
+
readonly subject: Subject<ProcessStreamResponseV3Init>
|
|
263
270
|
) {
|
|
264
271
|
super(processId)
|
|
265
272
|
}
|
|
@@ -267,22 +274,28 @@ export class DataBindingContext extends AbstractStoreContext implements IDataBin
|
|
|
267
274
|
sendTemplateRequest(templates: Array<TemplateInstance>, unbind: boolean) {
|
|
268
275
|
this.subject.next({
|
|
269
276
|
processId: this.processId,
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
277
|
+
value: {
|
|
278
|
+
case: 'tplRequest',
|
|
279
|
+
value: {
|
|
280
|
+
templates,
|
|
281
|
+
remove: unbind
|
|
282
|
+
}
|
|
273
283
|
}
|
|
274
284
|
})
|
|
275
285
|
}
|
|
276
286
|
sendTimeseriesRequest(timeseries: Array<TimeseriesResult>) {
|
|
277
287
|
this.subject.next({
|
|
278
288
|
processId: this.processId,
|
|
279
|
-
|
|
280
|
-
|
|
289
|
+
value: {
|
|
290
|
+
case: 'tsRequest',
|
|
291
|
+
value: {
|
|
292
|
+
data: timeseries
|
|
293
|
+
}
|
|
281
294
|
}
|
|
282
295
|
})
|
|
283
296
|
}
|
|
284
297
|
|
|
285
|
-
doSend(resp:
|
|
298
|
+
doSend(resp: ProcessStreamResponseV3Init) {
|
|
286
299
|
this.subject.next({
|
|
287
300
|
...resp,
|
|
288
301
|
processId: this.processId
|
package/src/full-service.ts
CHANGED
|
@@ -1,416 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { create } from '@bufbuild/protobuf'
|
|
2
|
+
import { type HandlerContext, type ServiceImpl } from '@connectrpc/connect'
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
ProcessResult,
|
|
13
|
-
ProcessStreamRequest,
|
|
14
|
-
StartRequest
|
|
15
|
-
} from './gen/processor/protos/processor.js'
|
|
16
|
-
|
|
17
|
-
import { DeepPartial, Empty, ProcessorV3ServiceImplementation, UpdateTemplatesRequest } from '@sentio/protos'
|
|
18
|
-
import os from 'os'
|
|
4
|
+
ExecutionConfigSchema,
|
|
5
|
+
type ProcessConfigRequest,
|
|
6
|
+
ProcessorV3,
|
|
7
|
+
type ProcessStreamRequest,
|
|
8
|
+
type StartRequest,
|
|
9
|
+
type UpdateTemplatesRequest
|
|
10
|
+
} from '@sentio/protos'
|
|
11
|
+
import { ProcessorServiceImplV3 } from './service-v3.js'
|
|
19
12
|
import { GLOBAL_CONFIG } from './global-config.js'
|
|
20
|
-
import { compareSemver, locatePackageJson, parseSemver, Semver } from './utils.js'
|
|
21
|
-
import { LRUCache } from 'lru-cache'
|
|
22
|
-
import { createHash } from 'crypto'
|
|
23
|
-
|
|
24
|
-
const FUEL_PROTO_UPDATE_VERSION = parseSemver('2.54.0-rc.7')
|
|
25
|
-
const FUEL_PROTO_NO_FUEL_TRANSACTION_AS_CALL_VERSION = parseSemver('2.55.0-rc.1')
|
|
26
|
-
|
|
27
|
-
const MOVE_USE_RAW_VERSION = parseSemver('2.55.0-rc.1')
|
|
28
|
-
const ETH_USE_RAW_VERSION = parseSemver('2.57.9-rc.12')
|
|
29
|
-
// new driver (after MOVE_USE_RAW_VERSION) will sent the same event multiple times when fetch all true
|
|
30
|
-
// so we need to cache it, key will be tx-handler_id
|
|
31
|
-
const PROCESSED_MOVE_EVENT_TX_HANDLER = new LRUCache<string, boolean>({
|
|
32
|
-
max: 10000
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
const enableTxCache = process.env.ENABLE_PARSE_CACHE === 'true'
|
|
36
|
-
|
|
37
|
-
// Cache for parsed JSON data
|
|
38
|
-
const PARSED_DATA_CACHE = new LRUCache<string, any>({
|
|
39
|
-
max: enableTxCache ? 5000 : 1
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Gets parsed JSON data from a string, using a cache to avoid repeated parsing
|
|
44
|
-
* @param rawData The raw string data to parse
|
|
45
|
-
* @returns The parsed JSON object
|
|
46
|
-
*/
|
|
47
|
-
function getParsedData(rawData: string): any {
|
|
48
|
-
if (!enableTxCache) {
|
|
49
|
-
return JSON.parse(rawData)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Create a digest of the raw data for cache key
|
|
53
|
-
const digest = createHash('md5').update(rawData).digest('hex')
|
|
54
|
-
|
|
55
|
-
// Check if we already have this data parsed
|
|
56
|
-
let parsedData = PARSED_DATA_CACHE.get(digest)
|
|
57
|
-
if (!parsedData) {
|
|
58
|
-
// Parse and cache the data
|
|
59
|
-
parsedData = JSON.parse(rawData)
|
|
60
|
-
PARSED_DATA_CACHE.set(digest, parsedData)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return parsedData
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* The RuntimeServicePatcher class is responsible for providing backward compatibility
|
|
68
|
-
* patches for different SDK versions. It ensures that the runtime can adapt to changes
|
|
69
|
-
* in the SDK by applying necessary adjustments to data bindings and other configurations.
|
|
70
|
-
*/
|
|
71
|
-
export class RuntimeServicePatcher {
|
|
72
|
-
sdkVersion: Semver
|
|
73
|
-
|
|
74
|
-
constructor() {
|
|
75
|
-
const sdkPackageJson = locatePackageJson('@sentio/sdk')
|
|
76
|
-
this.sdkVersion = parseSemver(sdkPackageJson.version)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
adjustDataBinding(dataBinding?: DataBinding): void {
|
|
80
|
-
const isBeforeMoveUseRawVersion = compareSemver(this.sdkVersion, MOVE_USE_RAW_VERSION) < 0
|
|
81
|
-
// const isBeforeEthUseRawVersion = compareSemver(this.sdkVersion,ETH_USE_RAW_VERSION) < 0
|
|
82
|
-
|
|
83
|
-
if (!dataBinding) {
|
|
84
|
-
return
|
|
85
|
-
}
|
|
86
|
-
switch (dataBinding.handlerType) {
|
|
87
|
-
case HandlerType.ETH_LOG:
|
|
88
|
-
const ethLog = dataBinding.data?.ethLog
|
|
89
|
-
if (ethLog?.log == null && ethLog?.rawLog) {
|
|
90
|
-
ethLog.log = JSON.parse(ethLog.rawLog)
|
|
91
|
-
|
|
92
|
-
if (ethLog.rawTransaction) {
|
|
93
|
-
ethLog.transaction = getParsedData(ethLog.rawTransaction)
|
|
94
|
-
}
|
|
95
|
-
if (ethLog.rawBlock) {
|
|
96
|
-
ethLog.block = getParsedData(ethLog.rawBlock)
|
|
97
|
-
}
|
|
98
|
-
if (ethLog.rawTransactionReceipt) {
|
|
99
|
-
ethLog.transactionReceipt = getParsedData(ethLog.rawTransactionReceipt)
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
break
|
|
103
|
-
case HandlerType.ETH_TRANSACTION:
|
|
104
|
-
const ethTx = dataBinding.data?.ethTransaction
|
|
105
|
-
if (ethTx?.transaction == null && ethTx?.rawTransaction) {
|
|
106
|
-
ethTx.transaction = getParsedData(ethTx.rawTransaction)
|
|
107
|
-
if (ethTx.rawBlock) {
|
|
108
|
-
ethTx.block = getParsedData(ethTx.rawBlock)
|
|
109
|
-
} else {
|
|
110
|
-
ethTx.block = undefined
|
|
111
|
-
}
|
|
112
|
-
if (ethTx.rawTransactionReceipt) {
|
|
113
|
-
ethTx.transactionReceipt = getParsedData(ethTx.rawTransactionReceipt)
|
|
114
|
-
} else {
|
|
115
|
-
ethTx.transactionReceipt = undefined
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
break
|
|
119
|
-
case HandlerType.FUEL_TRANSACTION:
|
|
120
|
-
if (compareSemver(this.sdkVersion, FUEL_PROTO_UPDATE_VERSION) < 0) {
|
|
121
|
-
dataBinding.handlerType = HandlerType.FUEL_CALL
|
|
122
|
-
if (dataBinding.data) {
|
|
123
|
-
dataBinding.data.fuelCall = dataBinding.data?.fuelTransaction
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
break
|
|
127
|
-
case HandlerType.FUEL_RECEIPT:
|
|
128
|
-
if (compareSemver(this.sdkVersion, FUEL_PROTO_UPDATE_VERSION) < 0) {
|
|
129
|
-
dataBinding.handlerType = HandlerType.FUEL_CALL
|
|
130
|
-
if (dataBinding.data) {
|
|
131
|
-
dataBinding.data.fuelCall = dataBinding.data?.fuelLog
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
break
|
|
136
|
-
case HandlerType.APT_EVENT:
|
|
137
|
-
const aptEvent = dataBinding.data?.aptEvent
|
|
138
|
-
if (aptEvent) {
|
|
139
|
-
if (isBeforeMoveUseRawVersion && aptEvent.rawTransaction) {
|
|
140
|
-
const transaction = getParsedData(aptEvent.rawTransaction)
|
|
141
|
-
|
|
142
|
-
const key = `${transaction.hash}-${dataBinding.handlerIds[0]}`
|
|
143
|
-
if (PROCESSED_MOVE_EVENT_TX_HANDLER.has(key)) {
|
|
144
|
-
console.debug('skip binding', key)
|
|
145
|
-
dataBinding.handlerType = HandlerType.UNKNOWN
|
|
146
|
-
return
|
|
147
|
-
}
|
|
148
|
-
PROCESSED_MOVE_EVENT_TX_HANDLER.set(key, true)
|
|
149
|
-
|
|
150
|
-
aptEvent.transaction = transaction
|
|
151
|
-
if (!transaction.events?.length) {
|
|
152
|
-
// when fetch all is not true, then events is empty, we need to fill it to old format
|
|
153
|
-
transaction.events = [JSON.parse(aptEvent.rawEvent)]
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
break
|
|
158
|
-
case HandlerType.APT_CALL:
|
|
159
|
-
const aptCall = dataBinding.data?.aptCall
|
|
160
|
-
if (aptCall) {
|
|
161
|
-
if (isBeforeMoveUseRawVersion && aptCall.rawTransaction) {
|
|
162
|
-
aptCall.transaction = getParsedData(aptCall.rawTransaction)
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
break
|
|
166
|
-
case HandlerType.APT_RESOURCE:
|
|
167
|
-
const aptResource = dataBinding.data?.aptResource
|
|
168
|
-
if (aptResource) {
|
|
169
|
-
if (isBeforeMoveUseRawVersion && aptResource.rawResources) {
|
|
170
|
-
aptResource.resources = aptResource.rawResources.map((e) => JSON.parse(e))
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
break
|
|
174
|
-
case HandlerType.SUI_EVENT:
|
|
175
|
-
const suiEvent = dataBinding.data?.suiEvent
|
|
176
|
-
if (suiEvent) {
|
|
177
|
-
if (isBeforeMoveUseRawVersion && suiEvent.rawTransaction) {
|
|
178
|
-
const transaction = getParsedData(suiEvent.rawTransaction)
|
|
179
|
-
|
|
180
|
-
const key = `${transaction.digest}-${dataBinding.handlerIds[0]}`
|
|
181
|
-
if (PROCESSED_MOVE_EVENT_TX_HANDLER.has(key)) {
|
|
182
|
-
console.debug('skip binding', key)
|
|
183
|
-
dataBinding.handlerType = HandlerType.UNKNOWN
|
|
184
|
-
return
|
|
185
|
-
}
|
|
186
|
-
PROCESSED_MOVE_EVENT_TX_HANDLER.set(key, true)
|
|
187
|
-
|
|
188
|
-
suiEvent.transaction = transaction
|
|
189
|
-
if (!transaction.events?.length) {
|
|
190
|
-
// when fetch all is not true, then events is empty, we need to fill it to old format
|
|
191
|
-
transaction.events = [JSON.parse(suiEvent.rawEvent)]
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
break
|
|
196
|
-
case HandlerType.SUI_CALL:
|
|
197
|
-
const suiCall = dataBinding.data?.suiCall
|
|
198
|
-
if (suiCall) {
|
|
199
|
-
if (isBeforeMoveUseRawVersion && suiCall.rawTransaction) {
|
|
200
|
-
suiCall.transaction = getParsedData(suiCall.rawTransaction)
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
break
|
|
204
|
-
case HandlerType.SUI_OBJECT:
|
|
205
|
-
const suiObject = dataBinding.data?.suiObject
|
|
206
|
-
if (suiObject) {
|
|
207
|
-
if (isBeforeMoveUseRawVersion && (suiObject.rawSelf || suiObject.rawObjects)) {
|
|
208
|
-
if (suiObject.rawSelf) {
|
|
209
|
-
suiObject.self = JSON.parse(suiObject.rawSelf)
|
|
210
|
-
}
|
|
211
|
-
suiObject.objects = suiObject.rawObjects.map((e) => JSON.parse(e))
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
break
|
|
215
|
-
case HandlerType.SUI_OBJECT_CHANGE:
|
|
216
|
-
const suiObjectChange = dataBinding.data?.suiObjectChange
|
|
217
|
-
if (suiObjectChange) {
|
|
218
|
-
if (isBeforeMoveUseRawVersion && suiObjectChange.rawChanges) {
|
|
219
|
-
suiObjectChange.changes = suiObjectChange.rawChanges.map((e) => JSON.parse(e))
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
break
|
|
223
|
-
case HandlerType.UNKNOWN:
|
|
224
|
-
// if (dataBinding.data?.ethBlock) {
|
|
225
|
-
// if (dataBinding.data.raw.length === 0) {
|
|
226
|
-
// // This is actually not needed in current system, just as initla test propose, move to test only
|
|
227
|
-
// // when this is stable
|
|
228
|
-
// dataBinding.data.raw = new TextEncoder().encode(JSON.stringify(dataBinding.data.ethBlock.block))
|
|
229
|
-
// }
|
|
230
|
-
// }
|
|
231
|
-
break
|
|
232
|
-
default:
|
|
233
|
-
break
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
patchConfig(config: DeepPartial<ProcessConfigResponse>): void {
|
|
238
|
-
config.executionConfig = ExecutionConfig.fromPartial(GLOBAL_CONFIG.execution)
|
|
239
|
-
|
|
240
|
-
if (config.contractConfigs) {
|
|
241
|
-
for (const contract of config.contractConfigs) {
|
|
242
|
-
// for old fuel processor
|
|
243
|
-
if (
|
|
244
|
-
compareSemver(this.sdkVersion, FUEL_PROTO_NO_FUEL_TRANSACTION_AS_CALL_VERSION) < 0 &&
|
|
245
|
-
contract.fuelCallConfigs
|
|
246
|
-
) {
|
|
247
|
-
contract.fuelTransactionConfigs = contract.fuelCallConfigs
|
|
248
|
-
contract.fuelCallConfigs = undefined
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// @ts-ignore convert old fuelLogConfigs to fuelReceiptConfigs
|
|
252
|
-
if (contract.fuelLogConfigs) {
|
|
253
|
-
contract.fuelReceiptConfigs = contract.fuelLogConfigs.map((e) => ({
|
|
254
|
-
handlerId: e.handlerId,
|
|
255
|
-
handlerName: e.handlerName,
|
|
256
|
-
log: {
|
|
257
|
-
logIds: e.logIds
|
|
258
|
-
}
|
|
259
|
-
}))
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// @ts-ignore old fields
|
|
263
|
-
if (contract.aptosCallConfigs) {
|
|
264
|
-
// @ts-ignore old fields
|
|
265
|
-
contract.moveCallConfigs = contract.aptosCallConfigs
|
|
266
|
-
}
|
|
267
|
-
// @ts-ignore old fields
|
|
268
|
-
if (contract.aptosEventConfigs) {
|
|
269
|
-
// @ts-ignore old fields
|
|
270
|
-
contract.moveEventConfigs = contract.aptosEventConfigs
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
export class FullProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
278
|
-
constructor(instance: ProcessorServiceImplementation) {
|
|
279
|
-
this.instance = instance
|
|
280
|
-
const sdkPackageJson = locatePackageJson('@sentio/sdk')
|
|
281
|
-
this.sdkVersion = parseSemver(sdkPackageJson.version)
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
instance: ProcessorServiceImplementation
|
|
285
|
-
sdkVersion: Semver
|
|
286
|
-
patcher: RuntimeServicePatcher = new RuntimeServicePatcher()
|
|
287
13
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
this.patcher.patchConfig(config)
|
|
291
|
-
|
|
292
|
-
if (compareSemver(this.sdkVersion, MOVE_USE_RAW_VERSION) < 0) {
|
|
293
|
-
PROCESSED_MOVE_EVENT_TX_HANDLER.clear()
|
|
294
|
-
}
|
|
14
|
+
export class FullProcessorServiceV3Impl implements ServiceImpl<typeof ProcessorV3> {
|
|
15
|
+
constructor(readonly instance: ProcessorServiceImplV3) {}
|
|
295
16
|
|
|
296
|
-
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
async start(request: StartRequest, context: CallContext) {
|
|
300
|
-
return await this.instance.start(request, context)
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
async stop(request: Empty, context: CallContext) {
|
|
304
|
-
return await this.instance.stop(request, context)
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
async processBindings(request: ProcessBindingsRequest, options: CallContext) {
|
|
308
|
-
// if (GLOBAL_CONFIG.execution.sequential) {
|
|
309
|
-
// request.bindings = request.bindings.sort(dataCompare)
|
|
310
|
-
// }
|
|
311
|
-
|
|
312
|
-
for (const binding of request.bindings) {
|
|
313
|
-
this.patcher.adjustDataBinding(binding)
|
|
314
|
-
}
|
|
315
|
-
try {
|
|
316
|
-
const result = await this.instance.processBindings(request, options)
|
|
317
|
-
this.adjustResult(result.result as ProcessResult)
|
|
318
|
-
if (!result.configUpdated && result.result?.states?.configUpdated) {
|
|
319
|
-
result.configUpdated = result.result?.states?.configUpdated
|
|
320
|
-
}
|
|
321
|
-
return result
|
|
322
|
-
} catch (e: any) {
|
|
323
|
-
if (this.sdkVersion.minor <= 16) {
|
|
324
|
-
// Old sdk doesn't handle this well
|
|
325
|
-
if (
|
|
326
|
-
e.code === os.constants.errno.ECONNRESET ||
|
|
327
|
-
e.code === os.constants.errno.ECONNREFUSED ||
|
|
328
|
-
e.code === os.constants.errno.ECONNABORTED
|
|
329
|
-
) {
|
|
330
|
-
process.exit(1)
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
throw e
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
async *adjustBindingsStream(requests: AsyncIterable<ProcessStreamRequest>): AsyncIterable<ProcessStreamRequest> {
|
|
338
|
-
for await (const request of requests) {
|
|
339
|
-
this.patcher.adjustDataBinding(request.binding)
|
|
340
|
-
yield request
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
async *processBindingsStream(requests: AsyncIterable<ProcessStreamRequest>, context: CallContext) {
|
|
345
|
-
yield* this.instance.processBindingsStream(this.adjustBindingsStream(requests), context)
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
async *preprocessBindingsStream(requests: AsyncIterable<PreprocessStreamRequest>, context: CallContext) {
|
|
349
|
-
yield* this.instance.preprocessBindingsStream(this.adjustBindingsStream(requests), context)
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
private adjustResult(res: ProcessResult): void {}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
// function dataCompare(a: DataBinding, b: DataBinding): number {
|
|
356
|
-
// const timeA = getTimestamp(a) || new Date(0)
|
|
357
|
-
// const timeB = getTimestamp(b) || new Date(0)
|
|
358
|
-
// const timeCmp = timeA.getTime() - timeB.getTime()
|
|
359
|
-
// if (timeCmp !== 0) {
|
|
360
|
-
// return timeCmp
|
|
361
|
-
// }
|
|
362
|
-
// return getSecondary(a) - getSecondary(b)
|
|
363
|
-
// }
|
|
364
|
-
//
|
|
365
|
-
// function getTimestamp(d: DataBinding): Date | undefined {
|
|
366
|
-
// return (
|
|
367
|
-
// d.data?.ethLog?.timestamp ||
|
|
368
|
-
// d.data?.ethTransaction?.timestamp ||
|
|
369
|
-
// (d.data?.ethBlock?.block?.timestamp ? new Date(Number(d.data.ethBlock.block.timestamp) * 1000) : undefined) ||
|
|
370
|
-
// d.data?.ethTrace?.timestamp ||
|
|
371
|
-
// (d.data?.aptCall?.transaction ? new Date(Number(d.data.aptCall.transaction.timestamp) / 1000) : undefined) ||
|
|
372
|
-
// (d.data?.aptEvent?.transaction ? new Date(Number(d.data.aptEvent.transaction.timestamp) / 1000) : undefined) ||
|
|
373
|
-
// (d.data?.aptResource?.timestampMicros ? new Date(Number(d.data.aptResource.timestampMicros) / 1000) : undefined) ||
|
|
374
|
-
// d.data?.fuelCall?.timestamp
|
|
375
|
-
// )
|
|
376
|
-
// }
|
|
377
|
-
//
|
|
378
|
-
// function getSecondary(d: DataBinding) {
|
|
379
|
-
// return (
|
|
380
|
-
// d.data?.ethLog?.log?.logIndex ||
|
|
381
|
-
// d.data?.ethTransaction?.transaction?.transactionIndex ||
|
|
382
|
-
// d.data?.ethBlock?.block?.number ||
|
|
383
|
-
// d.data?.ethTrace?.trace?.transactionPosition
|
|
384
|
-
// )
|
|
385
|
-
// }
|
|
386
|
-
|
|
387
|
-
export class FullProcessorServiceV3Impl implements ProcessorV3ServiceImplementation {
|
|
388
|
-
patcher: RuntimeServicePatcher = new RuntimeServicePatcher()
|
|
389
|
-
|
|
390
|
-
constructor(readonly instance: ProcessorV3ServiceImplementation) {}
|
|
391
|
-
|
|
392
|
-
async start(request: StartRequest, context: CallContext): Promise<DeepPartial<Empty>> {
|
|
17
|
+
async start(request: StartRequest, context: HandlerContext) {
|
|
393
18
|
return this.instance.start(request, context)
|
|
394
19
|
}
|
|
395
20
|
|
|
396
|
-
async getConfig(request: ProcessConfigRequest, context:
|
|
21
|
+
async getConfig(request: ProcessConfigRequest, context: HandlerContext) {
|
|
397
22
|
const config = await this.instance.getConfig(request, context)
|
|
398
|
-
|
|
23
|
+
config.executionConfig = create(ExecutionConfigSchema, GLOBAL_CONFIG.execution)
|
|
399
24
|
return config
|
|
400
25
|
}
|
|
401
26
|
|
|
402
|
-
async *processBindingsStream(requests: AsyncIterable<ProcessStreamRequest>, context:
|
|
403
|
-
yield* this.instance.processBindingsStream(
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
async *adjustBindingsStream(requests: AsyncIterable<ProcessStreamRequest>): AsyncIterable<ProcessStreamRequest> {
|
|
407
|
-
for await (const request of requests) {
|
|
408
|
-
this.patcher.adjustDataBinding(request.binding)
|
|
409
|
-
yield request
|
|
410
|
-
}
|
|
27
|
+
async *processBindingsStream(requests: AsyncIterable<ProcessStreamRequest>, context: HandlerContext) {
|
|
28
|
+
yield* this.instance.processBindingsStream(requests, context)
|
|
411
29
|
}
|
|
412
30
|
|
|
413
|
-
async updateTemplates(request: UpdateTemplatesRequest, context:
|
|
31
|
+
async updateTemplates(request: UpdateTemplatesRequest, context: HandlerContext) {
|
|
414
32
|
return this.instance.updateTemplates(request, context)
|
|
415
33
|
}
|
|
416
34
|
}
|