@sentio/runtime 2.40.0-rc.4 → 2.40.0-rc.5

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/.eslintrc.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": [
3
+ "../../.eslintrc.json"
4
+ ]
5
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "1": {
3
+ "ChainServer": "http://localhost:8645"
4
+ },
5
+ "25": {
6
+ "ChainID": 25,
7
+ "ChainServer": "http://localhost:8660"
8
+ }
9
+ }
@@ -48583,9 +48583,75 @@ var ProcessResult = {
48583
48583
  }
48584
48584
  };
48585
48585
  function createBaseEthCallParam() {
48586
- return { chainId: "", address: "", function: "", signature: "", args: [] };
48586
+ return { context: void 0, calldata: "" };
48587
48587
  }
48588
48588
  var EthCallParam = {
48589
+ encode(message, writer = import_minimal5.default.Writer.create()) {
48590
+ if (message.context !== void 0) {
48591
+ EthCallContext.encode(message.context, writer.uint32(10).fork()).ldelim();
48592
+ }
48593
+ if (message.calldata !== "") {
48594
+ writer.uint32(18).string(message.calldata);
48595
+ }
48596
+ return writer;
48597
+ },
48598
+ decode(input, length) {
48599
+ const reader = input instanceof import_minimal5.default.Reader ? input : import_minimal5.default.Reader.create(input);
48600
+ let end = length === void 0 ? reader.len : reader.pos + length;
48601
+ const message = createBaseEthCallParam();
48602
+ while (reader.pos < end) {
48603
+ const tag = reader.uint32();
48604
+ switch (tag >>> 3) {
48605
+ case 1:
48606
+ if (tag !== 10) {
48607
+ break;
48608
+ }
48609
+ message.context = EthCallContext.decode(reader, reader.uint32());
48610
+ continue;
48611
+ case 2:
48612
+ if (tag !== 18) {
48613
+ break;
48614
+ }
48615
+ message.calldata = reader.string();
48616
+ continue;
48617
+ }
48618
+ if ((tag & 7) === 4 || tag === 0) {
48619
+ break;
48620
+ }
48621
+ reader.skipType(tag & 7);
48622
+ }
48623
+ return message;
48624
+ },
48625
+ fromJSON(object2) {
48626
+ return {
48627
+ context: isSet3(object2.context) ? EthCallContext.fromJSON(object2.context) : void 0,
48628
+ calldata: isSet3(object2.calldata) ? globalThis.String(object2.calldata) : ""
48629
+ };
48630
+ },
48631
+ toJSON(message) {
48632
+ const obj = {};
48633
+ if (message.context !== void 0) {
48634
+ obj.context = EthCallContext.toJSON(message.context);
48635
+ }
48636
+ if (message.calldata !== "") {
48637
+ obj.calldata = message.calldata;
48638
+ }
48639
+ return obj;
48640
+ },
48641
+ create(base) {
48642
+ return EthCallParam.fromPartial(base ?? {});
48643
+ },
48644
+ fromPartial(object2) {
48645
+ const message = createBaseEthCallParam();
48646
+ message.context = object2.context !== void 0 && object2.context !== null ? EthCallContext.fromPartial(object2.context) : void 0;
48647
+ message.calldata = object2.calldata ?? "";
48648
+ return message;
48649
+ }
48650
+ };
48651
+ function createBaseEthCallContext() {
48652
+ return { chainId: "", address: "", blockTag: "" };
48653
+ }
48654
+ var EthCallContext = {
48589
48655
  encode(message, writer = import_minimal5.default.Writer.create()) {
48590
48656
  if (message.chainId !== "") {
48591
48657
  writer.uint32(10).string(message.chainId);
@@ -48593,21 +48659,15 @@ var EthCallParam = {
48593
48659
  if (message.address !== "") {
48594
48660
  writer.uint32(18).string(message.address);
48595
48661
  }
48596
- if (message.function !== "") {
48597
- writer.uint32(26).string(message.function);
48598
- }
48599
- if (message.signature !== "") {
48600
- writer.uint32(34).string(message.signature);
48601
- }
48602
- for (const v of message.args) {
48603
- Value.encode(Value.wrap(v), writer.uint32(42).fork()).ldelim();
48662
+ if (message.blockTag !== "") {
48663
+ writer.uint32(26).string(message.blockTag);
48604
48664
  }
48605
48665
  return writer;
48606
48666
  },
48607
48667
  decode(input, length) {
48608
48668
  const reader = input instanceof import_minimal5.default.Reader ? input : import_minimal5.default.Reader.create(input);
48609
48669
  let end = length === void 0 ? reader.len : reader.pos + length;
48610
- const message = createBaseEthCallParam();
48670
+ const message = createBaseEthCallContext();
48611
48671
  while (reader.pos < end) {
48612
48672
  const tag = reader.uint32();
48613
48673
  switch (tag >>> 3) {
@@ -48627,19 +48687,7 @@ var EthCallParam = {
48627
48687
  if (tag !== 26) {
48628
48688
  break;
48629
48689
  }
48630
- message.function = reader.string();
48631
- continue;
48632
- case 4:
48633
- if (tag !== 34) {
48634
- break;
48635
- }
48636
- message.signature = reader.string();
48637
- continue;
48638
- case 5:
48639
- if (tag !== 42) {
48640
- break;
48641
- }
48642
- message.args.push(Value.unwrap(Value.decode(reader, reader.uint32())));
48690
+ message.blockTag = reader.string();
48643
48691
  continue;
48644
48692
  }
48645
48693
  if ((tag & 7) === 4 || tag === 0) {
@@ -48653,9 +48701,7 @@ var EthCallParam = {
48653
48701
  return {
48654
48702
  chainId: isSet3(object2.chainId) ? globalThis.String(object2.chainId) : "",
48655
48703
  address: isSet3(object2.address) ? globalThis.String(object2.address) : "",
48656
- function: isSet3(object2.function) ? globalThis.String(object2.function) : "",
48657
- signature: isSet3(object2.signature) ? globalThis.String(object2.signature) : "",
48658
- args: globalThis.Array.isArray(object2?.args) ? [...object2.args] : []
48704
+ blockTag: isSet3(object2.blockTag) ? globalThis.String(object2.blockTag) : ""
48659
48705
  };
48660
48706
  },
48661
48707
  toJSON(message) {
@@ -48666,27 +48712,19 @@ var EthCallParam = {
48666
48712
  if (message.address !== "") {
48667
48713
  obj.address = message.address;
48668
48714
  }
48669
- if (message.function !== "") {
48670
- obj.function = message.function;
48671
- }
48672
- if (message.signature !== "") {
48673
- obj.signature = message.signature;
48674
- }
48675
- if (message.args?.length) {
48676
- obj.args = message.args;
48715
+ if (message.blockTag !== "") {
48716
+ obj.blockTag = message.blockTag;
48677
48717
  }
48678
48718
  return obj;
48679
48719
  },
48680
48720
  create(base) {
48681
- return EthCallParam.fromPartial(base ?? {});
48721
+ return EthCallContext.fromPartial(base ?? {});
48682
48722
  },
48683
48723
  fromPartial(object2) {
48684
- const message = createBaseEthCallParam();
48724
+ const message = createBaseEthCallContext();
48685
48725
  message.chainId = object2.chainId ?? "";
48686
48726
  message.address = object2.address ?? "";
48687
- message.function = object2.function ?? "";
48688
- message.signature = object2.signature ?? "";
48689
- message.args = object2.args?.map((e) => e) || [];
48727
+ message.blockTag = object2.blockTag ?? "";
48690
48728
  return message;
48691
48729
  }
48692
48730
  };
@@ -59488,6 +59526,13 @@ function errorString(e) {
59488
59526
  return e.message + "\n" + e.stack;
59489
59527
  }
59490
59528
  var USER_PROCESSOR = "user_processor";
59529
+ function makeEthCallKey(param) {
59530
+ if (!param.context) {
59531
+ throw new Error("null context for eth call");
59532
+ }
59533
+ const { chainId, address, blockTag } = param.context;
59534
+ return `${chainId}|${address}|${blockTag}|${param.calldata}`;
59535
+ }
59491
59536
 
59492
59537
  // src/endpoints.ts
59493
59538
  var _Endpoints = class {
@@ -78383,6 +78428,7 @@ var ProcessorServiceImpl = class {
78383
78428
  // private processorConfig: ProcessConfigResponse
78384
78429
  loader;
78385
78430
  shutdownHandler;
78431
+ preprocessedEthCalls;
78386
78432
  constructor(loader, shutdownHandler) {
78387
78433
  this.loader = loader;
78388
78434
  this.shutdownHandler = shutdownHandler;
@@ -78443,7 +78489,7 @@ var ProcessorServiceImpl = class {
78443
78489
  };
78444
78490
  }
78445
78491
  async preprocessBindings(bindings, dbContext, options) {
78446
- console.log(`preprocessBindings start, bindings: ${bindings.length}`);
78492
+ console.debug(`preprocessBindings start, bindings: ${bindings.length}`);
78447
78493
  const promises = [];
78448
78494
  for (const binding of bindings) {
78449
78495
  promises.push(this.preprocessBinding(binding, dbContext, options));
@@ -78454,7 +78500,7 @@ var ProcessorServiceImpl = class {
78454
78500
  } catch (e) {
78455
78501
  throw e;
78456
78502
  }
78457
- console.log(
78503
+ console.debug(
78458
78504
  "ethCallParams: ",
78459
78505
  preprocessResults.map((r) => r.ethCallParams)
78460
78506
  );
@@ -78462,10 +78508,11 @@ var ProcessorServiceImpl = class {
78462
78508
  const providers2 = /* @__PURE__ */ new Map();
78463
78509
  for (const result of preprocessResults) {
78464
78510
  for (const param of result.ethCallParams) {
78465
- if (!providers2.has(param.chainId)) {
78466
- providers2.set(param.chainId, getProvider2(param.chainId));
78511
+ const { chainId, address, blockTag } = param.context;
78512
+ if (!providers2.has(chainId)) {
78513
+ providers2.set(chainId, getProvider2(chainId));
78467
78514
  }
78468
- const key = param.chainId + "|" + param.address;
78515
+ const key = [chainId, address, blockTag].join("|");
78469
78516
  if (!groupedRequests.has(key)) {
78470
78517
  groupedRequests.set(key, []);
78471
78518
  }
@@ -78475,15 +78522,15 @@ var ProcessorServiceImpl = class {
78475
78522
  const start = Date.now();
78476
78523
  const callPromises = [];
78477
78524
  for (const params of groupedRequests.values()) {
78478
- console.log(`chain: ${params[0].chainId}, address: ${params[0].address}, totalCalls: ${params.length}`);
78525
+ const { chainId, address, blockTag } = params[0].context;
78526
+ console.log(`chain: ${chainId}, address: ${address}, blockTag: ${blockTag}, totalCalls: ${params.length}`);
78479
78527
  for (const param of params) {
78480
- const frag = new Interface([param.signature]);
78481
- const calldata = frag.encodeFunctionData(param.function, param.args);
78482
78528
  callPromises.push(
78483
- providers2.get(param.chainId).call({
78484
- to: param.address,
78485
- data: calldata
78486
- }).then((ret) => [calldata, frag.decodeFunctionResult(param.function, ret).toArray()])
78529
+ providers2.get(chainId).call({
78530
+ to: address,
78531
+ data: param.calldata,
78532
+ blockTag
78533
+ }).then((result) => [makeEthCallKey(param), result])
78487
78534
  );
78488
78535
  }
78489
78536
  }
@@ -78563,11 +78610,9 @@ var ProcessorServiceImpl = class {
78563
78610
  }).catch((e) => {
78564
78611
  console.debug(e);
78565
78612
  dbContext.error(request.processId, e);
78566
- process_binding_error.add(1);
78567
78613
  }).finally(() => {
78568
78614
  const cost = Date.now() - start;
78569
78615
  console.debug("preprocessBinding", request.processId, " took", cost, "ms");
78570
- process_binding_time.add(cost);
78571
78616
  contexts.delete(request.processId);
78572
78617
  });
78573
78618
  }
@@ -78672,6 +78717,7 @@ export {
78672
78717
  mergeProcessResults,
78673
78718
  errorString,
78674
78719
  USER_PROCESSOR,
78720
+ makeEthCallKey,
78675
78721
  Endpoints,
78676
78722
  require_lib,
78677
78723
  require_lodash,
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _sentio_protos from '@sentio/protos';
2
- import { DeepPartial as DeepPartial$1, ProcessStreamResponse, DBResponse, DBRequest_DBUpsert, DBRequest, HandlerType, ProcessConfigResponse, StartRequest, DataBinding, PreparedData, ProcessResult, PreprocessResult, ProcessorServiceImplementation, ProcessConfigRequest, Empty, ProcessBindingsRequest, ProcessBindingResponse, ProcessStreamRequest, PreprocessStreamRequest, PreprocessStreamResponse } from '@sentio/protos';
2
+ import { DeepPartial as DeepPartial$1, ProcessStreamResponse, DBResponse, DBRequest_DBUpsert, DBRequest, HandlerType, ProcessConfigResponse, StartRequest, DataBinding, PreparedData, ProcessResult, PreprocessResult, EthCallParam, ProcessorServiceImplementation, ProcessConfigRequest, Empty, ProcessBindingsRequest, ProcessBindingResponse, ProcessStreamRequest, PreprocessStreamRequest, PreprocessStreamResponse } from '@sentio/protos';
3
3
  import { Subject } from 'rxjs';
4
4
  import { AsyncLocalStorage } from 'node:async_hooks';
5
5
  import { Required } from 'utility-types';
@@ -85,6 +85,7 @@ declare abstract class ListStateStorage<T> extends StateStorage<T[]> {
85
85
  declare function mergeProcessResults(results: ProcessResult[]): Required<ProcessResult, 'states'>;
86
86
  declare function errorString(e: Error): string;
87
87
  declare const USER_PROCESSOR = "user_processor";
88
+ declare function makeEthCallKey(param: EthCallParam): string;
88
89
 
89
90
  declare class Endpoints {
90
91
  static INSTANCE: Endpoints;
@@ -106,13 +107,14 @@ declare class ProcessorServiceImpl implements ProcessorServiceImplementation {
106
107
  unhandled: Error;
107
108
  private readonly loader;
108
109
  private readonly shutdownHandler?;
110
+ private readonly preprocessedEthCalls;
109
111
  constructor(loader: () => Promise<any>, shutdownHandler?: () => void);
110
112
  getConfig(request: ProcessConfigRequest, context: CallContext): Promise<ProcessConfigResponse>;
111
113
  start(request: StartRequest, context: CallContext): Promise<Empty>;
112
114
  stop(request: Empty, context: CallContext): Promise<Empty>;
113
115
  processBindings(request: ProcessBindingsRequest, options?: CallContext): Promise<ProcessBindingResponse>;
114
116
  preprocessBindings(bindings: DataBinding[], dbContext?: StoreContext, options?: CallContext): Promise<{
115
- [calldata: string]: any[];
117
+ [ethCallKey: string]: string;
116
118
  }>;
117
119
  preprocessBinding(request: DataBinding, dbContext?: StoreContext, options?: CallContext): Promise<PreprocessResult>;
118
120
  processBinding(request: DataBinding, preparedData: PreparedData | undefined, options?: CallContext): Promise<ProcessResult>;
@@ -366,4 +368,4 @@ interface GlobalConfig {
366
368
  }
367
369
  declare const GLOBAL_CONFIG: GlobalConfig;
368
370
 
369
- export { ChainConfig, Endpoints, GLOBAL_CONFIG, GlobalConfig, ListStateStorage, MapStateStorage, Plugin, PluginManager, ProcessorServiceImpl, State, StateStorage, StoreContext, USER_PROCESSOR, errorString, mergeProcessResults, timeoutError };
371
+ export { ChainConfig, Endpoints, GLOBAL_CONFIG, GlobalConfig, ListStateStorage, MapStateStorage, Plugin, PluginManager, ProcessorServiceImpl, State, StateStorage, StoreContext, USER_PROCESSOR, errorString, makeEthCallKey, mergeProcessResults, timeoutError };
package/lib/index.js CHANGED
@@ -9,9 +9,10 @@ import {
9
9
  USER_PROCESSOR,
10
10
  __publicField,
11
11
  errorString,
12
+ makeEthCallKey,
12
13
  mergeProcessResults,
13
14
  timeoutError
14
- } from "./chunk-FGIYODHE.js";
15
+ } from "./chunk-FFU5RYDX.js";
15
16
 
16
17
  // src/state.ts
17
18
  var _State = class {
@@ -87,6 +88,7 @@ export {
87
88
  StoreContext,
88
89
  USER_PROCESSOR,
89
90
  errorString,
91
+ makeEthCallKey,
90
92
  mergeProcessResults,
91
93
  timeoutError
92
94
  };
File without changes
@@ -40,7 +40,7 @@ import {
40
40
  require_minimal,
41
41
  require_src,
42
42
  trace
43
- } from "./chunk-FGIYODHE.js";
43
+ } from "./chunk-FFU5RYDX.js";
44
44
 
45
45
  // ../../node_modules/.pnpm/universalify@2.0.1/node_modules/universalify/index.js
46
46
  var require_universalify = __commonJS({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentio/runtime",
3
- "version": "2.40.0-rc.4",
3
+ "version": "2.40.0-rc.5",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -14,17 +14,6 @@
14
14
  "!**/*.test.{js,ts}",
15
15
  "!{lib,src}/tests"
16
16
  ],
17
- "dependencies": {},
18
- "devDependencies": {
19
- "@types/command-line-args": "^5.2.3",
20
- "@types/command-line-usage": "^5.0.4",
21
- "@types/fs-extra": "^11.0.4",
22
- "@types/google-protobuf": "^3.15.12",
23
- "tslib": "^2.6.2"
24
- },
25
- "engines": {
26
- "node": ">=16"
27
- },
28
17
  "scripts": {
29
18
  "build": "pnpm bundle",
30
19
  "build:all": "pnpm --filter=$(node -p \"require('./package.json').name\")... build",
@@ -35,5 +24,38 @@
35
24
  "start_js": "tsx ./lib/processor-runner.js $PWD/../../debug/dist/lib.js",
36
25
  "start_ts": "tsx ./lib/processor-runner.js --log-format=json $PWD/../../debug/src/processor.ts",
37
26
  "test": "glob -c 'tsx --test' '**/*.test.ts'"
27
+ },
28
+ "dependencies": {
29
+ "@grpc/grpc-js": "^1.9.14",
30
+ "@opentelemetry/exporter-metrics-otlp-grpc": "^0.52.1",
31
+ "@opentelemetry/sdk-node": "^0.52.1",
32
+ "@sentio/protos": "workspace:*",
33
+ "command-line-args": "^5.2.1",
34
+ "command-line-usage": "^7.0.1",
35
+ "fs-extra": "^11.2.0",
36
+ "google-protobuf": "^3.21.2",
37
+ "ix": "^5.0.0",
38
+ "long": "^5.2.3",
39
+ "nice-grpc": "^2.1.7",
40
+ "nice-grpc-client-middleware-retry": "^3.1.6",
41
+ "nice-grpc-common": "^2.0.2",
42
+ "nice-grpc-error-details": "^0.2.4",
43
+ "nice-grpc-opentelemetry": "^0.1.15",
44
+ "nice-grpc-prometheus": "^0.2.2",
45
+ "prom-client": "^14.2.0",
46
+ "protobufjs": "^7.2.6",
47
+ "rxjs": "^7.8.1",
48
+ "utility-types": "^3.11.0",
49
+ "winston": "^3.11.0"
50
+ },
51
+ "devDependencies": {
52
+ "@types/command-line-args": "^5.2.3",
53
+ "@types/command-line-usage": "^5.0.4",
54
+ "@types/fs-extra": "^11.0.4",
55
+ "@types/google-protobuf": "^3.15.12",
56
+ "tslib": "^2.6.2"
57
+ },
58
+ "engines": {
59
+ "node": ">=16"
38
60
  }
39
- }
61
+ }
File without changes
@@ -0,0 +1,19 @@
1
+ import { describe, test } from 'node:test'
2
+ import { deepFreeze, GLOBAL_CONFIG } from './global-config.js'
3
+ import { assert } from 'chai'
4
+
5
+ describe('global config test', () => {
6
+ test('freeze test', async () => {
7
+ GLOBAL_CONFIG.execution = {
8
+ sequential: true,
9
+ forceExactBlockTime: false
10
+ }
11
+
12
+ deepFreeze(GLOBAL_CONFIG.execution)
13
+ deepFreeze(GLOBAL_CONFIG.execution)
14
+
15
+ assert.throw(() => {
16
+ GLOBAL_CONFIG.execution.sequential = false
17
+ })
18
+ })
19
+ })
@@ -0,0 +1,26 @@
1
+ import { describe, test } from 'node:test'
2
+ import { setupLogger } from './logger.js'
3
+
4
+ describe('Test logger', () => {
5
+ test('check log output', () => {
6
+ const object = { a: 'asdf', b: 'Asdf' }
7
+
8
+ console.log(JSON.stringify(object), object)
9
+ setupLogger(false, true)
10
+ console.log('asdf')
11
+ console.log('asdf')
12
+ console.log(1111, true, 'asdf')
13
+ console.log(111111111n)
14
+
15
+ // console.log(object)
16
+ console.log(JSON.stringify(object), object)
17
+ })
18
+
19
+ test('check debug log', () => {
20
+ console.log('check debug log')
21
+ setupLogger(false, true)
22
+ console.debug('debug=true')
23
+ setupLogger(true, false)
24
+ console.debug('debug=false')
25
+ })
26
+ })
@@ -0,0 +1,80 @@
1
+ import { before, describe, test } from 'node:test'
2
+ import { ProcessorServiceImpl } from './service.js'
3
+ import { FullProcessorServiceImpl } from './full-service.js'
4
+ import { CallContext } from 'nice-grpc-common'
5
+ import { DataBinding, HandlerType, ProcessResult } from './gen/processor/protos/processor.js'
6
+ import { Plugin, PluginManager } from './plugin.js'
7
+ import { assert } from 'chai'
8
+ import { GLOBAL_CONFIG } from './global-config.js'
9
+ export const TEST_CONTEXT: CallContext = <CallContext>{}
10
+
11
+ let testRequest: DataBinding
12
+
13
+ class TestPlugin extends Plugin {
14
+ async processBinding(request: DataBinding): Promise<ProcessResult> {
15
+ testRequest = request
16
+ return ProcessResult.fromPartial({})
17
+ }
18
+ supportedHandlers = [HandlerType.ETH_BLOCK]
19
+ }
20
+
21
+ describe('Test seq mode', () => {
22
+ const baseService = new ProcessorServiceImpl(async () => {
23
+ PluginManager.INSTANCE.plugins = []
24
+ PluginManager.INSTANCE.register(new TestPlugin())
25
+ })
26
+ const service = new FullProcessorServiceImpl(baseService)
27
+
28
+ before(async () => {
29
+ GLOBAL_CONFIG.execution.sequential = true
30
+
31
+ await service.start({ templateInstances: [] }, TEST_CONTEXT)
32
+ })
33
+
34
+ test('Check block dispatch in seq', async () => {
35
+ const binding1: DataBinding = {
36
+ data: {
37
+ raw: new Uint8Array(),
38
+ ethBlock: {
39
+ block: {
40
+ number: '0x1',
41
+ timestamp: '0x65ed3a46'
42
+ }
43
+ }
44
+ },
45
+ handlerType: HandlerType.ETH_BLOCK,
46
+ handlerIds: [0]
47
+ }
48
+
49
+ const binding2 = {
50
+ data: {
51
+ raw: new Uint8Array(),
52
+ ethBlock: {
53
+ block: {
54
+ number: '0x2',
55
+ timestamp: '0x65ed3b46'
56
+ }
57
+ }
58
+ },
59
+ handlerType: HandlerType.ETH_BLOCK,
60
+ handlerIds: [0]
61
+ }
62
+
63
+ const binding3 = {
64
+ data: {
65
+ raw: new Uint8Array(),
66
+ ethBlock: {
67
+ block: {
68
+ number: '0x1',
69
+ timestamp: '0x65ed3c46'
70
+ }
71
+ }
72
+ },
73
+ handlerType: HandlerType.ETH_BLOCK,
74
+ handlerIds: [0]
75
+ }
76
+
77
+ await service.processBindings({ bindings: [binding2, binding1, binding3] }, TEST_CONTEXT)
78
+ assert(testRequest.handlerType === HandlerType.ETH_BLOCK)
79
+ })
80
+ })
@@ -0,0 +1,51 @@
1
+ import { before, describe, test } from 'node:test'
2
+ import { ProcessorServiceImpl } from './service.js'
3
+ import { FullProcessorServiceImpl } from './full-service.js'
4
+ import { CallContext } from 'nice-grpc-common'
5
+ import { DataBinding, HandlerType, ProcessResult } from './gen/processor/protos/processor.js'
6
+ import { Plugin, PluginManager } from './plugin.js'
7
+ import { assert } from 'chai'
8
+
9
+ export const TEST_CONTEXT: CallContext = <CallContext>{}
10
+
11
+ // TODO use mock
12
+ let testRequest: DataBinding
13
+
14
+ class TestPlugin extends Plugin {
15
+ async processBinding(request: DataBinding): Promise<ProcessResult> {
16
+ testRequest = request
17
+ return ProcessResult.fromPartial({})
18
+ }
19
+ supportedHandlers = [HandlerType.UNKNOWN, HandlerType.APT_EVENT]
20
+ }
21
+
22
+ describe('Test Service Compatibility', () => {
23
+ const baseService = new ProcessorServiceImpl(async () => {
24
+ PluginManager.INSTANCE.plugins = []
25
+ PluginManager.INSTANCE.register(new TestPlugin())
26
+ })
27
+ const service = new FullProcessorServiceImpl(baseService)
28
+
29
+ before(async () => {
30
+ await service.start({ templateInstances: [] }, TEST_CONTEXT)
31
+ })
32
+
33
+ test('Check transaction dispatch', async () => {
34
+ const binding1: DataBinding = {
35
+ data: {
36
+ raw: new Uint8Array(),
37
+ ethBlock: {
38
+ block: {
39
+ number: '0x1'
40
+ }
41
+ }
42
+ },
43
+ handlerType: HandlerType.UNKNOWN,
44
+ handlerIds: [0]
45
+ }
46
+
47
+ await service.processBindings({ bindings: [binding1] }, TEST_CONTEXT)
48
+ assert(testRequest.handlerType === HandlerType.UNKNOWN)
49
+ assert((testRequest.data?.raw.length || 0) > 0)
50
+ })
51
+ })
@@ -0,0 +1,25 @@
1
+ import { describe, test } from 'node:test'
2
+ import { assert } from 'chai'
3
+ import { State, MapStateStorage } from './state.js'
4
+
5
+ describe('state storage tests', () => {
6
+ State.reset()
7
+
8
+ test('test labels', async () => {
9
+ // assert(false)
10
+ class TestState extends MapStateStorage<any> {
11
+ static INSTANCE = new TestState()
12
+ }
13
+ const m = TestState.INSTANCE.getOrRegister()
14
+ assert(m !== undefined)
15
+
16
+ const v1 = TestState.INSTANCE.getOrSetValue('k1', {})
17
+ const v2 = TestState.INSTANCE.getOrSetValue('k1', { a: '' })
18
+ assert(v1 === v2)
19
+ TestState.INSTANCE.getOrSetValue('k2', 'v2')
20
+
21
+ assert(TestState.INSTANCE.getValues().length === 2)
22
+ assert(State.INSTANCE.stateMap.size === 1)
23
+ assert(State.INSTANCE.stateMap.keys().next().value === 'TestState')
24
+ })
25
+ })
package/tsconfig.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ // "inlineSources": true,
5
+ "rootDir": "./src",
6
+ "baseUrl": "./src",
7
+ "outDir": "lib"
8
+ },
9
+ "exclude": ["lib"]
10
+ }
package/LICENSE DELETED
@@ -1,55 +0,0 @@
1
- Apache License
2
-
3
- Version 2.0, January 2004
4
-
5
- http://www.apache.org/licenses/
6
-
7
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
-
9
- 1. Definitions.
10
-
11
- "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
12
-
13
- "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
16
-
17
- "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
18
-
19
- "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
20
-
21
- "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
22
-
23
- "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
24
-
25
- "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
26
-
27
- "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
28
-
29
- "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
30
-
31
- 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
32
-
33
- 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
34
-
35
- 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
36
-
37
- You must give any other recipients of the Work or Derivative Works a copy of this License; and
38
-
39
- You must cause any modified files to carry prominent notices stating that You changed the files; and
40
-
41
- You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
42
-
43
- If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
44
-
45
- 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
46
-
47
- 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
48
-
49
- 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
50
-
51
- 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
52
-
53
- 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
54
-
55
- END OF TERMS AND CONDITIONS