@sentio/sdk 1.19.3 → 1.19.4
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/core/aptos-processor.d.ts +19 -0
- package/lib/core/aptos-processor.js +59 -1
- package/lib/core/aptos-processor.js.map +1 -1
- package/lib/core/generic-processor.test.js +1 -1
- package/lib/core/generic-processor.test.js.map +1 -1
- package/lib/core/logger.d.ts +5 -2
- package/lib/core/logger.js +10 -4
- package/lib/core/logger.js.map +1 -1
- package/lib/gen/processor/protos/processor.d.ts +165 -163
- package/lib/gen/processor/protos/processor.js +455 -482
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/service.d.ts +13 -7
- package/lib/service.js +102 -18
- package/lib/service.js.map +1 -1
- package/lib/testing/test-processor-server.d.ts +15 -15
- package/lib/testing/test-processor-server.js +9 -4
- package/lib/testing/test-processor-server.js.map +1 -1
- package/lib/tests/erc20.test.js +1 -1
- package/lib/tests/erc20.test.js.map +1 -1
- package/lib/tests/logger.test.js +1 -1
- package/lib/tests/logger.test.js.map +1 -1
- package/lib/utils/erc20.test.js +0 -1
- package/lib/utils/erc20.test.js.map +1 -1
- package/package.json +1 -1
- package/src/core/aptos-processor.ts +70 -0
- package/src/core/generic-processor.test.ts +1 -1
- package/src/core/logger.ts +12 -4
- package/src/gen/processor/protos/processor.ts +606 -650
- package/src/service.ts +126 -34
- package/src/testing/test-processor-server.ts +27 -32
- package/src/tests/erc20.test.ts +1 -1
- package/src/tests/logger.test.ts +1 -1
- package/src/utils/erc20.test.ts +1 -4
package/lib/service.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { CallContext } from 'nice-grpc';
|
|
2
|
-
import { BlockBinding,
|
|
2
|
+
import { BlockBinding, DataBinding, ProcessBindingResponse, ProcessBindingsRequest, ProcessBlocksRequest, ProcessConfigRequest, ProcessConfigResponse, ProcessInstructionsRequest, ProcessorServiceImplementation, ProcessResult, ProcessTransactionsRequest, StartRequest } from './gen/processor/protos/processor';
|
|
3
3
|
import { Empty } from './gen/google/protobuf/empty';
|
|
4
4
|
export declare class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
5
5
|
private eventHandlers;
|
|
6
6
|
private traceHandlers;
|
|
7
7
|
private blockHandlers;
|
|
8
|
+
private aptosEventHandlers;
|
|
9
|
+
private aptosCallHandlers;
|
|
8
10
|
private started;
|
|
9
11
|
private contractConfigs;
|
|
10
12
|
private templateInstances;
|
|
@@ -15,11 +17,15 @@ export declare class ProcessorServiceImpl implements ProcessorServiceImplementat
|
|
|
15
17
|
configure(): Promise<void>;
|
|
16
18
|
start(request: StartRequest, context: CallContext): Promise<Empty>;
|
|
17
19
|
stop(request: Empty, context: CallContext): Promise<Empty>;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
processBindings(request: ProcessBindingsRequest, options?: CallContext): Promise<ProcessBindingResponse>;
|
|
21
|
+
processBinding(request: DataBinding, options?: CallContext): Promise<ProcessResult>;
|
|
22
|
+
processLogs(request: ProcessBindingsRequest, context: CallContext): Promise<ProcessBindingResponse>;
|
|
23
|
+
processTransactions(request: ProcessTransactionsRequest, context: CallContext): Promise<ProcessBindingResponse>;
|
|
24
|
+
processInstructions(request: ProcessInstructionsRequest, context: CallContext): Promise<ProcessBindingResponse>;
|
|
25
|
+
processBlocks(request: ProcessBlocksRequest, context: CallContext): Promise<ProcessBindingResponse>;
|
|
22
26
|
processBlock(binding: BlockBinding): Promise<ProcessResult>;
|
|
23
|
-
processTraces(request:
|
|
24
|
-
processTrace(binding:
|
|
27
|
+
processTraces(request: ProcessBindingsRequest, context: CallContext): Promise<ProcessBindingResponse>;
|
|
28
|
+
processTrace(binding: DataBinding): Promise<ProcessResult>;
|
|
29
|
+
processAptosEvent(binding: DataBinding): Promise<ProcessResult>;
|
|
30
|
+
processAptosCall(binding: DataBinding): Promise<ProcessResult>;
|
|
25
31
|
}
|
package/lib/service.js
CHANGED
|
@@ -15,6 +15,8 @@ class ProcessorServiceImpl {
|
|
|
15
15
|
eventHandlers = [];
|
|
16
16
|
traceHandlers = [];
|
|
17
17
|
blockHandlers = [];
|
|
18
|
+
aptosEventHandlers = [];
|
|
19
|
+
aptosCallHandlers = [];
|
|
18
20
|
// map from chain id to list of processors
|
|
19
21
|
// private blockHandlers = new Map<string, ((block: Block) => Promise<ProcessResult>)[]>()
|
|
20
22
|
// private processorsByChainId = new Map<string, BaseProcessor<BaseContract, BoundContractView<BaseContract, any>>>()
|
|
@@ -64,6 +66,8 @@ class ProcessorServiceImpl {
|
|
|
64
66
|
startBlock: processor.config.startBlock,
|
|
65
67
|
endBlock: DEFAULT_MAX_BLOCK,
|
|
66
68
|
instructionConfig: undefined,
|
|
69
|
+
aptosEventConfigs: [],
|
|
70
|
+
aptosCallConfigs: [],
|
|
67
71
|
};
|
|
68
72
|
if (processor.config.endBlock) {
|
|
69
73
|
contractConfig.endBlock = processor.config.endBlock;
|
|
@@ -71,6 +75,7 @@ class ProcessorServiceImpl {
|
|
|
71
75
|
// Step 1. Prepare all the block handlers
|
|
72
76
|
for (const blockHandler of processor.blockHandlers) {
|
|
73
77
|
const handlerId = this.blockHandlers.push(blockHandler) - 1;
|
|
78
|
+
// TODO wrap the block handler into one
|
|
74
79
|
contractConfig.blockConfigs.push({
|
|
75
80
|
handlerId: handlerId,
|
|
76
81
|
});
|
|
@@ -135,6 +140,8 @@ class ProcessorServiceImpl {
|
|
|
135
140
|
parsedInstruction: solanaProcessor.fromParsedInstruction !== null,
|
|
136
141
|
rawDataInstruction: solanaProcessor.decodeInstruction !== null,
|
|
137
142
|
},
|
|
143
|
+
aptosEventConfigs: [],
|
|
144
|
+
aptosCallConfigs: [],
|
|
138
145
|
};
|
|
139
146
|
this.contractConfigs.push(contractConfig);
|
|
140
147
|
}
|
|
@@ -154,6 +161,8 @@ class ProcessorServiceImpl {
|
|
|
154
161
|
startBlock: suiProcessor.config.startSeqNumber,
|
|
155
162
|
endBlock: DEFAULT_MAX_BLOCK,
|
|
156
163
|
instructionConfig: undefined,
|
|
164
|
+
aptosEventConfigs: [],
|
|
165
|
+
aptosCallConfigs: [],
|
|
157
166
|
};
|
|
158
167
|
this.contractConfigs.push(contractConfig);
|
|
159
168
|
}
|
|
@@ -173,7 +182,33 @@ class ProcessorServiceImpl {
|
|
|
173
182
|
startBlock: aptosProcessor.config.startSeqNumber,
|
|
174
183
|
endBlock: DEFAULT_MAX_BLOCK,
|
|
175
184
|
instructionConfig: undefined,
|
|
185
|
+
aptosEventConfigs: [],
|
|
186
|
+
aptosCallConfigs: [],
|
|
176
187
|
};
|
|
188
|
+
// 1. Prepare event handlers
|
|
189
|
+
for (const handler of aptosProcessor.eventHandlers) {
|
|
190
|
+
const handlerId = this.aptosEventHandlers.push(handler.handler) - 1;
|
|
191
|
+
const eventHandlerConfig = {
|
|
192
|
+
filters: handler.filters,
|
|
193
|
+
handlerId,
|
|
194
|
+
};
|
|
195
|
+
contractConfig.aptosEventConfigs.push(eventHandlerConfig);
|
|
196
|
+
}
|
|
197
|
+
// 2. Prepare function handlers
|
|
198
|
+
for (const handler of aptosProcessor.callHandlers) {
|
|
199
|
+
const handlerId = this.aptosCallHandlers.push(handler.handler) - 1;
|
|
200
|
+
const functionHandlerConfig = {
|
|
201
|
+
filters: handler.filters.map((filter) => {
|
|
202
|
+
return {
|
|
203
|
+
function: filter.function,
|
|
204
|
+
typeArguments: filter.typeArguments ?? [],
|
|
205
|
+
withTypeArguments: filter.typeArguments ? true : false,
|
|
206
|
+
};
|
|
207
|
+
}),
|
|
208
|
+
handlerId,
|
|
209
|
+
};
|
|
210
|
+
contractConfig.aptosCallConfigs.push(functionHandlerConfig);
|
|
211
|
+
}
|
|
177
212
|
this.contractConfigs.push(contractConfig);
|
|
178
213
|
}
|
|
179
214
|
}
|
|
@@ -219,19 +254,46 @@ class ProcessorServiceImpl {
|
|
|
219
254
|
}
|
|
220
255
|
return {};
|
|
221
256
|
}
|
|
257
|
+
async processBindings(request, options) {
|
|
258
|
+
if (!this.started) {
|
|
259
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.UNAVAILABLE, 'Service Not started.');
|
|
260
|
+
}
|
|
261
|
+
const promises = request.bindings.map((binding) => this.processBinding(binding));
|
|
262
|
+
const result = mergeProcessResults(await Promise.all(promises));
|
|
263
|
+
let updated = false;
|
|
264
|
+
if (global.PROCESSOR_STATE.templatesInstances &&
|
|
265
|
+
this.templateInstances.length != global.PROCESSOR_STATE.templatesInstances.length) {
|
|
266
|
+
await this.configure();
|
|
267
|
+
updated = true;
|
|
268
|
+
}
|
|
269
|
+
return {
|
|
270
|
+
result,
|
|
271
|
+
configUpdated: updated,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
async processBinding(request, options) {
|
|
275
|
+
switch (request.handlerType) {
|
|
276
|
+
case processor_1.HandlerType.APT_CALL:
|
|
277
|
+
return this.processAptosCall(request);
|
|
278
|
+
case processor_1.HandlerType.APT_EVENT:
|
|
279
|
+
return this.processAptosEvent(request);
|
|
280
|
+
default:
|
|
281
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
222
284
|
async processLogs(request, context) {
|
|
223
285
|
if (!this.started) {
|
|
224
286
|
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.UNAVAILABLE, 'Service Not started.');
|
|
225
287
|
}
|
|
226
288
|
const promises = [];
|
|
227
|
-
for (const l of request.
|
|
228
|
-
if (!l.
|
|
289
|
+
for (const l of request.bindings) {
|
|
290
|
+
if (!l.data) {
|
|
229
291
|
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Log can't be null");
|
|
230
292
|
}
|
|
231
293
|
// const jsonString = Buffer.from(l.log.raw.buffer).toString("utf-8")
|
|
232
294
|
// const jsonString = String.fromCharCode.apply(null, l.log.raw)
|
|
233
295
|
try {
|
|
234
|
-
const jsonString = Utf8ArrayToStr(l.
|
|
296
|
+
const jsonString = Utf8ArrayToStr(l.data.raw);
|
|
235
297
|
const log = JSON.parse(jsonString);
|
|
236
298
|
const handler = this.eventHandlers[l.handlerId];
|
|
237
299
|
const promise = handler(log).catch((e) => {
|
|
@@ -250,7 +312,7 @@ class ProcessorServiceImpl {
|
|
|
250
312
|
await this.configure();
|
|
251
313
|
updated = true;
|
|
252
314
|
}
|
|
253
|
-
recordRuntimeInfo(result, processor_1.HandlerType.
|
|
315
|
+
recordRuntimeInfo(result, processor_1.HandlerType.ETH_LOG);
|
|
254
316
|
return {
|
|
255
317
|
result,
|
|
256
318
|
configUpdated: updated,
|
|
@@ -260,11 +322,7 @@ class ProcessorServiceImpl {
|
|
|
260
322
|
if (!this.started) {
|
|
261
323
|
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.UNAVAILABLE, 'Service not started.');
|
|
262
324
|
}
|
|
263
|
-
const result = {
|
|
264
|
-
gauges: [],
|
|
265
|
-
counters: [],
|
|
266
|
-
logs: [],
|
|
267
|
-
};
|
|
325
|
+
const result = processor_1.ProcessResult.fromPartial({});
|
|
268
326
|
if (request.chainId.toLowerCase().startsWith('sui') && global.PROCESSOR_STATE.suiProcessors) {
|
|
269
327
|
const processorPromises = [];
|
|
270
328
|
for (const txn of request.transactions) {
|
|
@@ -304,17 +362,14 @@ class ProcessorServiceImpl {
|
|
|
304
362
|
recordRuntimeInfo(result, processor_1.HandlerType.TRANSACTION);
|
|
305
363
|
return {
|
|
306
364
|
result,
|
|
365
|
+
configUpdated: false,
|
|
307
366
|
};
|
|
308
367
|
}
|
|
309
368
|
async processInstructions(request, context) {
|
|
310
369
|
if (!this.started) {
|
|
311
370
|
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.UNAVAILABLE, 'Service not started.');
|
|
312
371
|
}
|
|
313
|
-
const result = {
|
|
314
|
-
gauges: [],
|
|
315
|
-
counters: [],
|
|
316
|
-
logs: [],
|
|
317
|
-
};
|
|
372
|
+
const result = processor_1.ProcessResult.fromPartial({});
|
|
318
373
|
// Only have instruction handlers for solana processors
|
|
319
374
|
if (global.PROCESSOR_STATE.solanaProcessors) {
|
|
320
375
|
const processorPromises = [];
|
|
@@ -353,6 +408,7 @@ class ProcessorServiceImpl {
|
|
|
353
408
|
recordRuntimeInfo(result, processor_1.HandlerType.INSTRUCTION);
|
|
354
409
|
return {
|
|
355
410
|
result,
|
|
411
|
+
configUpdated: false,
|
|
356
412
|
};
|
|
357
413
|
}
|
|
358
414
|
async processBlocks(request, context) {
|
|
@@ -364,6 +420,7 @@ class ProcessorServiceImpl {
|
|
|
364
420
|
recordRuntimeInfo(result, processor_1.HandlerType.BLOCK);
|
|
365
421
|
return {
|
|
366
422
|
result,
|
|
423
|
+
configUpdated: false,
|
|
367
424
|
};
|
|
368
425
|
}
|
|
369
426
|
async processBlock(binding) {
|
|
@@ -385,23 +442,50 @@ class ProcessorServiceImpl {
|
|
|
385
442
|
if (!this.started) {
|
|
386
443
|
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.UNAVAILABLE, 'Service Not started.');
|
|
387
444
|
}
|
|
388
|
-
const promises = request.
|
|
445
|
+
const promises = request.bindings.map((binding) => this.processTrace(binding));
|
|
389
446
|
const result = mergeProcessResults(await Promise.all(promises));
|
|
390
|
-
recordRuntimeInfo(result, processor_1.HandlerType.
|
|
447
|
+
recordRuntimeInfo(result, processor_1.HandlerType.ETH_TRACE);
|
|
391
448
|
return {
|
|
392
449
|
result,
|
|
450
|
+
configUpdated: false,
|
|
393
451
|
};
|
|
394
452
|
}
|
|
395
453
|
async processTrace(binding) {
|
|
396
|
-
if (!binding.
|
|
454
|
+
if (!binding.data) {
|
|
397
455
|
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Trace can't be empty");
|
|
398
456
|
}
|
|
399
|
-
const jsonString = Utf8ArrayToStr(binding.
|
|
457
|
+
const jsonString = Utf8ArrayToStr(binding.data.raw);
|
|
400
458
|
const trace = JSON.parse(jsonString);
|
|
401
459
|
return this.traceHandlers[binding.handlerId](trace).catch((e) => {
|
|
402
460
|
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'error processing trace: ' + jsonString + '\n' + errorString(e));
|
|
403
461
|
});
|
|
404
462
|
}
|
|
463
|
+
async processAptosEvent(binding) {
|
|
464
|
+
if (!binding.data) {
|
|
465
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Event can't be empty");
|
|
466
|
+
}
|
|
467
|
+
const jsonString = Utf8ArrayToStr(binding.data.raw);
|
|
468
|
+
const event = JSON.parse(jsonString);
|
|
469
|
+
// only support aptos event for now
|
|
470
|
+
const result = await this.aptosEventHandlers[binding.handlerId](event).catch((e) => {
|
|
471
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'error processing event: ' + jsonString + '\n' + errorString(e));
|
|
472
|
+
});
|
|
473
|
+
recordRuntimeInfo(result, processor_1.HandlerType.APT_EVENT);
|
|
474
|
+
return result;
|
|
475
|
+
}
|
|
476
|
+
async processAptosCall(binding) {
|
|
477
|
+
if (!binding.data) {
|
|
478
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Event can't be empty");
|
|
479
|
+
}
|
|
480
|
+
const jsonString = Utf8ArrayToStr(binding.data.raw);
|
|
481
|
+
const call = JSON.parse(jsonString);
|
|
482
|
+
// only support aptos call for now
|
|
483
|
+
const result = await this.aptosCallHandlers[binding.handlerId](call).catch((e) => {
|
|
484
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'error processing call: ' + jsonString + '\n' + errorString(e));
|
|
485
|
+
});
|
|
486
|
+
recordRuntimeInfo(result, processor_1.HandlerType.APT_CALL);
|
|
487
|
+
return result;
|
|
488
|
+
}
|
|
405
489
|
}
|
|
406
490
|
exports.ProcessorServiceImpl = ProcessorServiceImpl;
|
|
407
491
|
// https://ourcodeworld.com/articles/read/164/how-to-convert-an-uint8array-to-string-in-javascript
|
package/lib/service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":";;;;;;AACA,yCAA4D;AAC5D,yCAA+E;AAE/E,gEAuByC;AAGzC,gDAAuB;AACvB,+BAAkC;AAGlC,MAAM,iBAAiB,GAAG,cAAI,CAAC,IAAI,CAAA;AAEnC,MAAM,cAAc,GAAG,gBAAgB,CAAA;AAEvC,MAAa,oBAAoB;IACvB,aAAa,GAA+C,EAAE,CAAA;IAC9D,aAAa,GAAiD,EAAE,CAAA;IAChE,aAAa,GAAiD,EAAE,CAAA;IAExE,0CAA0C;IAC1C,0FAA0F;IAC1F,qHAAqH;IAE7G,OAAO,GAAG,KAAK,CAAA;IACf,eAAe,CAAkB;IACjC,iBAAiB,CAAoB;IAC5B,MAAM,CAAY;IAElB,eAAe,CAAa;IAE7C,YAAY,MAAkB,EAAE,eAA4B;QAC1D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;IACxC,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,OAA6B,EAAE,OAAoB;QACjE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACjB,MAAM,IAAI,uBAAW,CAAC,kBAAM,CAAC,WAAW,EAAE,sBAAsB,CAAC,CAAA;SAClE;QACD,OAAO;YACL,uBAAuB;YACvB,MAAM,EAAE,SAAS;YACjB,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;SAC1C,CAAA;IACH,CAAC;IAED,KAAK,CAAC,SAAS;QACb,IAAI,CAAC,aAAa,GAAG,EAAE,CAAA;QACvB,IAAI,CAAC,iBAAiB,GAAG,EAAE,CAAA;QAC3B,mCAAmC;QACnC,IAAI,CAAC,eAAe,GAAG,EAAE,CAAA;QAEzB,IAAI,CAAC,iBAA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,SAAS,mBAAmB,CAAC,OAAwB;IACnD,MAAM,GAAG,GAAG,yBAAa,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;IAEzC,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE;QACvB,GAAG,CAAC,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;QAC9C,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;QACxC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;KACnC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAsB,EAAE,WAAwB;IACzE,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QAC3B,CAAC,CAAC,WAAW,GAAG;YACd,IAAI,EAAE,WAAW;SAClB,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QAC7B,CAAC,CAAC,WAAW,GAAG;YACd,IAAI,EAAE,WAAW;SAClB,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QACzB,CAAC,CAAC,WAAW,GAAG;YACd,IAAI,EAAE,WAAW;SAClB,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,WAAW,CAAC,CAAQ;IAC3B,OAAO,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,OAAO,CAAA;AAC7B,CAAC","sourcesContent":["import { Block, Log } from '@ethersproject/abstract-provider'\nimport { CallContext, ServerError, Status } from 'nice-grpc'\nimport { APTOS_TESTNET_ID, SOL_MAINMET_ID, SUI_DEVNET_ID } from './utils/chain'\n\nimport {\n BlockBinding,\n ContractConfig,\n HandlerType,\n LogFilter,\n LogHandlerConfig,\n ProcessResult,\n ProcessBlocksRequest,\n ProcessBlocksResponse,\n ProcessConfigRequest,\n ProcessConfigResponse,\n ProcessInstructionsRequest,\n ProcessInstructionsResponse,\n ProcessLogsRequest,\n ProcessLogsResponse,\n ProcessorServiceImplementation,\n ProcessTracesRequest,\n ProcessTracesResponse,\n ProcessTransactionsRequest,\n ProcessTransactionsResponse,\n StartRequest,\n TemplateInstance,\n TraceBinding,\n} from './gen/processor/protos/processor'\n\nimport { Empty } from './gen/google/protobuf/empty'\nimport Long from 'long'\nimport { TextDecoder } from 'util'\nimport { Trace } from './core'\n\nconst DEFAULT_MAX_BLOCK = Long.ZERO\n\nconst USER_PROCESSOR = 'user_processor'\n\nexport class ProcessorServiceImpl implements ProcessorServiceImplementation {\n private eventHandlers: ((event: Log) => Promise<ProcessResult>)[] = []\n private traceHandlers: ((trace: Trace) => Promise<ProcessResult>)[] = []\n private blockHandlers: ((block: Block) => Promise<ProcessResult>)[] = []\n\n // map from chain id to list of processors\n // private blockHandlers = new Map<string, ((block: Block) => Promise<ProcessResult>)[]>()\n // private processorsByChainId = new Map<string, BaseProcessor<BaseContract, BoundContractView<BaseContract, any>>>()\n\n private started = false\n private contractConfigs: ContractConfig[]\n private templateInstances: TemplateInstance[]\n private readonly loader: () => void\n\n private readonly shutdownHandler?: () => void\n\n constructor(loader: () => void, shutdownHandler?: () => void) {\n this.loader = loader\n this.shutdownHandler = shutdownHandler\n }\n\n async getConfig(request: ProcessConfigRequest, context: CallContext): Promise<ProcessConfigResponse> {\n if (!this.started) {\n throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')\n }\n return {\n // TODO project setting\n config: undefined,\n contractConfigs: this.contractConfigs,\n templateInstances: this.templateInstances,\n }\n }\n\n async configure() {\n this.eventHandlers = []\n this.templateInstances = []\n // this.processorsByChainId.clear()\n this.contractConfigs = []\n\n this.templateInstances = [...global.PROCESSOR_STATE.templatesInstances]\n\n // Part 1, prepare EVM processors\n for (const processor of global.PROCESSOR_STATE.processors) {\n // If server favor incremental update this need to change\n // Start basic config for contract\n const chainId = processor.getChainId()\n // this.processorsByChainId.set(chainId, processor)\n\n const contractConfig: ContractConfig = {\n processorType: USER_PROCESSOR,\n contract: {\n name: processor.config.name,\n chainId: chainId.toString(),\n address: processor.config.address,\n abi: '',\n },\n blockConfigs: [],\n logConfigs: [],\n traceConfigs: [],\n startBlock: processor.config.startBlock,\n endBlock: DEFAULT_MAX_BLOCK,\n instructionConfig: undefined,\n }\n if (processor.config.endBlock) {\n contractConfig.endBlock = processor.config.endBlock\n }\n\n // Step 1. Prepare all the block handlers\n for (const blockHandler of processor.blockHandlers) {\n const handlerId = this.blockHandlers.push(blockHandler) - 1\n contractConfig.blockConfigs.push({\n handlerId: handlerId,\n })\n }\n\n // Step 2. Prepare all trace handlers\n for (const traceHandler of processor.traceHandlers) {\n const handlerId = this.traceHandlers.push(traceHandler.handler) - 1\n contractConfig.traceConfigs.push({\n signature: traceHandler.signature,\n handlerId: handlerId,\n })\n }\n\n // Step 3. Prepare all the event handlers\n for (const eventsHandler of processor.eventHandlers) {\n // associate id with filter\n const handlerId = this.eventHandlers.push(eventsHandler.handler) - 1\n const logConfig: LogHandlerConfig = {\n handlerId: handlerId,\n filters: [],\n }\n\n for (const filter of eventsHandler.filters) {\n if (!filter.topics) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Topic should not be null')\n }\n const logFilter: LogFilter = {\n topics: [],\n }\n\n for (const ts of filter.topics) {\n let hashes: string[] = []\n if (Array.isArray(ts)) {\n hashes = hashes.concat(ts)\n } else if (ts) {\n hashes.push(ts)\n }\n logFilter.topics.push({ hashes: hashes })\n }\n logConfig.filters.push(logFilter)\n }\n contractConfig.logConfigs.push(logConfig)\n }\n\n // Finish up a contract\n this.contractConfigs.push(contractConfig)\n }\n\n // Part 2, prepare solana constractors\n for (const solanaProcessor of global.PROCESSOR_STATE.solanaProcessors) {\n const contractConfig: ContractConfig = {\n processorType: USER_PROCESSOR,\n contract: {\n name: solanaProcessor.contractName,\n chainId: SOL_MAINMET_ID, // TODO set in processor\n address: solanaProcessor.address,\n abi: '',\n },\n blockConfigs: [],\n logConfigs: [],\n traceConfigs: [],\n startBlock: solanaProcessor.config.startSlot,\n endBlock: DEFAULT_MAX_BLOCK,\n instructionConfig: {\n innerInstruction: solanaProcessor.processInnerInstruction,\n parsedInstruction: solanaProcessor.fromParsedInstruction !== null,\n rawDataInstruction: solanaProcessor.decodeInstruction !== null,\n },\n }\n this.contractConfigs.push(contractConfig)\n }\n\n // Part 3, prepare sui constractors\n for (const suiProcessor of global.PROCESSOR_STATE.suiProcessors) {\n const contractConfig: ContractConfig = {\n processorType: USER_PROCESSOR,\n contract: {\n name: 'sui contract',\n chainId: SUI_DEVNET_ID,\n address: suiProcessor.address,\n abi: '',\n },\n blockConfigs: [],\n logConfigs: [],\n traceConfigs: [],\n startBlock: suiProcessor.config.startSeqNumber,\n endBlock: DEFAULT_MAX_BLOCK,\n instructionConfig: undefined,\n }\n this.contractConfigs.push(contractConfig)\n }\n\n // Part 3, prepare aptos constractors\n for (const aptosProcessor of global.PROCESSOR_STATE.aptosProcessors) {\n const contractConfig: ContractConfig = {\n processorType: USER_PROCESSOR,\n contract: {\n name: aptosProcessor.name,\n chainId: APTOS_TESTNET_ID,\n address: aptosProcessor.address,\n abi: '',\n },\n blockConfigs: [],\n logConfigs: [],\n traceConfigs: [],\n startBlock: aptosProcessor.config.startSeqNumber,\n endBlock: DEFAULT_MAX_BLOCK,\n instructionConfig: undefined,\n }\n this.contractConfigs.push(contractConfig)\n }\n }\n\n async start(request: StartRequest, context: CallContext): Promise<Empty> {\n if (this.started) {\n return {}\n }\n\n try {\n this.loader()\n } catch (e) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Failed to load processor: ' + errorString(e))\n }\n\n for (const instance of request.templateInstances) {\n const template = global.PROCESSOR_STATE.templates[instance.templateId]\n if (!template) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Invalid template contract:' + instance)\n }\n if (!instance.contract) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Contract Empty from:' + instance)\n }\n template.bind({\n name: instance.contract.name,\n address: instance.contract.address,\n network: Number(instance.contract.chainId),\n startBlock: instance.startBlock,\n endBlock: instance.endBlock,\n })\n }\n try {\n await this.configure()\n } catch (e) {\n throw new ServerError(Status.INTERNAL, 'Failed to start processor : ' + errorString(e))\n }\n this.started = true\n return {}\n }\n\n async stop(request: Empty, context: CallContext): Promise<Empty> {\n console.log('Server Shutting down in 5 seconds')\n if (this.shutdownHandler) {\n setTimeout(this.shutdownHandler, 5000)\n }\n return {}\n }\n\n async processLogs(request: ProcessLogsRequest, context: CallContext): Promise<ProcessLogsResponse> {\n if (!this.started) {\n throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')\n }\n\n const promises: Promise<ProcessResult>[] = []\n for (const l of request.logBindings) {\n if (!l.log) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Log can't be null\")\n }\n // const jsonString = Buffer.from(l.log.raw.buffer).toString(\"utf-8\")\n // const jsonString = String.fromCharCode.apply(null, l.log.raw)\n\n try {\n const jsonString = Utf8ArrayToStr(l.log.raw)\n const log: Log = JSON.parse(jsonString)\n const handler = this.eventHandlers[l.handlerId]\n const promise = handler(log).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing log: ' + jsonString + '\\n' + errorString(e))\n })\n\n promises.push(promise)\n } catch (e) {\n throw new ServerError(Status.INTERNAL, 'error parse log: ' + l)\n }\n }\n\n const result = mergeProcessResults(await Promise.all(promises))\n\n let updated = false\n if (\n global.PROCESSOR_STATE.templatesInstances &&\n this.templateInstances.length != global.PROCESSOR_STATE.templatesInstances.length\n ) {\n await this.configure()\n updated = true\n }\n\n recordRuntimeInfo(result, HandlerType.LOG)\n return {\n result,\n configUpdated: updated,\n }\n }\n\n async processTransactions(\n request: ProcessTransactionsRequest,\n context: CallContext\n ): Promise<ProcessTransactionsResponse> {\n if (!this.started) {\n throw new ServerError(Status.UNAVAILABLE, 'Service not started.')\n }\n\n const result: ProcessResult = {\n gauges: [],\n counters: [],\n logs: [],\n }\n\n if (request.chainId.toLowerCase().startsWith('sui') && global.PROCESSOR_STATE.suiProcessors) {\n const processorPromises: Promise<void>[] = []\n for (const txn of request.transactions) {\n processorPromises.push(\n new Promise((resolve, _) => {\n for (const processor of global.PROCESSOR_STATE.suiProcessors) {\n const res = processor.handleTransaction(\n JSON.parse(new TextDecoder().decode(txn.raw)),\n txn.slot ?? Long.fromNumber(0)\n )\n if (res) {\n res.gauges.forEach((g) => result.gauges.push(g))\n res.counters.forEach((c) => result.counters.push(c))\n res.logs.forEach((l) => result.logs.push(l))\n }\n }\n resolve()\n })\n )\n }\n await Promise.all(processorPromises)\n }\n\n if (request.chainId.toLowerCase().startsWith('apt') && global.PROCESSOR_STATE.aptosProcessors) {\n const processorPromises: Promise<void>[] = []\n for (const txn of request.transactions) {\n processorPromises.push(\n new Promise((resolve, _) => {\n for (const processor of global.PROCESSOR_STATE.aptosProcessors) {\n if (processor.address === txn.programAccountId!) {\n const res = processor.handleTransaction(\n JSON.parse(new TextDecoder().decode(txn.raw)),\n txn.slot ?? Long.fromNumber(0)\n )\n if (res) {\n res.gauges.forEach((g) => result.gauges.push(g))\n res.counters.forEach((c) => result.counters.push(c))\n res.logs.forEach((l) => result.logs.push(l))\n }\n }\n }\n resolve()\n })\n )\n }\n await Promise.all(processorPromises)\n }\n\n recordRuntimeInfo(result, HandlerType.TRANSACTION)\n return {\n result,\n }\n }\n\n async processInstructions(\n request: ProcessInstructionsRequest,\n context: CallContext\n ): Promise<ProcessInstructionsResponse> {\n if (!this.started) {\n throw new ServerError(Status.UNAVAILABLE, 'Service not started.')\n }\n\n const result: ProcessResult = {\n gauges: [],\n counters: [],\n logs: [],\n }\n\n // Only have instruction handlers for solana processors\n if (global.PROCESSOR_STATE.solanaProcessors) {\n const processorPromises: Promise<void>[] = []\n for (const instruction of request.instructions) {\n if (!instruction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'instruction cannot be null')\n }\n\n processorPromises.push(\n new Promise((resolve, _) => {\n for (const processor of global.PROCESSOR_STATE.solanaProcessors) {\n if (processor.address === instruction.programAccountId) {\n let res: ProcessResult | null\n if (instruction.parsed) {\n res = processor.handleInstruction(\n JSON.parse(new TextDecoder().decode(instruction.parsed)),\n instruction.slot\n )\n } else if (instruction.instructionData) {\n res = processor.handleInstruction(instruction.instructionData, instruction.slot)\n } else {\n continue\n }\n if (res) {\n res.gauges.forEach((g) => result.gauges.push(g))\n res.counters.forEach((c) => result.counters.push(c))\n res.logs.forEach((l) => result.logs.push(l))\n } else {\n console.warn(\n `Failed to decode the instruction: ${instruction.instructionData} with slot: ${instruction.slot}`\n )\n }\n }\n }\n resolve()\n })\n )\n }\n\n await Promise.all(processorPromises)\n }\n\n recordRuntimeInfo(result, HandlerType.INSTRUCTION)\n return {\n result,\n }\n }\n\n async processBlocks(request: ProcessBlocksRequest, context: CallContext): Promise<ProcessBlocksResponse> {\n if (!this.started) {\n throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')\n }\n\n const promises = request.blockBindings.map((binding) => this.processBlock(binding))\n const result = mergeProcessResults(await Promise.all(promises))\n\n recordRuntimeInfo(result, HandlerType.BLOCK)\n return {\n result,\n }\n }\n\n async processBlock(binding: BlockBinding): Promise<ProcessResult> {\n if (!binding.block) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Block can't be empty\")\n }\n const jsonString = Utf8ArrayToStr(binding.block.raw)\n\n const block: Block = JSON.parse(jsonString)\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n const promise = this.blockHandlers[handlerId](block).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing block: ' + block.number + '\\n' + errorString(e))\n })\n promises.push(promise)\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processTraces(request: ProcessTracesRequest, context: CallContext): Promise<ProcessTracesResponse> {\n if (!this.started) {\n throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')\n }\n\n const promises = request.traceBindings.map((binding) => this.processTrace(binding))\n const result = mergeProcessResults(await Promise.all(promises))\n\n recordRuntimeInfo(result, HandlerType.TRACE)\n return {\n result,\n }\n }\n\n async processTrace(binding: TraceBinding): Promise<ProcessResult> {\n if (!binding.trace) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Trace can't be empty\")\n }\n const jsonString = Utf8ArrayToStr(binding.trace.raw)\n const trace: Trace = JSON.parse(jsonString)\n\n return this.traceHandlers[binding.handlerId](trace).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing trace: ' + jsonString + '\\n' + errorString(e))\n })\n }\n}\n\n// https://ourcodeworld.com/articles/read/164/how-to-convert-an-uint8array-to-string-in-javascript\n/* eslint-disable */\nfunction Utf8ArrayToStr(array: Uint8Array) {\n let out, i, len, c\n let char2, char3\n\n out = ''\n len = array.length\n i = 0\n while (i < len) {\n c = array[i++]\n switch (c >> 4) {\n case 0:\n case 1:\n case 2:\n case 3:\n case 4:\n case 5:\n case 6:\n case 7:\n // 0xxxxxxx\n out += String.fromCharCode(c)\n break\n case 12:\n case 13:\n // 110x xxxx 10xx xxxx\n char2 = array[i++]\n out += String.fromCharCode(((c & 0x1f) << 6) | (char2 & 0x3f))\n break\n case 14:\n // 1110 xxxx 10xx xxxx 10xx xxxx\n char2 = array[i++]\n char3 = array[i++]\n out += String.fromCharCode(((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0))\n break\n }\n }\n\n return out\n}\n\nfunction mergeProcessResults(results: ProcessResult[]): ProcessResult {\n const res = ProcessResult.fromPartial({})\n\n for (const r of results) {\n res.counters = res.counters.concat(r.counters)\n res.gauges = res.gauges.concat(r.gauges)\n res.logs = res.logs.concat(r.logs)\n }\n return res\n}\n\nfunction recordRuntimeInfo(results: ProcessResult, handlerType: HandlerType) {\n results.gauges.forEach((e) => {\n e.runtimeInfo = {\n from: handlerType,\n }\n })\n\n results.counters.forEach((e) => {\n e.runtimeInfo = {\n from: handlerType,\n }\n })\n\n results.logs.forEach((e) => {\n e.runtimeInfo = {\n from: handlerType,\n }\n })\n}\n\nfunction errorString(e: Error): string {\n return e.stack || e.message\n}\n"]}
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":";;;;;;AACA,yCAA4D;AAC5D,yCAA+E;AAE/E,gEAoByC;AAGzC,gDAAuB;AACvB,+BAAkC;AAGlC,MAAM,iBAAiB,GAAG,cAAI,CAAC,IAAI,CAAA;AAEnC,MAAM,cAAc,GAAG,gBAAgB,CAAA;AAEvC,MAAa,oBAAoB;IACvB,aAAa,GAA+C,EAAE,CAAA;IAC9D,aAAa,GAAiD,EAAE,CAAA;IAChE,aAAa,GAAiD,EAAE,CAAA;IAChE,kBAAkB,GAA+C,EAAE,CAAA;IACnE,iBAAiB,GAA8C,EAAE,CAAA;IAEzE,0CAA0C;IAC1C,0FAA0F;IAC1F,qHAAqH;IAE7G,OAAO,GAAG,KAAK,CAAA;IACf,eAAe,CAAkB;IACjC,iBAAiB,CAAoB;IAC5B,MAAM,CAAY;IAElB,eAAe,CAAa;IAE7C,YAAY,MAAkB,EAAE,eAA4B;QAC1D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;IACxC,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,OAA6B,EAAE,OAAoB;QACjE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACjB,MAAM,IAAI,uBAAW,CAAC,kBAAM,CAAC,WAAW,EAAE,sBAAsB,CAAC,CAAA;SAClE;QACD,OAAO;YACL,uBAAuB;YACvB,MAAM,EAAE,SAAS;YACjB,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;SAC1C,CAAA;IACH,CAAC;IAED,KAAK,CAA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CAAC;AAED,SAAS,WAAW,CAAC,CAAQ;IAC3B,OAAO,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,OAAO,CAAA;AAC7B,CAAC","sourcesContent":["import { Block, Log } from '@ethersproject/abstract-provider'\nimport { CallContext, ServerError, Status } from 'nice-grpc'\nimport { APTOS_TESTNET_ID, SOL_MAINMET_ID, SUI_DEVNET_ID } from './utils/chain'\n\nimport {\n AptosCallHandlerConfig,\n AptosEventHandlerConfig,\n BlockBinding,\n ContractConfig,\n DataBinding,\n HandlerType,\n LogFilter,\n LogHandlerConfig,\n ProcessBindingResponse,\n ProcessBindingsRequest,\n ProcessBlocksRequest,\n ProcessConfigRequest,\n ProcessConfigResponse,\n ProcessInstructionsRequest,\n ProcessorServiceImplementation,\n ProcessResult,\n ProcessTransactionsRequest,\n StartRequest,\n TemplateInstance,\n} from './gen/processor/protos/processor'\n\nimport { Empty } from './gen/google/protobuf/empty'\nimport Long from 'long'\nimport { TextDecoder } from 'util'\nimport { Trace } from './core'\n\nconst DEFAULT_MAX_BLOCK = Long.ZERO\n\nconst USER_PROCESSOR = 'user_processor'\n\nexport class ProcessorServiceImpl implements ProcessorServiceImplementation {\n private eventHandlers: ((event: Log) => Promise<ProcessResult>)[] = []\n private traceHandlers: ((trace: Trace) => Promise<ProcessResult>)[] = []\n private blockHandlers: ((block: Block) => Promise<ProcessResult>)[] = []\n private aptosEventHandlers: ((event: any) => Promise<ProcessResult>)[] = []\n private aptosCallHandlers: ((func: any) => Promise<ProcessResult>)[] = []\n\n // map from chain id to list of processors\n // private blockHandlers = new Map<string, ((block: Block) => Promise<ProcessResult>)[]>()\n // private processorsByChainId = new Map<string, BaseProcessor<BaseContract, BoundContractView<BaseContract, any>>>()\n\n private started = false\n private contractConfigs: ContractConfig[]\n private templateInstances: TemplateInstance[]\n private readonly loader: () => void\n\n private readonly shutdownHandler?: () => void\n\n constructor(loader: () => void, shutdownHandler?: () => void) {\n this.loader = loader\n this.shutdownHandler = shutdownHandler\n }\n\n async getConfig(request: ProcessConfigRequest, context: CallContext): Promise<ProcessConfigResponse> {\n if (!this.started) {\n throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')\n }\n return {\n // TODO project setting\n config: undefined,\n contractConfigs: this.contractConfigs,\n templateInstances: this.templateInstances,\n }\n }\n\n async configure() {\n this.eventHandlers = []\n this.templateInstances = []\n // this.processorsByChainId.clear()\n this.contractConfigs = []\n\n this.templateInstances = [...global.PROCESSOR_STATE.templatesInstances]\n\n // Part 1, prepare EVM processors\n for (const processor of global.PROCESSOR_STATE.processors) {\n // If server favor incremental update this need to change\n // Start basic config for contract\n const chainId = processor.getChainId()\n // this.processorsByChainId.set(chainId, processor)\n\n const contractConfig: ContractConfig = {\n processorType: USER_PROCESSOR,\n contract: {\n name: processor.config.name,\n chainId: chainId.toString(),\n address: processor.config.address,\n abi: '',\n },\n blockConfigs: [],\n logConfigs: [],\n traceConfigs: [],\n startBlock: processor.config.startBlock,\n endBlock: DEFAULT_MAX_BLOCK,\n instructionConfig: undefined,\n aptosEventConfigs: [],\n aptosCallConfigs: [],\n }\n if (processor.config.endBlock) {\n contractConfig.endBlock = processor.config.endBlock\n }\n\n // Step 1. Prepare all the block handlers\n for (const blockHandler of processor.blockHandlers) {\n const handlerId = this.blockHandlers.push(blockHandler) - 1\n // TODO wrap the block handler into one\n\n contractConfig.blockConfigs.push({\n handlerId: handlerId,\n })\n }\n\n // Step 2. Prepare all trace handlers\n for (const traceHandler of processor.traceHandlers) {\n const handlerId = this.traceHandlers.push(traceHandler.handler) - 1\n contractConfig.traceConfigs.push({\n signature: traceHandler.signature,\n handlerId: handlerId,\n })\n }\n\n // Step 3. Prepare all the event handlers\n for (const eventsHandler of processor.eventHandlers) {\n // associate id with filter\n const handlerId = this.eventHandlers.push(eventsHandler.handler) - 1\n const logConfig: LogHandlerConfig = {\n handlerId: handlerId,\n filters: [],\n }\n\n for (const filter of eventsHandler.filters) {\n if (!filter.topics) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Topic should not be null')\n }\n const logFilter: LogFilter = {\n topics: [],\n }\n\n for (const ts of filter.topics) {\n let hashes: string[] = []\n if (Array.isArray(ts)) {\n hashes = hashes.concat(ts)\n } else if (ts) {\n hashes.push(ts)\n }\n logFilter.topics.push({ hashes: hashes })\n }\n logConfig.filters.push(logFilter)\n }\n contractConfig.logConfigs.push(logConfig)\n }\n\n // Finish up a contract\n this.contractConfigs.push(contractConfig)\n }\n\n // Part 2, prepare solana constractors\n for (const solanaProcessor of global.PROCESSOR_STATE.solanaProcessors) {\n const contractConfig: ContractConfig = {\n processorType: USER_PROCESSOR,\n contract: {\n name: solanaProcessor.contractName,\n chainId: SOL_MAINMET_ID,\n address: solanaProcessor.address,\n abi: '',\n },\n blockConfigs: [],\n logConfigs: [],\n traceConfigs: [],\n startBlock: solanaProcessor.config.startSlot,\n endBlock: DEFAULT_MAX_BLOCK,\n instructionConfig: {\n innerInstruction: solanaProcessor.processInnerInstruction,\n parsedInstruction: solanaProcessor.fromParsedInstruction !== null,\n rawDataInstruction: solanaProcessor.decodeInstruction !== null,\n },\n aptosEventConfigs: [],\n aptosCallConfigs: [],\n }\n this.contractConfigs.push(contractConfig)\n }\n\n // Part 3, prepare sui constractors\n for (const suiProcessor of global.PROCESSOR_STATE.suiProcessors) {\n const contractConfig: ContractConfig = {\n processorType: USER_PROCESSOR,\n contract: {\n name: 'sui contract',\n chainId: SUI_DEVNET_ID,\n address: suiProcessor.address,\n abi: '',\n },\n blockConfigs: [],\n logConfigs: [],\n traceConfigs: [],\n startBlock: suiProcessor.config.startSeqNumber,\n endBlock: DEFAULT_MAX_BLOCK,\n instructionConfig: undefined,\n aptosEventConfigs: [],\n aptosCallConfigs: [],\n }\n this.contractConfigs.push(contractConfig)\n }\n\n // Part 3, prepare aptos constractors\n for (const aptosProcessor of global.PROCESSOR_STATE.aptosProcessors) {\n const contractConfig: ContractConfig = {\n processorType: USER_PROCESSOR,\n contract: {\n name: aptosProcessor.name,\n chainId: APTOS_TESTNET_ID,\n address: aptosProcessor.address,\n abi: '',\n },\n blockConfigs: [],\n logConfigs: [],\n traceConfigs: [],\n startBlock: aptosProcessor.config.startSeqNumber,\n endBlock: DEFAULT_MAX_BLOCK,\n instructionConfig: undefined,\n aptosEventConfigs: [],\n aptosCallConfigs: [],\n }\n // 1. Prepare event handlers\n for (const handler of aptosProcessor.eventHandlers) {\n const handlerId = this.aptosEventHandlers.push(handler.handler) - 1\n const eventHandlerConfig: AptosEventHandlerConfig = {\n filters: handler.filters,\n handlerId,\n }\n contractConfig.aptosEventConfigs.push(eventHandlerConfig)\n }\n\n // 2. Prepare function handlers\n for (const handler of aptosProcessor.callHandlers) {\n const handlerId = this.aptosCallHandlers.push(handler.handler) - 1\n const functionHandlerConfig: AptosCallHandlerConfig = {\n filters: handler.filters.map((filter) => {\n return {\n function: filter.function,\n typeArguments: filter.typeArguments ?? [],\n withTypeArguments: filter.typeArguments ? true : false,\n }\n }),\n handlerId,\n }\n contractConfig.aptosCallConfigs.push(functionHandlerConfig)\n }\n this.contractConfigs.push(contractConfig)\n }\n }\n\n async start(request: StartRequest, context: CallContext): Promise<Empty> {\n if (this.started) {\n return {}\n }\n\n try {\n this.loader()\n } catch (e) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Failed to load processor: ' + errorString(e))\n }\n\n for (const instance of request.templateInstances) {\n const template = global.PROCESSOR_STATE.templates[instance.templateId]\n if (!template) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Invalid template contract:' + instance)\n }\n if (!instance.contract) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Contract Empty from:' + instance)\n }\n template.bind({\n name: instance.contract.name,\n address: instance.contract.address,\n network: Number(instance.contract.chainId),\n startBlock: instance.startBlock,\n endBlock: instance.endBlock,\n })\n }\n try {\n await this.configure()\n } catch (e) {\n throw new ServerError(Status.INTERNAL, 'Failed to start processor : ' + errorString(e))\n }\n this.started = true\n return {}\n }\n\n async stop(request: Empty, context: CallContext): Promise<Empty> {\n console.log('Server Shutting down in 5 seconds')\n if (this.shutdownHandler) {\n setTimeout(this.shutdownHandler, 5000)\n }\n return {}\n }\n\n async processBindings(request: ProcessBindingsRequest, options?: CallContext): Promise<ProcessBindingResponse> {\n if (!this.started) {\n throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')\n }\n\n const promises = request.bindings.map((binding) => this.processBinding(binding))\n const result = mergeProcessResults(await Promise.all(promises))\n\n let updated = false\n if (\n global.PROCESSOR_STATE.templatesInstances &&\n this.templateInstances.length != global.PROCESSOR_STATE.templatesInstances.length\n ) {\n await this.configure()\n updated = true\n }\n\n return {\n result,\n configUpdated: updated,\n }\n }\n\n async processBinding(request: DataBinding, options?: CallContext): Promise<ProcessResult> {\n switch (request.handlerType) {\n case HandlerType.APT_CALL:\n return this.processAptosCall(request)\n case HandlerType.APT_EVENT:\n return this.processAptosEvent(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n\n async processLogs(request: ProcessBindingsRequest, context: CallContext): Promise<ProcessBindingResponse> {\n if (!this.started) {\n throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')\n }\n\n const promises: Promise<ProcessResult>[] = []\n for (const l of request.bindings) {\n if (!l.data) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Log can't be null\")\n }\n // const jsonString = Buffer.from(l.log.raw.buffer).toString(\"utf-8\")\n // const jsonString = String.fromCharCode.apply(null, l.log.raw)\n\n try {\n const jsonString = Utf8ArrayToStr(l.data.raw)\n const log: Log = JSON.parse(jsonString)\n const handler = this.eventHandlers[l.handlerId]\n const promise = handler(log).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing log: ' + jsonString + '\\n' + errorString(e))\n })\n\n promises.push(promise)\n } catch (e) {\n throw new ServerError(Status.INTERNAL, 'error parse log: ' + l)\n }\n }\n\n const result = mergeProcessResults(await Promise.all(promises))\n\n let updated = false\n if (\n global.PROCESSOR_STATE.templatesInstances &&\n this.templateInstances.length != global.PROCESSOR_STATE.templatesInstances.length\n ) {\n await this.configure()\n updated = true\n }\n\n recordRuntimeInfo(result, HandlerType.ETH_LOG)\n return {\n result,\n configUpdated: updated,\n }\n }\n\n async processTransactions(\n request: ProcessTransactionsRequest,\n context: CallContext\n ): Promise<ProcessBindingResponse> {\n if (!this.started) {\n throw new ServerError(Status.UNAVAILABLE, 'Service not started.')\n }\n\n const result = ProcessResult.fromPartial({})\n\n if (request.chainId.toLowerCase().startsWith('sui') && global.PROCESSOR_STATE.suiProcessors) {\n const processorPromises: Promise<void>[] = []\n for (const txn of request.transactions) {\n processorPromises.push(\n new Promise((resolve, _) => {\n for (const processor of global.PROCESSOR_STATE.suiProcessors) {\n const res = processor.handleTransaction(\n JSON.parse(new TextDecoder().decode(txn.raw)),\n txn.slot ?? Long.fromNumber(0)\n )\n if (res) {\n res.gauges.forEach((g) => result.gauges.push(g))\n res.counters.forEach((c) => result.counters.push(c))\n res.logs.forEach((l) => result.logs.push(l))\n }\n }\n resolve()\n })\n )\n }\n await Promise.all(processorPromises)\n }\n\n if (request.chainId.toLowerCase().startsWith('apt') && global.PROCESSOR_STATE.aptosProcessors) {\n const processorPromises: Promise<void>[] = []\n for (const txn of request.transactions) {\n processorPromises.push(\n new Promise((resolve, _) => {\n for (const processor of global.PROCESSOR_STATE.aptosProcessors) {\n if (processor.address === txn.programAccountId!) {\n const res = processor.handleTransaction(\n JSON.parse(new TextDecoder().decode(txn.raw)),\n txn.slot ?? Long.fromNumber(0)\n )\n if (res) {\n res.gauges.forEach((g) => result.gauges.push(g))\n res.counters.forEach((c) => result.counters.push(c))\n res.logs.forEach((l) => result.logs.push(l))\n }\n }\n }\n resolve()\n })\n )\n }\n await Promise.all(processorPromises)\n }\n\n recordRuntimeInfo(result, HandlerType.TRANSACTION)\n return {\n result,\n configUpdated: false,\n }\n }\n\n async processInstructions(\n request: ProcessInstructionsRequest,\n context: CallContext\n ): Promise<ProcessBindingResponse> {\n if (!this.started) {\n throw new ServerError(Status.UNAVAILABLE, 'Service not started.')\n }\n\n const result = ProcessResult.fromPartial({})\n\n // Only have instruction handlers for solana processors\n if (global.PROCESSOR_STATE.solanaProcessors) {\n const processorPromises: Promise<void>[] = []\n for (const instruction of request.instructions) {\n if (!instruction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'instruction cannot be null')\n }\n\n processorPromises.push(\n new Promise((resolve, _) => {\n for (const processor of global.PROCESSOR_STATE.solanaProcessors) {\n if (processor.address === instruction.programAccountId) {\n let res: ProcessResult | null\n if (instruction.parsed) {\n res = processor.handleInstruction(\n JSON.parse(new TextDecoder().decode(instruction.parsed)),\n instruction.slot\n )\n } else if (instruction.instructionData) {\n res = processor.handleInstruction(instruction.instructionData, instruction.slot)\n } else {\n continue\n }\n if (res) {\n res.gauges.forEach((g) => result.gauges.push(g))\n res.counters.forEach((c) => result.counters.push(c))\n res.logs.forEach((l) => result.logs.push(l))\n } else {\n console.warn(\n `Failed to decode the instruction: ${instruction.instructionData} with slot: ${instruction.slot}`\n )\n }\n }\n }\n resolve()\n })\n )\n }\n\n await Promise.all(processorPromises)\n }\n\n recordRuntimeInfo(result, HandlerType.INSTRUCTION)\n return {\n result,\n configUpdated: false,\n }\n }\n\n async processBlocks(request: ProcessBlocksRequest, context: CallContext): Promise<ProcessBindingResponse> {\n if (!this.started) {\n throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')\n }\n\n const promises = request.blockBindings.map((binding) => this.processBlock(binding))\n const result = mergeProcessResults(await Promise.all(promises))\n\n recordRuntimeInfo(result, HandlerType.BLOCK)\n return {\n result,\n configUpdated: false,\n }\n }\n\n async processBlock(binding: BlockBinding): Promise<ProcessResult> {\n if (!binding.block) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Block can't be empty\")\n }\n const jsonString = Utf8ArrayToStr(binding.block.raw)\n\n const block: Block = JSON.parse(jsonString)\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n const promise = this.blockHandlers[handlerId](block).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing block: ' + block.number + '\\n' + errorString(e))\n })\n promises.push(promise)\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processTraces(request: ProcessBindingsRequest, context: CallContext): Promise<ProcessBindingResponse> {\n if (!this.started) {\n throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')\n }\n\n const promises = request.bindings.map((binding) => this.processTrace(binding))\n const result = mergeProcessResults(await Promise.all(promises))\n\n recordRuntimeInfo(result, HandlerType.ETH_TRACE)\n return {\n result,\n configUpdated: false,\n }\n }\n\n async processTrace(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Trace can't be empty\")\n }\n const jsonString = Utf8ArrayToStr(binding.data.raw)\n const trace: Trace = JSON.parse(jsonString)\n\n return this.traceHandlers[binding.handlerId](trace).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing trace: ' + jsonString + '\\n' + errorString(e))\n })\n }\n\n async processAptosEvent(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n const jsonString = Utf8ArrayToStr(binding.data.raw)\n const event = JSON.parse(jsonString)\n // only support aptos event for now\n const result = await this.aptosEventHandlers[binding.handlerId](event).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing event: ' + jsonString + '\\n' + errorString(e))\n })\n recordRuntimeInfo(result, HandlerType.APT_EVENT)\n return result\n }\n\n async processAptosCall(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n const jsonString = Utf8ArrayToStr(binding.data.raw)\n const call = JSON.parse(jsonString)\n // only support aptos call for now\n const result = await this.aptosCallHandlers[binding.handlerId](call).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing call: ' + jsonString + '\\n' + errorString(e))\n })\n recordRuntimeInfo(result, HandlerType.APT_CALL)\n return result\n }\n}\n\n// https://ourcodeworld.com/articles/read/164/how-to-convert-an-uint8array-to-string-in-javascript\n/* eslint-disable */\nfunction Utf8ArrayToStr(array: Uint8Array) {\n let out, i, len, c\n let char2, char3\n\n out = ''\n len = array.length\n i = 0\n while (i < len) {\n c = array[i++]\n switch (c >> 4) {\n case 0:\n case 1:\n case 2:\n case 3:\n case 4:\n case 5:\n case 6:\n case 7:\n // 0xxxxxxx\n out += String.fromCharCode(c)\n break\n case 12:\n case 13:\n // 110x xxxx 10xx xxxx\n char2 = array[i++]\n out += String.fromCharCode(((c & 0x1f) << 6) | (char2 & 0x3f))\n break\n case 14:\n // 1110 xxxx 10xx xxxx 10xx xxxx\n char2 = array[i++]\n char3 = array[i++]\n out += String.fromCharCode(((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0))\n break\n }\n }\n\n return out\n}\n\nfunction mergeProcessResults(results: ProcessResult[]): ProcessResult {\n const res = ProcessResult.fromPartial({})\n\n for (const r of results) {\n res.counters = res.counters.concat(r.counters)\n res.gauges = res.gauges.concat(r.gauges)\n res.logs = res.logs.concat(r.logs)\n }\n return res\n}\n\nfunction recordRuntimeInfo(results: ProcessResult, handlerType: HandlerType) {\n results.gauges.forEach((e) => {\n e.runtimeInfo = {\n from: handlerType,\n }\n })\n\n results.counters.forEach((e) => {\n e.runtimeInfo = {\n from: handlerType,\n }\n })\n\n results.logs.forEach((e) => {\n e.runtimeInfo = {\n from: handlerType,\n }\n })\n}\n\nfunction errorString(e: Error): string {\n return e.stack || e.message\n}\n"]}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { BlockBinding, ContractConfig,
|
|
1
|
+
import { BlockBinding, ContractConfig, DataBinding, ProcessBindingResponse, ProcessBindingsRequest, ProcessBlocksRequest, ProcessConfigRequest, ProcessConfigResponse, ProcessInstructionsRequest, ProcessorServiceImpl, ProcessorServiceImplementation, ProcessTransactionsRequest, StartRequest, Trace } from '@sentio/sdk';
|
|
2
2
|
import { CallContext } from 'nice-grpc-common';
|
|
3
3
|
import { Empty } from '../gen/google/protobuf/empty';
|
|
4
4
|
import { Block, Log } from '@ethersproject/abstract-provider';
|
|
5
5
|
import { Networkish } from '@ethersproject/providers';
|
|
6
|
-
import { Trace } from '@sentio/sdk';
|
|
7
6
|
export declare class TestProcessorServer implements ProcessorServiceImplementation {
|
|
8
7
|
service: ProcessorServiceImpl;
|
|
9
8
|
contractConfig: ContractConfig[];
|
|
@@ -11,24 +10,25 @@ export declare class TestProcessorServer implements ProcessorServiceImplementati
|
|
|
11
10
|
start(request?: StartRequest, context?: CallContext): Promise<Empty>;
|
|
12
11
|
stop(request: Empty, context?: CallContext): Promise<Empty>;
|
|
13
12
|
getConfig(request: ProcessConfigRequest, context?: CallContext): Promise<ProcessConfigResponse>;
|
|
14
|
-
processBlocks(request: ProcessBlocksRequest, context?: CallContext): Promise<
|
|
15
|
-
processInstructions(request: ProcessInstructionsRequest, context?: CallContext): Promise<
|
|
16
|
-
processLogs(request:
|
|
17
|
-
processTraces(request:
|
|
18
|
-
processTransactions(request: ProcessTransactionsRequest, context?: CallContext): Promise<
|
|
19
|
-
testTrace(trace: Trace, network?: Networkish): Promise<
|
|
20
|
-
testTraces(traces: Trace[], network?: Networkish): Promise<
|
|
21
|
-
buildTraceBinding(trace: Trace, network?: Networkish):
|
|
22
|
-
testLog(log: Log, network?: Networkish): Promise<
|
|
23
|
-
testLogs(logs: Log[], network?: Networkish): Promise<
|
|
24
|
-
buildLogBinding(log: Log, network?: Networkish):
|
|
13
|
+
processBlocks(request: ProcessBlocksRequest, context?: CallContext): Promise<ProcessBindingResponse>;
|
|
14
|
+
processInstructions(request: ProcessInstructionsRequest, context?: CallContext): Promise<ProcessBindingResponse>;
|
|
15
|
+
processLogs(request: ProcessBindingsRequest, context?: CallContext): Promise<ProcessBindingResponse>;
|
|
16
|
+
processTraces(request: ProcessBindingsRequest, context?: CallContext): Promise<ProcessBindingResponse>;
|
|
17
|
+
processTransactions(request: ProcessTransactionsRequest, context?: CallContext): Promise<ProcessBindingResponse>;
|
|
18
|
+
testTrace(trace: Trace, network?: Networkish): Promise<ProcessBindingResponse>;
|
|
19
|
+
testTraces(traces: Trace[], network?: Networkish): Promise<ProcessBindingResponse>;
|
|
20
|
+
buildTraceBinding(trace: Trace, network?: Networkish): DataBinding | undefined;
|
|
21
|
+
testLog(log: Log, network?: Networkish): Promise<ProcessBindingResponse>;
|
|
22
|
+
testLogs(logs: Log[], network?: Networkish): Promise<ProcessBindingResponse>;
|
|
23
|
+
buildLogBinding(log: Log, network?: Networkish): DataBinding | undefined;
|
|
25
24
|
testBlock(block: Partial<Block> & {
|
|
26
25
|
number: number;
|
|
27
|
-
}, network?: Networkish): Promise<
|
|
26
|
+
}, network?: Networkish): Promise<ProcessBindingResponse>;
|
|
28
27
|
testBlocks(blocks: Partial<Block> & {
|
|
29
28
|
number: number;
|
|
30
|
-
}[], network?: Networkish): Promise<
|
|
29
|
+
}[], network?: Networkish): Promise<ProcessBindingResponse>;
|
|
31
30
|
buildBlockBinding(block: Partial<Block> & {
|
|
32
31
|
number: number;
|
|
33
32
|
}, network?: Networkish): BlockBinding;
|
|
33
|
+
processBindings(request: ProcessBindingsRequest, context: CallContext): Promise<ProcessBindingResponse>;
|
|
34
34
|
}
|
|
@@ -67,7 +67,7 @@ class TestProcessorServer {
|
|
|
67
67
|
bindings.push(binding);
|
|
68
68
|
}
|
|
69
69
|
return this.processTraces({
|
|
70
|
-
|
|
70
|
+
bindings: bindings,
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
buildTraceBinding(trace, network = 1) {
|
|
@@ -85,10 +85,11 @@ class TestProcessorServer {
|
|
|
85
85
|
for (const config of contract.traceConfigs) {
|
|
86
86
|
if (config.signature == signature) {
|
|
87
87
|
return {
|
|
88
|
-
|
|
88
|
+
data: {
|
|
89
89
|
raw: toBytes(trace),
|
|
90
90
|
},
|
|
91
91
|
handlerId: config.handlerId,
|
|
92
|
+
handlerType: sdk_1.HandlerType.ETH_TRACE,
|
|
92
93
|
};
|
|
93
94
|
}
|
|
94
95
|
}
|
|
@@ -108,7 +109,7 @@ class TestProcessorServer {
|
|
|
108
109
|
bindings.push(binding);
|
|
109
110
|
}
|
|
110
111
|
return this.processLogs({
|
|
111
|
-
|
|
112
|
+
bindings: bindings,
|
|
112
113
|
});
|
|
113
114
|
}
|
|
114
115
|
buildLogBinding(log, network = 1) {
|
|
@@ -141,10 +142,11 @@ class TestProcessorServer {
|
|
|
141
142
|
}
|
|
142
143
|
if (match) {
|
|
143
144
|
return {
|
|
144
|
-
|
|
145
|
+
data: {
|
|
145
146
|
raw: toBytes(log),
|
|
146
147
|
},
|
|
147
148
|
handlerId: config.handlerId,
|
|
149
|
+
handlerType: sdk_1.HandlerType.ETH_LOG,
|
|
148
150
|
};
|
|
149
151
|
}
|
|
150
152
|
}
|
|
@@ -192,6 +194,9 @@ class TestProcessorServer {
|
|
|
192
194
|
}
|
|
193
195
|
return binding;
|
|
194
196
|
}
|
|
197
|
+
processBindings(request, context) {
|
|
198
|
+
return this.service.processBindings(request, context);
|
|
199
|
+
}
|
|
195
200
|
}
|
|
196
201
|
exports.TestProcessorServer = TestProcessorServer;
|
|
197
202
|
function toBytes(obj) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-processor-server.js","sourceRoot":"","sources":["../../src/testing/test-processor-server.ts"],"names":[],"mappings":";;;;;;AAAA,qCAsBoB;AAIpB,0CAA0C;AAE1C,gDAAuB;AACvB,wDAAiE;AAGjE,MAAM,YAAY,GAA6B,EAAE,CAAA;AAEjD,SAAS,SAAS;IAChB,MAAM,CAAC,eAAe,GAAG,IAAI,oBAAc,EAAE,CAAA;AAC/C,CAAC;AAED,MAAa,mBAAmB;IAC9B,OAAO,CAAsB;IAC7B,cAAc,CAAkB;IAEhC,YAAY,MAAkB,EAAE,gBAAwC,EAAE;QACxE,SAAS,EAAE,CAAA;QAEX,IAAI,CAAC,OAAO,GAAG,I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rD,IAAI,eAAe,GAAG,QAAQ,CAAC,UAAU,EAAE;gBACzC,SAAQ;aACT;YACD,IAAI,QAAQ,CAAC,QAAQ,KAAK,cAAI,CAAC,IAAI,IAAI,eAAe,IAAI,QAAQ,CAAC,QAAQ,EAAE;gBAC3E,SAAQ;aACT;YAED,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,YAAY,EAAE;gBAC1C,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;aAC1C;SACF;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;CACF;AAlND,kDAkNC;AAED,SAAS,OAAO,CAAC,GAAQ;IACvB,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;IACtC,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;IAC7C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC1C,GAAG,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;KAClC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC","sourcesContent":["import {\n BlockBinding,\n ContractConfig,\n LogBinding,\n ProcessBlocksRequest,\n ProcessBlocksResponse,\n ProcessConfigRequest,\n ProcessConfigResponse,\n ProcessInstructionsRequest,\n ProcessInstructionsResponse,\n ProcessLogsRequest,\n ProcessLogsResponse,\n ProcessorServiceImpl,\n ProcessorServiceImplementation,\n ProcessorState,\n ProcessTracesRequest,\n ProcessTracesResponse,\n ProcessTransactionsRequest,\n ProcessTransactionsResponse,\n setProvider,\n StartRequest,\n TraceBinding,\n} from '@sentio/sdk'\nimport { CallContext } from 'nice-grpc-common'\nimport { Empty } from '../gen/google/protobuf/empty'\nimport { ChainConfig } from '../chain-config'\nimport { CHAIN_MAP } from '../utils/chain'\nimport { Block, Log } from '@ethersproject/abstract-provider'\nimport Long from 'long'\nimport { getNetwork, Networkish } from '@ethersproject/providers'\nimport { Trace } from '@sentio/sdk'\n\nconst TEST_CONTEXT: CallContext = <CallContext>{}\n\nfunction cleanTest() {\n global.PROCESSOR_STATE = new ProcessorState()\n}\n\nexport class TestProcessorServer implements ProcessorServiceImplementation {\n service: ProcessorServiceImpl\n contractConfig: ContractConfig[]\n\n constructor(loader: () => void, httpEndpoints: Record<string, string> = {}) {\n cleanTest()\n\n this.service = new ProcessorServiceImpl(loader)\n const dummyConfig: Record<string, ChainConfig> = {}\n\n for (const k in CHAIN_MAP) {\n const http = httpEndpoints[k] || ''\n dummyConfig[k] = {\n ChainID: k,\n Https: [http],\n }\n }\n\n setProvider(dummyConfig)\n }\n\n async start(request: StartRequest = { templateInstances: [] }, context = TEST_CONTEXT): Promise<Empty> {\n const res = await this.service.start(request, context)\n this.contractConfig = (await this.getConfig({})).contractConfigs\n return res\n }\n\n stop(request: Empty, context = TEST_CONTEXT): Promise<Empty> {\n return this.service.stop(request, context)\n }\n\n getConfig(request: ProcessConfigRequest, context = TEST_CONTEXT): Promise<ProcessConfigResponse> {\n return this.service.getConfig(request, context)\n }\n\n processBlocks(request: ProcessBlocksRequest, context = TEST_CONTEXT): Promise<ProcessBlocksResponse> {\n return this.service.processBlocks(request, context)\n }\n\n processInstructions(\n request: ProcessInstructionsRequest,\n context = TEST_CONTEXT\n ): Promise<ProcessInstructionsResponse> {\n return this.service.processInstructions(request, context)\n }\n\n processLogs(request: ProcessLogsRequest, context = TEST_CONTEXT): Promise<ProcessLogsResponse> {\n return this.service.processLogs(request, context)\n }\n\n processTraces(request: ProcessTracesRequest, context: CallContext = TEST_CONTEXT): Promise<ProcessTracesResponse> {\n return this.service.processTraces(request, context)\n }\n\n processTransactions(\n request: ProcessTransactionsRequest,\n context = TEST_CONTEXT\n ): Promise<ProcessTransactionsResponse> {\n return this.service.processTransactions(request, context)\n }\n\n testTrace(trace: Trace, network: Networkish = 1): Promise<ProcessTracesResponse> {\n return this.testTraces([trace], network)\n }\n\n testTraces(traces: Trace[], network: Networkish = 1): Promise<ProcessTracesResponse> {\n const bindings = []\n for (const trace of traces) {\n const binding = this.buildTraceBinding(trace, network)\n if (!binding) {\n throw Error('Invalid test trace: ' + JSON.stringify(trace))\n }\n bindings.push(binding)\n }\n return this.processTraces({\n traceBindings: bindings,\n })\n }\n\n buildTraceBinding(trace: Trace, network: Networkish = 1): TraceBinding | undefined {\n if (trace.type !== 'call' || !trace.action.input) {\n throw Error('Invalid test trace: ' + JSON.stringify(trace))\n }\n const signature = trace.action.input.slice(0, 10)\n\n for (const contract of this.contractConfig) {\n if (contract.contract?.chainId !== getNetwork(network).chainId.toString()) {\n continue\n }\n if (trace.action.to?.toLowerCase() !== contract.contract?.address.toLowerCase()) {\n continue\n }\n for (const config of contract.traceConfigs) {\n if (config.signature == signature) {\n return {\n trace: {\n raw: toBytes(trace),\n },\n handlerId: config.handlerId,\n }\n }\n }\n }\n return undefined\n }\n\n testLog(log: Log, network: Networkish = 1): Promise<ProcessLogsResponse> {\n return this.testLogs([log], network)\n }\n\n testLogs(logs: Log[], network: Networkish = 1): Promise<ProcessLogsResponse> {\n const bindings = []\n for (const log of logs) {\n const binding = this.buildLogBinding(log, network)\n if (!binding) {\n throw Error('Invalid test log: ' + JSON.stringify(log))\n }\n bindings.push(binding)\n }\n return this.processLogs({\n logBindings: bindings,\n })\n }\n\n buildLogBinding(log: Log, network: Networkish = 1): LogBinding | undefined {\n for (const contract of this.contractConfig) {\n if (contract.contract?.chainId !== getNetwork(network).chainId.toString()) {\n continue\n }\n if (log.address.toLowerCase() !== contract.contract?.address.toLowerCase()) {\n continue\n }\n for (const config of contract.logConfigs) {\n for (const filter of config.filters) {\n // if (filter.topics.length != log.topics.length) {\n // continue\n // }\n\n let match = true\n for (const topicIdx in filter.topics) {\n const logTopic = log.topics[topicIdx]\n const possibleTopic = filter.topics[topicIdx].hashes\n if (possibleTopic.length === 0) {\n // match all\n continue\n }\n if (possibleTopic.find((e) => e.toLowerCase() === logTopic.toLowerCase())) {\n // find one\n continue\n }\n match = false\n break\n }\n if (match) {\n return {\n log: {\n raw: toBytes(log),\n },\n handlerId: config.handlerId,\n }\n }\n }\n }\n }\n return undefined\n }\n\n testBlock(block: Partial<Block> & { number: number }, network: Networkish = 1): Promise<ProcessBlocksResponse> {\n return this.testBlocks([block], network)\n }\n\n testBlocks(blocks: Partial<Block> & { number: number }[], network: Networkish = 1) {\n const bindings = []\n for (const block of blocks) {\n const binding = this.buildBlockBinding(block, network)\n if (!binding) {\n throw Error('Invalid test block: ' + JSON.stringify(block))\n }\n bindings.push(binding)\n }\n return this.processBlocks({\n blockBindings: bindings,\n })\n }\n\n buildBlockBinding(block: Partial<Block> & { number: number }, network: Networkish = 1): BlockBinding {\n const binding: BlockBinding = {\n block: {\n raw: toBytes(block),\n },\n handlerIds: [],\n }\n for (const contract of this.contractConfig) {\n if (contract.contract?.chainId !== getNetwork(network).chainId.toString()) {\n continue\n }\n const longBlockNumber = Long.fromNumber(block.number)\n if (longBlockNumber < contract.startBlock) {\n continue\n }\n if (contract.endBlock !== Long.ZERO && longBlockNumber >= contract.endBlock) {\n continue\n }\n\n for (const config of contract.blockConfigs) {\n binding.handlerIds.push(config.handlerId)\n }\n }\n return binding\n }\n}\n\nfunction toBytes(obj: any): Uint8Array {\n const logJsonStr = JSON.stringify(obj)\n const raw = new Uint8Array(logJsonStr.length)\n for (let i = 0; i < logJsonStr.length; i++) {\n raw[i] = logJsonStr.charCodeAt(i)\n }\n return raw\n}\n"]}
|
|
1
|
+
{"version":3,"file":"test-processor-server.js","sourceRoot":"","sources":["../../src/testing/test-processor-server.ts"],"names":[],"mappings":";;;;;;AAAA,qCAkBoB;AAIpB,0CAA0C;AAE1C,gDAAuB;AACvB,wDAAiE;AAEjE,MAAM,YAAY,GAA6B,EAAE,CAAA;AAEjD,SAAS,SAAS;IAChB,MAAM,CAAC,eAAe,GAAG,IAAI,oBAAc,EAAE,CAAA;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ProcessBlocksRequest,\n ProcessConfigRequest,\n ProcessConfigResponse,\n ProcessInstructionsRequest,\n ProcessorServiceImpl,\n ProcessorServiceImplementation,\n ProcessorState,\n ProcessTransactionsRequest,\n setProvider,\n StartRequest,\n Trace,\n} from '@sentio/sdk'\nimport { CallContext } from 'nice-grpc-common'\nimport { Empty } from '../gen/google/protobuf/empty'\nimport { ChainConfig } from '../chain-config'\nimport { CHAIN_MAP } from '../utils/chain'\nimport { Block, Log } from '@ethersproject/abstract-provider'\nimport Long from 'long'\nimport { getNetwork, Networkish } from '@ethersproject/providers'\n\nconst TEST_CONTEXT: CallContext = <CallContext>{}\n\nfunction cleanTest() {\n global.PROCESSOR_STATE = new ProcessorState()\n}\n\nexport class TestProcessorServer implements ProcessorServiceImplementation {\n service: ProcessorServiceImpl\n contractConfig: ContractConfig[]\n\n constructor(loader: () => void, httpEndpoints: Record<string, string> = {}) {\n cleanTest()\n\n this.service = new ProcessorServiceImpl(loader)\n const dummyConfig: Record<string, ChainConfig> = {}\n\n for (const k in CHAIN_MAP) {\n const http = httpEndpoints[k] || ''\n dummyConfig[k] = {\n ChainID: k,\n Https: [http],\n }\n }\n\n setProvider(dummyConfig)\n }\n\n async start(request: StartRequest = { templateInstances: [] }, context = TEST_CONTEXT): Promise<Empty> {\n const res = await this.service.start(request, context)\n this.contractConfig = (await this.getConfig({})).contractConfigs\n return res\n }\n\n stop(request: Empty, context = TEST_CONTEXT): Promise<Empty> {\n return this.service.stop(request, context)\n }\n\n getConfig(request: ProcessConfigRequest, context = TEST_CONTEXT): Promise<ProcessConfigResponse> {\n return this.service.getConfig(request, context)\n }\n\n processBlocks(request: ProcessBlocksRequest, context = TEST_CONTEXT): Promise<ProcessBindingResponse> {\n return this.service.processBlocks(request, context)\n }\n\n processInstructions(request: ProcessInstructionsRequest, context = TEST_CONTEXT): Promise<ProcessBindingResponse> {\n return this.service.processInstructions(request, context)\n }\n\n processLogs(request: ProcessBindingsRequest, context = TEST_CONTEXT): Promise<ProcessBindingResponse> {\n return this.service.processLogs(request, context)\n }\n\n processTraces(request: ProcessBindingsRequest, context: CallContext = TEST_CONTEXT): Promise<ProcessBindingResponse> {\n return this.service.processTraces(request, context)\n }\n\n processTransactions(request: ProcessTransactionsRequest, context = TEST_CONTEXT): Promise<ProcessBindingResponse> {\n return this.service.processTransactions(request, context)\n }\n\n testTrace(trace: Trace, network: Networkish = 1): Promise<ProcessBindingResponse> {\n return this.testTraces([trace], network)\n }\n\n testTraces(traces: Trace[], network: Networkish = 1): Promise<ProcessBindingResponse> {\n const bindings = []\n for (const trace of traces) {\n const binding = this.buildTraceBinding(trace, network)\n if (!binding) {\n throw Error('Invalid test trace: ' + JSON.stringify(trace))\n }\n bindings.push(binding)\n }\n return this.processTraces({\n bindings: bindings,\n })\n }\n\n buildTraceBinding(trace: Trace, network: Networkish = 1): DataBinding | undefined {\n if (trace.type !== 'call' || !trace.action.input) {\n throw Error('Invalid test trace: ' + JSON.stringify(trace))\n }\n const signature = trace.action.input.slice(0, 10)\n\n for (const contract of this.contractConfig) {\n if (contract.contract?.chainId !== getNetwork(network).chainId.toString()) {\n continue\n }\n if (trace.action.to?.toLowerCase() !== contract.contract?.address.toLowerCase()) {\n continue\n }\n for (const config of contract.traceConfigs) {\n if (config.signature == signature) {\n return {\n data: {\n raw: toBytes(trace),\n },\n handlerId: config.handlerId,\n handlerType: HandlerType.ETH_TRACE,\n }\n }\n }\n }\n return undefined\n }\n\n testLog(log: Log, network: Networkish = 1): Promise<ProcessBindingResponse> {\n return this.testLogs([log], network)\n }\n\n testLogs(logs: Log[], network: Networkish = 1): Promise<ProcessBindingResponse> {\n const bindings = []\n for (const log of logs) {\n const binding = this.buildLogBinding(log, network)\n if (!binding) {\n throw Error('Invalid test log: ' + JSON.stringify(log))\n }\n bindings.push(binding)\n }\n return this.processLogs({\n bindings: bindings,\n })\n }\n\n buildLogBinding(log: Log, network: Networkish = 1): DataBinding | undefined {\n for (const contract of this.contractConfig) {\n if (contract.contract?.chainId !== getNetwork(network).chainId.toString()) {\n continue\n }\n if (log.address.toLowerCase() !== contract.contract?.address.toLowerCase()) {\n continue\n }\n for (const config of contract.logConfigs) {\n for (const filter of config.filters) {\n // if (filter.topics.length != log.topics.length) {\n // continue\n // }\n\n let match = true\n for (const topicIdx in filter.topics) {\n const logTopic = log.topics[topicIdx]\n const possibleTopic = filter.topics[topicIdx].hashes\n if (possibleTopic.length === 0) {\n // match all\n continue\n }\n if (possibleTopic.find((e) => e.toLowerCase() === logTopic.toLowerCase())) {\n // find one\n continue\n }\n match = false\n break\n }\n if (match) {\n return {\n data: {\n raw: toBytes(log),\n },\n handlerId: config.handlerId,\n handlerType: HandlerType.ETH_LOG,\n }\n }\n }\n }\n }\n return undefined\n }\n\n testBlock(block: Partial<Block> & { number: number }, network: Networkish = 1): Promise<ProcessBindingResponse> {\n return this.testBlocks([block], network)\n }\n\n testBlocks(blocks: Partial<Block> & { number: number }[], network: Networkish = 1) {\n const bindings = []\n for (const block of blocks) {\n const binding = this.buildBlockBinding(block, network)\n if (!binding) {\n throw Error('Invalid test block: ' + JSON.stringify(block))\n }\n bindings.push(binding)\n }\n return this.processBlocks({\n blockBindings: bindings,\n })\n }\n\n buildBlockBinding(block: Partial<Block> & { number: number }, network: Networkish = 1): BlockBinding {\n const binding: BlockBinding = {\n block: {\n raw: toBytes(block),\n },\n handlerIds: [],\n }\n for (const contract of this.contractConfig) {\n if (contract.contract?.chainId !== getNetwork(network).chainId.toString()) {\n continue\n }\n const longBlockNumber = Long.fromNumber(block.number)\n if (longBlockNumber < contract.startBlock) {\n continue\n }\n if (contract.endBlock !== Long.ZERO && longBlockNumber >= contract.endBlock) {\n continue\n }\n\n for (const config of contract.blockConfigs) {\n binding.handlerIds.push(config.handlerId)\n }\n }\n return binding\n }\n\n processBindings(request: ProcessBindingsRequest, context: CallContext): Promise<ProcessBindingResponse> {\n return this.service.processBindings(request, context)\n }\n}\n\nfunction toBytes(obj: any): Uint8Array {\n const logJsonStr = JSON.stringify(obj)\n const raw = new Uint8Array(logJsonStr.length)\n for (let i = 0; i < logJsonStr.length; i++) {\n raw[i] = logJsonStr.charCodeAt(i)\n }\n return raw\n}\n"]}
|