@sentio/sdk 1.7.15 → 1.7.16

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.
@@ -0,0 +1,5 @@
1
+ export declare function load(name: string): {
2
+ module: any;
3
+ name: string;
4
+ path: string;
5
+ } | undefined;
package/lib/loader.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.load = void 0;
4
+ function load(name) {
5
+ const req = eval('require');
6
+ try {
7
+ let path;
8
+ try {
9
+ path = req.resolve(name, { paths: [process.cwd()] });
10
+ }
11
+ catch {
12
+ path = req.resolve(name);
13
+ }
14
+ const module = { module: req(path), name, path };
15
+ console.log('Load successfully: ', name);
16
+ return module;
17
+ }
18
+ catch (err) {
19
+ if (err instanceof Error && err.message.startsWith(`Cannot find module '${name}'`)) {
20
+ // this error is expected
21
+ console.log("Couldn't load (expected): ", name);
22
+ return undefined;
23
+ }
24
+ else {
25
+ throw err;
26
+ }
27
+ }
28
+ }
29
+ exports.load = load;
30
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";;;AAAA,SAAgB,IAAI,CAAC,IAAY;IAC/B,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,CAAA;IAE3B,IAAI;QACF,IAAI,IAAY,CAAA;QAChB,IAAI;YACF,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAA;SACrD;QAAC,MAAM;YACN,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;SACzB;QAED,MAAM,MAAM,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;QAChD,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAA;QACxC,OAAO,MAAM,CAAA;KACd;IAAC,OAAO,GAAG,EAAE;QACZ,IAAI,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,uBAAuB,IAAI,GAAG,CAAC,EAAE;YAClF,yBAAyB;YACzB,OAAO,CAAC,GAAG,CAAC,4BAA4B,EAAE,IAAI,CAAC,CAAA;YAC/C,OAAO,SAAS,CAAA;SACjB;aAAM;YACL,MAAM,GAAG,CAAA;SACV;KACF;AACH,CAAC;AAvBD,oBAuBC","sourcesContent":["export function load(name: string): { module: any; name: string; path: string } | undefined {\n const req = eval('require')\n\n try {\n let path: string\n try {\n path = req.resolve(name, { paths: [process.cwd()] })\n } catch {\n path = req.resolve(name)\n }\n\n const module = { module: req(path), name, path }\n console.log('Load successfully: ', name)\n return module\n } catch (err) {\n if (err instanceof Error && err.message.startsWith(`Cannot find module '${name}'`)) {\n // this error is expected\n console.log(\"Couldn't load (expected): \", name)\n return undefined\n } else {\n throw err\n }\n }\n}\n"]}
@@ -12,33 +12,9 @@ const provider_1 = require("./provider");
12
12
  const path_1 = __importDefault(require("path"));
13
13
  const fs_extra_1 = __importDefault(require("fs-extra"));
14
14
  const processor_state_1 = require("./processor-state");
15
+ const loader_1 = require("./loader");
15
16
  global.sentio_sdk = require('.');
16
17
  global.PROCESSOR_STATE = new processor_state_1.ProcessorState();
17
- function tryRequire(name) {
18
- const req = eval('require');
19
- try {
20
- let path;
21
- try {
22
- path = req.resolve(name, { paths: [process.cwd()] });
23
- }
24
- catch {
25
- path = req.resolve(name);
26
- }
27
- const module = { module: req(path), name, path };
28
- console.log('Load successfully: ', name);
29
- return module;
30
- }
31
- catch (err) {
32
- if (err instanceof Error && err.message.startsWith(`Cannot find module '${name}'`)) {
33
- // this error is expected
34
- console.log("Couldn't load (expected): ", name);
35
- return undefined;
36
- }
37
- else {
38
- throw err;
39
- }
40
- }
41
- }
42
18
  const optionDefinitions = [
43
19
  { name: 'target', type: String, defaultOption: true },
44
20
  { name: 'port', alias: 'p', type: String, defaultValue: '4000' },
@@ -56,12 +32,11 @@ console.log('loading', options.target);
56
32
  const fullPath = path_1.default.resolve(options['chains-config']);
57
33
  const chainsConfig = fs_extra_1.default.readJsonSync(fullPath);
58
34
  (0, provider_1.setProvider)(chainsConfig, options.concurrency, options['use-chainserver']);
59
- tryRequire(options.target);
60
35
  console.log('Start Server', options);
61
36
  console.log(global.PROCESSOR_STATE.processors.length, ' processors loaded');
62
37
  console.log(global.PROCESSOR_STATE.solanaProcessors.length, ' solana processors loaded');
63
38
  const server = (0, nice_grpc_1.createServer)();
64
- const service = new service_1.ProcessorServiceImpl(server.shutdown);
39
+ const service = new service_1.ProcessorServiceImpl(() => (0, loader_1.load)(options.target), server.shutdown);
65
40
  server.add(processor_1.ProcessorDefinition, service);
66
41
  server.listen('0.0.0.0:' + options.port);
67
42
  //# sourceMappingURL=processor-runner.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"processor-runner.js","sourceRoot":"","sources":["../src/processor-runner.ts"],"names":[],"mappings":";;;;;;AAEA,0EAA+C;AAC/C,yCAAwC;AACxC,gEAAsE;AACtE,uCAAgD;AAChD,yCAAwC;AAExC,gDAAuB;AACvB,wDAAyB;AACzB,uDAAkD;AAElD,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;AAChC,MAAM,CAAC,eAAe,GAAG,IAAI,gCAAc,EAAE,CAAA;AAE7C,SAAS,UAAU,CAAC,IAAY;IAC9B,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,CAAA;IAE3B,IAAI;QACF,IAAI,IAAY,CAAA;QAChB,IAAI;YACF,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAA;SACrD;QAAC,MAAM;YACN,IAAI,GAAG,GAAG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AI,CAAC,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAA;AACvD,MAAM,YAAY,GAAG,kBAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAA;AAE9C,IAAA,sBAAW,EAAC,YAAY,EAAE,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAA;AAE1E,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;AAE1B,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,OAAO,CAAC,CAAA;AAEpC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,eAAe,CAAC,UAAU,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAA;AAC3E,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,eAAe,CAAC,gBAAgB,CAAC,MAAM,EAAE,2BAA2B,CAAC,CAAA;AAExF,MAAM,MAAM,GAAG,IAAA,wBAAY,GAAE,CAAA;AAE7B,MAAM,OAAO,GAAG,IAAI,8BAAoB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;AACzD,MAAM,CAAC,GAAG,CAAC,+BAAmB,EAAE,OAAO,CAAC,CAAA;AAExC,MAAM,CAAC,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA","sourcesContent":["#!/usr/bin/env node\n\nimport commandLineArgs from 'command-line-args'\nimport { createServer } from 'nice-grpc'\nimport { ProcessorDefinition } from './gen/processor/protos/processor'\nimport { ProcessorServiceImpl } from './service'\nimport { setProvider } from './provider'\n\nimport path from 'path'\nimport fs from 'fs-extra'\nimport { ProcessorState } from './processor-state'\n\nglobal.sentio_sdk = require('.')\nglobal.PROCESSOR_STATE = new ProcessorState()\n\nfunction tryRequire(name: string): { module: any; name: string; path: string } | undefined {\n const req = eval('require')\n\n try {\n let path: string\n try {\n path = req.resolve(name, { paths: [process.cwd()] })\n } catch {\n path = req.resolve(name)\n }\n\n const module = { module: req(path), name, path }\n console.log('Load successfully: ', name)\n return module\n } catch (err) {\n if (err instanceof Error && err.message.startsWith(`Cannot find module '${name}'`)) {\n // this error is expected\n console.log(\"Couldn't load (expected): \", name)\n return undefined\n } else {\n throw err\n }\n }\n}\n\nconst optionDefinitions = [\n { name: 'target', type: String, defaultOption: true },\n { name: 'port', alias: 'p', type: String, defaultValue: '4000' },\n { name: 'concurrency', type: Number, defaultValue: 4 },\n { name: 'use-chainserver', type: Boolean, defaultValue: false },\n {\n name: 'chains-config',\n alias: 'c',\n type: String,\n defaultValue: 'chains-config.json',\n },\n]\n\nconst options = commandLineArgs(optionDefinitions, { partial: true })\n\nconsole.log('loading', options.target)\n\nconst fullPath = path.resolve(options['chains-config'])\nconst chainsConfig = fs.readJsonSync(fullPath)\n\nsetProvider(chainsConfig, options.concurrency, options['use-chainserver'])\n\ntryRequire(options.target)\n\nconsole.log('Start Server', options)\n\nconsole.log(global.PROCESSOR_STATE.processors.length, ' processors loaded')\nconsole.log(global.PROCESSOR_STATE.solanaProcessors.length, ' solana processors loaded')\n\nconst server = createServer()\n\nconst service = new ProcessorServiceImpl(server.shutdown)\nserver.add(ProcessorDefinition, service)\n\nserver.listen('0.0.0.0:' + options.port)\n"]}
1
+ {"version":3,"file":"processor-runner.js","sourceRoot":"","sources":["../src/processor-runner.ts"],"names":[],"mappings":";;;;;;AAEA,0EAA+C;AAC/C,yCAAwC;AACxC,gEAAsE;AACtE,uCAAgD;AAChD,yCAAwC;AAExC,gDAAuB;AACvB,wDAAyB;AACzB,uDAAkD;AAClD,qCAA+B;AAE/B,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;AAChC,MAAM,CAAC,eAAe,GAAG,IAAI,gCAAc,EAAE,CAAA;AAE7C,MAAM,iBAAiB,GAAG;IACxB,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE;IACrD,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE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AM,CAAC,GAAG,CAAC,+BAAmB,EAAE,OAAO,CAAC,CAAA;AAExC,MAAM,CAAC,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA","sourcesContent":["#!/usr/bin/env node\n\nimport commandLineArgs from 'command-line-args'\nimport { createServer } from 'nice-grpc'\nimport { ProcessorDefinition } from './gen/processor/protos/processor'\nimport { ProcessorServiceImpl } from './service'\nimport { setProvider } from './provider'\n\nimport path from 'path'\nimport fs from 'fs-extra'\nimport { ProcessorState } from './processor-state'\nimport { load } from './loader'\n\nglobal.sentio_sdk = require('.')\nglobal.PROCESSOR_STATE = new ProcessorState()\n\nconst optionDefinitions = [\n { name: 'target', type: String, defaultOption: true },\n { name: 'port', alias: 'p', type: String, defaultValue: '4000' },\n { name: 'concurrency', type: Number, defaultValue: 4 },\n { name: 'use-chainserver', type: Boolean, defaultValue: false },\n {\n name: 'chains-config',\n alias: 'c',\n type: String,\n defaultValue: 'chains-config.json',\n },\n]\n\nconst options = commandLineArgs(optionDefinitions, { partial: true })\n\nconsole.log('loading', options.target)\n\nconst fullPath = path.resolve(options['chains-config'])\nconst chainsConfig = fs.readJsonSync(fullPath)\n\nsetProvider(chainsConfig, options.concurrency, options['use-chainserver'])\n\nconsole.log('Start Server', options)\n\nconsole.log(global.PROCESSOR_STATE.processors.length, ' processors loaded')\nconsole.log(global.PROCESSOR_STATE.solanaProcessors.length, ' solana processors loaded')\n\nconst server = createServer()\n\nconst service = new ProcessorServiceImpl(() => load(options.target), server.shutdown)\nserver.add(ProcessorDefinition, service)\n\nserver.listen('0.0.0.0:' + options.port)\n"]}
package/lib/service.d.ts CHANGED
@@ -7,8 +7,9 @@ export declare class ProcessorServiceImpl implements ProcessorServiceImplementat
7
7
  private started;
8
8
  private contractConfigs;
9
9
  private templateInstances;
10
+ private readonly loader;
10
11
  private readonly shutdownHandler?;
11
- constructor(shutdownHandler?: () => void);
12
+ constructor(loader: () => void, shutdownHandler?: () => void);
12
13
  getConfig(request: ProcessConfigRequest, context: CallContext): Promise<ProcessConfigResponse>;
13
14
  configure(): Promise<void>;
14
15
  start(request: StartRequest, context: CallContext): Promise<Empty>;
package/lib/service.js CHANGED
@@ -18,8 +18,10 @@ class ProcessorServiceImpl {
18
18
  started = false;
19
19
  contractConfigs;
20
20
  templateInstances;
21
+ loader;
21
22
  shutdownHandler;
22
- constructor(shutdownHandler) {
23
+ constructor(loader, shutdownHandler) {
24
+ this.loader = loader;
23
25
  this.shutdownHandler = shutdownHandler;
24
26
  }
25
27
  async getConfig(request, context) {
@@ -117,8 +119,8 @@ class ProcessorServiceImpl {
117
119
  endBlock: DEFAULT_MAX_BLOCK,
118
120
  instructionConfig: {
119
121
  innerInstruction: solanaProcessor.processInnerInstruction,
120
- parsedInstruction: solanaProcessor.fromParsedInstruction != null ? true : false,
121
- rawDataInstruction: solanaProcessor.decodeInstruction != null ? true : false,
122
+ parsedInstruction: solanaProcessor.fromParsedInstruction !== null,
123
+ rawDataInstruction: solanaProcessor.decodeInstruction !== null,
122
124
  },
123
125
  };
124
126
  this.contractConfigs.push(contractConfig);
@@ -128,6 +130,7 @@ class ProcessorServiceImpl {
128
130
  if (this.started) {
129
131
  return {};
130
132
  }
133
+ this.loader();
131
134
  for (const instance of request.templateInstances) {
132
135
  const template = global.PROCESSOR_STATE.templates[instance.templateId];
133
136
  if (!template) {
@@ -1 +1 @@
1
- {"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":";;;;;;AACA,yCAA4D;AAE5D,gEAoByC;AAGzC,gDAAuB;AACvB,+BAAkC;AAElC,MAAM,iBAAiB,GAAG,cAAI,CAAC,IAAI,CAAA;AAEnC,MAAa,oBAAoB;IACvB,aAAa,GAA4C,EAAE,CAAA;IAC3D,aAAa,GAA8C,EAAE,CAAA;IAErE,0CAA0C;IAC1C,uFAAuF;IACvF,qHAAqH;IAE7G,OAAO,GAAG,KAAK,CAAA;IACf,eAAe,CAAkB;IACjC,iBAAiB,CAAoB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AAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;gBAC9F,MAAK;SACR;KACF;IAED,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAmB,EAAE,WAAwB;IACtE,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;AACJ,CAAC","sourcesContent":["import { Block, Log } from '@ethersproject/abstract-provider'\nimport { CallContext, ServerError, Status } from 'nice-grpc'\n\nimport {\n BlockBinding,\n ContractConfig,\n HandlerType,\n LogFilter,\n LogHandlerConfig,\n O11yResult,\n ProcessBlocksRequest,\n ProcessBlocksResponse,\n ProcessConfigRequest,\n ProcessConfigResponse,\n ProcessInstructionsRequest,\n ProcessInstructionsResponse,\n ProcessLogsRequest,\n ProcessLogsResponse,\n ProcessorServiceImplementation,\n ProcessTransactionsRequest,\n ProcessTransactionsResponse,\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'\n\nconst DEFAULT_MAX_BLOCK = Long.ZERO\n\nexport class ProcessorServiceImpl implements ProcessorServiceImplementation {\n private eventHandlers: ((event: Log) => Promise<O11yResult>)[] = []\n private blockHandlers: ((block: Block) => Promise<O11yResult>)[] = []\n\n // map from chain id to list of processors\n // private blockHandlers = new Map<string, ((block: Block) => Promise<O11yResult>)[]>()\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\n private readonly shutdownHandler?: () => void\n\n constructor(shutdownHandler?: () => void) {\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 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 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:mainnet', // TODO set in processor\n address: solanaProcessor.address,\n abi: '',\n },\n blockConfigs: [],\n logConfigs: [],\n startBlock: solanaProcessor.config.startSlot,\n endBlock: DEFAULT_MAX_BLOCK,\n instructionConfig: {\n innerInstruction: solanaProcessor.processInnerInstruction,\n parsedInstruction: solanaProcessor.fromParsedInstruction != null ? true : false,\n rawDataInstruction: solanaProcessor.decodeInstruction != null ? true : false,\n },\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 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 await this.configure()\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 resp: O11yResult = {\n gauges: [],\n counters: [],\n }\n\n const promises: Promise<O11yResult>[] = []\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' + e.toString())\n })\n\n promises.push(promise)\n } catch (e) {\n throw new ServerError(Status.INTERNAL, 'error parse log: ' + l)\n }\n }\n\n const results = await Promise.all(promises)\n for (const res of results) {\n resp.counters = resp.counters.concat(res.counters)\n resp.gauges = resp.gauges.concat(res.gauges)\n }\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(resp, HandlerType.LOG)\n return {\n result: resp,\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 throw new ServerError(Status.UNIMPLEMENTED, 'Processing transaction is not suppored.')\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: O11yResult = {\n gauges: [],\n counters: [],\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: O11yResult | null\n if (instruction.parsed) {\n res = processor.handleInstruction(JSON.parse(new TextDecoder().decode(instruction.parsed)))\n } else if (instruction.instructionData) {\n res = processor.handleInstruction(instruction.instructionData)\n } else {\n continue\n }\n if (res) {\n try {\n res.gauges.forEach((g) => {\n if (g.metadata) {\n g.metadata.blockNumber = instruction.slot\n }\n result.gauges.push(g)\n })\n res.counters.forEach((c) => {\n if (c.metadata) {\n c.metadata.blockNumber = instruction.slot\n }\n result.counters.push(c)\n })\n } catch (e) {\n console.error('error processing instruction ' + e.toString())\n }\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 results = await Promise.all(promises)\n\n const res = O11yResult.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 }\n\n recordRuntimeInfo(res, HandlerType.BLOCK)\n return {\n result: res,\n }\n }\n\n async processBlock(binding: BlockBinding): Promise<O11yResult> {\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 resp: O11yResult = {\n gauges: [],\n counters: [],\n }\n\n const promises: Promise<O11yResult>[] = []\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' + e.toString())\n })\n promises.push(promise)\n }\n const allRes = await Promise.all(promises)\n for (const res of allRes) {\n resp.counters = resp.counters.concat(res.counters)\n resp.gauges = resp.gauges.concat(res.gauges)\n }\n return resp\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 recordRuntimeInfo(results: O11yResult, 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"]}
1
+ {"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":";;;;;;AACA,yCAA4D;AAE5D,gEAoByC;AAGzC,gDAAuB;AACvB,+BAAkC;AAElC,MAAM,iBAAiB,GAAG,cAAI,CAAC,IAAI,CAAA;AAEnC,MAAa,oBAAoB;IACvB,aAAa,GAA4C,EAAE,CAAA;IAC3D,aAAa,GAA8C,EAAE,CAAA;IAErE,0CAA0C;IAC1C,uFAAuF;IACvF,qHAAqH;IAE7G,OAAO,GAAG,KAAK,CAAA;IACf,eAAe,CAAkB;IACjC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AG,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;gBAC9F,MAAK;SACR;KACF;IAED,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAmB,EAAE,WAAwB;IACtE,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;AACJ,CAAC","sourcesContent":["import { Block, Log } from '@ethersproject/abstract-provider'\nimport { CallContext, ServerError, Status } from 'nice-grpc'\n\nimport {\n BlockBinding,\n ContractConfig,\n HandlerType,\n LogFilter,\n LogHandlerConfig,\n O11yResult,\n ProcessBlocksRequest,\n ProcessBlocksResponse,\n ProcessConfigRequest,\n ProcessConfigResponse,\n ProcessInstructionsRequest,\n ProcessInstructionsResponse,\n ProcessLogsRequest,\n ProcessLogsResponse,\n ProcessorServiceImplementation,\n ProcessTransactionsRequest,\n ProcessTransactionsResponse,\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'\n\nconst DEFAULT_MAX_BLOCK = Long.ZERO\n\nexport class ProcessorServiceImpl implements ProcessorServiceImplementation {\n private eventHandlers: ((event: Log) => Promise<O11yResult>)[] = []\n private blockHandlers: ((block: Block) => Promise<O11yResult>)[] = []\n\n // map from chain id to list of processors\n // private blockHandlers = new Map<string, ((block: Block) => Promise<O11yResult>)[]>()\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 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 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:mainnet', // TODO set in processor\n address: solanaProcessor.address,\n abi: '',\n },\n blockConfigs: [],\n logConfigs: [],\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\n async start(request: StartRequest, context: CallContext): Promise<Empty> {\n if (this.started) {\n return {}\n }\n\n this.loader()\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 await this.configure()\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 resp: O11yResult = {\n gauges: [],\n counters: [],\n }\n\n const promises: Promise<O11yResult>[] = []\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' + e.toString())\n })\n\n promises.push(promise)\n } catch (e) {\n throw new ServerError(Status.INTERNAL, 'error parse log: ' + l)\n }\n }\n\n const results = await Promise.all(promises)\n for (const res of results) {\n resp.counters = resp.counters.concat(res.counters)\n resp.gauges = resp.gauges.concat(res.gauges)\n }\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(resp, HandlerType.LOG)\n return {\n result: resp,\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 throw new ServerError(Status.UNIMPLEMENTED, 'Processing transaction is not suppored.')\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: O11yResult = {\n gauges: [],\n counters: [],\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: O11yResult | null\n if (instruction.parsed) {\n res = processor.handleInstruction(JSON.parse(new TextDecoder().decode(instruction.parsed)))\n } else if (instruction.instructionData) {\n res = processor.handleInstruction(instruction.instructionData)\n } else {\n continue\n }\n if (res) {\n try {\n res.gauges.forEach((g) => {\n if (g.metadata) {\n g.metadata.blockNumber = instruction.slot\n }\n result.gauges.push(g)\n })\n res.counters.forEach((c) => {\n if (c.metadata) {\n c.metadata.blockNumber = instruction.slot\n }\n result.counters.push(c)\n })\n } catch (e) {\n console.error('error processing instruction ' + e.toString())\n }\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 results = await Promise.all(promises)\n\n const res = O11yResult.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 }\n\n recordRuntimeInfo(res, HandlerType.BLOCK)\n return {\n result: res,\n }\n }\n\n async processBlock(binding: BlockBinding): Promise<O11yResult> {\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 resp: O11yResult = {\n gauges: [],\n counters: [],\n }\n\n const promises: Promise<O11yResult>[] = []\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' + e.toString())\n })\n promises.push(promise)\n }\n const allRes = await Promise.all(promises)\n for (const res of allRes) {\n resp.counters = resp.counters.concat(res.counters)\n resp.gauges = resp.gauges.concat(res.gauges)\n }\n return resp\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 recordRuntimeInfo(results: O11yResult, 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"]}
@@ -8,10 +8,8 @@ const chai_1 = require("chai");
8
8
  const long_1 = __importDefault(require("long"));
9
9
  const test_processor_server_1 = require("./test-processor-server");
10
10
  describe('Test Template', () => {
11
- const service = new test_processor_server_1.TestProcessorServer();
11
+ const service = new test_processor_server_1.TestProcessorServer(() => require('./erc20-template'));
12
12
  beforeAll(async () => {
13
- service.setup();
14
- require('./erc20-template');
15
13
  const request = {
16
14
  templateInstances: [
17
15
  {
@@ -1 +1 @@
1
- {"version":3,"file":"erc20-template.test.js","sourceRoot":"","sources":["../../src/test/erc20-template.test.ts"],"names":[],"mappings":";AAAA,gCAAgC;;;;;AAEhC,+BAA6B;AAG7B,gDAAuB;AACvB,mEAA6D;AAE7D,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,MAAM,OAAO,GAAG,IAAI,2CAAmB,EAAE,CAAA;IAEzC,SAAS,CAAC,KAAK,IAAI,EAAE;QACnB,OAAO,CAAC,KAAK,EAAE,CAAA;QACf,OAAO,CAAC,kBAAkB,CAAC,CAAA;QAC3B,MAAM,OAAO,GAAiB;YAC5B,iBAAiB,EAAE;gBACjB;oBACE,QAAQ,EAAE;wBACR,OAAO,EAAE,UAAU;wBACnB,IAAI,EAAE,UAAU;wBAChB,OAAO,EAAE,GAAG;wBACZ,GAAG,EAAE,EAAE;qBACR;oBACD,UAAU,EAAE,cAAI,CAAC,IAAI;oBACrB,QAAQ,EAAE,cAAI,CAAC,IAAI;oBACnB,UAAU,EAAE,CAAC;iBACd;aACF;SACF,CAAA;QACD,MAAM,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAC9B,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;QAC5C,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAC1C,IAAA,aAAM,EAAC,MAAM,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;QACxC,IAAA,aAAM,EAAC,MAAM,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;QACrE,IAAA,aAAM,EAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IAC5C,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["// TODO move out of this package\n\nimport { expect } from 'chai'\n\nimport { StartRequest } from '..'\nimport Long from 'long'\nimport { TestProcessorServer } from './test-processor-server'\n\ndescribe('Test Template', () => {\n const service = new TestProcessorServer()\n\n beforeAll(async () => {\n service.setup()\n require('./erc20-template')\n const request: StartRequest = {\n templateInstances: [\n {\n contract: {\n address: 'dynamic2',\n name: 'dynamic2',\n chainId: '1',\n abi: '',\n },\n startBlock: Long.ZERO,\n endBlock: Long.ZERO,\n templateId: 0,\n },\n ],\n }\n await service.start(request)\n })\n\n test('Check template instantiate', async () => {\n const config = await service.getConfig({})\n expect(config.contractConfigs).length(2)\n expect(config.contractConfigs?.[1].contract?.name).equals('dynamic2')\n expect(config.templateInstances).length(1)\n })\n})\n"]}
1
+ {"version":3,"file":"erc20-template.test.js","sourceRoot":"","sources":["../../src/test/erc20-template.test.ts"],"names":[],"mappings":";AAAA,gCAAgC;;;;;AAEhC,+BAA6B;AAG7B,gDAAuB;AACvB,mEAA6D;AAE7D,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,MAAM,OAAO,GAAG,IAAI,2CAAmB,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAA;IAE1E,SAAS,CAAC,KAAK,IAAI,EAAE;QACnB,MAAM,OAAO,GAAiB;YAC5B,iBAAiB,EAAE;gBACjB;oBACE,QAAQ,EAAE;wBACR,OAAO,EAAE,UAAU;wBACnB,IAAI,EAAE,UAAU;wBAChB,OAAO,EAAE,GAAG;wBACZ,GAAG,EAAE,EAAE;qBACR;oBACD,UAAU,EAAE,cAAI,CAAC,IAAI;oBACrB,QAAQ,EAAE,cAAI,CAAC,IAAI;oBACnB,UAAU,EAAE,CAAC;iBACd;aACF;SACF,CAAA;QACD,MAAM,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAC9B,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;QAC5C,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAC1C,IAAA,aAAM,EAAC,MAAM,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;QACxC,IAAA,aAAM,EAAC,MAAM,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;QACrE,IAAA,aAAM,EAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IAC5C,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["// TODO move out of this package\n\nimport { expect } from 'chai'\n\nimport { StartRequest } from '..'\nimport Long from 'long'\nimport { TestProcessorServer } from './test-processor-server'\n\ndescribe('Test Template', () => {\n const service = new TestProcessorServer(() => require('./erc20-template'))\n\n beforeAll(async () => {\n const request: StartRequest = {\n templateInstances: [\n {\n contract: {\n address: 'dynamic2',\n name: 'dynamic2',\n chainId: '1',\n abi: '',\n },\n startBlock: Long.ZERO,\n endBlock: Long.ZERO,\n templateId: 0,\n },\n ],\n }\n await service.start(request)\n })\n\n test('Check template instantiate', async () => {\n const config = await service.getConfig({})\n expect(config.contractConfigs).length(2)\n expect(config.contractConfigs?.[1].contract?.name).equals('dynamic2')\n expect(config.templateInstances).length(1)\n })\n})\n"]}
@@ -8,10 +8,8 @@ const metric_utils_1 = require("./metric-utils");
8
8
  const ethers_1 = require("ethers");
9
9
  const test_utils_1 = require("../builtin/erc20/test-utils");
10
10
  describe('Test Basic Examples', () => {
11
- const service = new test_processor_server_1.TestProcessorServer();
11
+ const service = new test_processor_server_1.TestProcessorServer(() => require('./erc20'));
12
12
  beforeAll(async () => {
13
- service.setup();
14
- require('./erc20');
15
13
  await service.start();
16
14
  });
17
15
  test('check configuration', async () => {
@@ -1 +1 @@
1
- {"version":3,"file":"erc20.test.js","sourceRoot":"","sources":["../../src/test/erc20.test.ts"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CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;QAEpC,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAC1C,IAAA,aAAM,EAAC,MAAM,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA,CAAC,kBAAkB;QAC3D,IAAA,aAAM,EAAC,MAAM,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;QAEpE,kCAAkC;QAClC,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAA;QACjC,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAC3C,IAAA,aAAM,EAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IACrC,CAAC,CAAC,CAAA;IAEF,MAAM,SAAS,GAAG;QAChB,IAAI,EAAE,oEAAoE;QAC1E,MAAM,EAAE,QAAQ;QAChB,SAAS,EAAE,UAAU;QACrB,SAAS,EAAE,wCAAwC;KACpD,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["// TODO move out of this package\n\nimport { expect } from 'chai'\n\nimport { HandlerType } from '..'\n\nimport { TestProcessorServer } from './test-processor-server'\nimport { firstCounterValue, firstGaugeValue } from './metric-utils'\nimport { BigNumber } from 'ethers'\nimport { mockTransferLog } from '../builtin/erc20/test-utils'\n\ndescribe('Test Basic Examples', () => {\n const service = new TestProcessorServer()\n\n beforeAll(async () => {\n service.setup()\n require('./erc20')\n await service.start()\n })\n\n test('check configuration', async () => {\n const config = await service.getConfig({})\n expect(config.contractConfigs).length(5)\n\n // check auto rename\n expect(config.contractConfigs?.[2].contract?.name).equals('Erc20')\n expect(config.contractConfigs?.[3].contract?.name).equals('Erc20_1')\n // same as above because only differ in parameters\n expect(config.contractConfigs?.[4].contract?.name).equals('Erc20_1')\n })\n\n test('Check block dispatch', async () => {\n const res = await service.testBlock(blockData)\n const o11yRes = res.result\n expect(o11yRes?.counters).length(0)\n expect(o11yRes?.gauges).length(1)\n expect(firstGaugeValue(o11yRes, 'g1')).equals(10n)\n\n const gauge = o11yRes?.gauges?.[0]\n expect(gauge?.metadata?.blockNumber?.toString()).equals('14373295')\n expect(gauge?.runtimeInfo?.from).equals(HandlerType.BLOCK)\n\n const res2 = await service.testBlock(blockData, 56)\n const o11yRes2 = res2.result\n expect(o11yRes2?.counters).length(0)\n expect(o11yRes2?.gauges).length(1)\n expect(firstGaugeValue(o11yRes2, 'g2')).equals(20n)\n })\n\n test('Check log dispatch', async () => {\n const logData = mockTransferLog('0x1E4EDE388cbc9F4b5c79681B7f94d36a11ABEBC9', {\n from: '0x0000000000000000000000000000000000000000',\n to: '0xB329e39Ebefd16f40d38f07643652cE17Ca5Bac1',\n value: BigNumber.from('0x9a71db64810aaa0000'),\n })\n\n let res = await service.testLog(logData)\n\n const counters = res.result?.counters\n expect(counters).length(1)\n expect(firstCounterValue(res.result, 'c1')).equals(1n)\n\n expect(counters?.[0].metadata?.chainId).equals('1')\n expect(counters?.[0].runtimeInfo?.from).equals(HandlerType.LOG)\n expect(res.configUpdated).equals(true)\n\n const logData2 = Object.assign({}, logData)\n logData2.address = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'\n res = await service.testLog(logData2, 56)\n\n expect(firstCounterValue(res.result, 'c2')).equals(2n)\n expect(res.result?.counters[0].metadata?.chainId).equals('56')\n\n expect(res.result?.gauges).length(0)\n\n const config = await service.getConfig({})\n expect(config.contractConfigs).length(6) //config increased\n expect(config.contractConfigs?.[5].contract?.name).equals('dynamic')\n\n // repeat trigger won't bind again\n await service.testLogs([logData])\n const config2 = await service.getConfig({})\n expect(config).deep.equals(config2)\n })\n\n const blockData = {\n hash: '0x2b9b7cce1f17f3b7e1f3c2472cc806a07bee3f0baca07d021350950d81d73a42',\n number: 14373295,\n timestamp: 1647106437,\n extraData: '0xe4b883e5bda9e7a59ee4bb99e9b1bc493421',\n }\n})\n"]}
1
+ {"version":3,"file":"erc20.test.js","sourceRoot":"","sources":["../../src/test/erc20.test.ts"],"names":[],"mappings":";AAAA,gCAAgC;;AAEhC,+BAA6B;AAE7B,0BAAgC;AAEhC,mEAA6D;AAC7D,iDAAmE;AACnE,mCAAkC;AAClC,4DAA6D;AAE7D,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,MAAM,OAAO,GAAG,IAAI,2CAAmB,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAA;IAEjE,SAAS,CAAC,KAAK,IAAI,EAAE;QACnB,MAAM,OAAO,CAAC,KAAK,EAAE,CAAA;IACvB,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,qBAAqB,EAAE,KAAK,IAAI,EAAE;QACrC,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAC1C,IAAA,aAAM,EAAC,MAAM,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;QAExC,oBAAoB;QACpB,IAAA,aAAM,EAAC,MAAM,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QAClE,IAAA,aAAM,EAAC,MAAM,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;QACpE,kDAAkD;QAClD,IAAA,aAAM,EAAC,MAAM,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;IACtE,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE;QACtC,MAAM,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AAE,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QAE9D,IAAA,aAAM,EAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;QAEpC,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAC1C,IAAA,aAAM,EAAC,MAAM,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA,CAAC,kBAAkB;QAC3D,IAAA,aAAM,EAAC,MAAM,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;QAEpE,kCAAkC;QAClC,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAA;QACjC,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAC3C,IAAA,aAAM,EAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IACrC,CAAC,CAAC,CAAA;IAEF,MAAM,SAAS,GAAG;QAChB,IAAI,EAAE,oEAAoE;QAC1E,MAAM,EAAE,QAAQ;QAChB,SAAS,EAAE,UAAU;QACrB,SAAS,EAAE,wCAAwC;KACpD,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["// TODO move out of this package\n\nimport { expect } from 'chai'\n\nimport { HandlerType } from '..'\n\nimport { TestProcessorServer } from './test-processor-server'\nimport { firstCounterValue, firstGaugeValue } from './metric-utils'\nimport { BigNumber } from 'ethers'\nimport { mockTransferLog } from '../builtin/erc20/test-utils'\n\ndescribe('Test Basic Examples', () => {\n const service = new TestProcessorServer(() => require('./erc20'))\n\n beforeAll(async () => {\n await service.start()\n })\n\n test('check configuration', async () => {\n const config = await service.getConfig({})\n expect(config.contractConfigs).length(5)\n\n // check auto rename\n expect(config.contractConfigs?.[2].contract?.name).equals('Erc20')\n expect(config.contractConfigs?.[3].contract?.name).equals('Erc20_1')\n // same as above because only differ in parameters\n expect(config.contractConfigs?.[4].contract?.name).equals('Erc20_1')\n })\n\n test('Check block dispatch', async () => {\n const res = await service.testBlock(blockData)\n const o11yRes = res.result\n expect(o11yRes?.counters).length(0)\n expect(o11yRes?.gauges).length(1)\n expect(firstGaugeValue(o11yRes, 'g1')).equals(10n)\n\n const gauge = o11yRes?.gauges?.[0]\n expect(gauge?.metadata?.blockNumber?.toString()).equals('14373295')\n expect(gauge?.runtimeInfo?.from).equals(HandlerType.BLOCK)\n\n const res2 = await service.testBlock(blockData, 56)\n const o11yRes2 = res2.result\n expect(o11yRes2?.counters).length(0)\n expect(o11yRes2?.gauges).length(1)\n expect(firstGaugeValue(o11yRes2, 'g2')).equals(20n)\n })\n\n test('Check log dispatch', async () => {\n const logData = mockTransferLog('0x1E4EDE388cbc9F4b5c79681B7f94d36a11ABEBC9', {\n from: '0x0000000000000000000000000000000000000000',\n to: '0xB329e39Ebefd16f40d38f07643652cE17Ca5Bac1',\n value: BigNumber.from('0x9a71db64810aaa0000'),\n })\n\n let res = await service.testLog(logData)\n\n const counters = res.result?.counters\n expect(counters).length(1)\n expect(firstCounterValue(res.result, 'c1')).equals(1n)\n\n expect(counters?.[0].metadata?.chainId).equals('1')\n expect(counters?.[0].runtimeInfo?.from).equals(HandlerType.LOG)\n expect(res.configUpdated).equals(true)\n\n const logData2 = Object.assign({}, logData)\n logData2.address = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'\n res = await service.testLog(logData2, 56)\n\n expect(firstCounterValue(res.result, 'c2')).equals(2n)\n expect(res.result?.counters[0].metadata?.chainId).equals('56')\n\n expect(res.result?.gauges).length(0)\n\n const config = await service.getConfig({})\n expect(config.contractConfigs).length(6) //config increased\n expect(config.contractConfigs?.[5].contract?.name).equals('dynamic')\n\n // repeat trigger won't bind again\n await service.testLogs([logData])\n const config2 = await service.getConfig({})\n expect(config).deep.equals(config2)\n })\n\n const blockData = {\n hash: '0x2b9b7cce1f17f3b7e1f3c2472cc806a07bee3f0baca07d021350950d81d73a42',\n number: 14373295,\n timestamp: 1647106437,\n extraData: '0xe4b883e5bda9e7a59ee4bb99e9b1bc493421',\n }\n})\n"]}
@@ -7,9 +7,7 @@ const generic_processor_1 = require("../generic-processor");
7
7
  const test_processor_server_1 = require("./test-processor-server");
8
8
  const metric_utils_1 = require("./metric-utils");
9
9
  describe('Test Generic Processor', () => {
10
- const service = new test_processor_server_1.TestProcessorServer();
11
- beforeAll(async () => {
12
- service.setup();
10
+ const service = new test_processor_server_1.TestProcessorServer(() => {
13
11
  generic_processor_1.GenericProcessor.bind([
14
12
  'event Transfer(address indexed from, address indexed to, uint256 value)',
15
13
  'event Approval(address indexed from, address indexed to, uint256 value)',
@@ -21,6 +19,8 @@ describe('Test Generic Processor', () => {
21
19
  }).onAllEvents(function (log, ctx) {
22
20
  ctx.meter.Counter('wallet').add(1);
23
21
  });
22
+ });
23
+ beforeAll(async () => {
24
24
  await service.start();
25
25
  });
26
26
  test('check configuration', async () => {
@@ -1 +1 @@
1
- {"version":3,"file":"generic-processor.test.js","sourceRoot":"","sources":["../../src/test/generic-processor.test.ts"],"names":[],"mappings":";AAAA,gCAAgC;;AAEhC,+BAA6B;AAE7B,0BAAgC;AAEhC,4DAAuD;AACvD,mEAA6D;AAC7D,iDAAkD;AAElD,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,MAAM,OAAO,GAAG,IAAI,2CAAmB,EAAE,CAAA;IAEzC,SAAS,CAAC,KAAK,IAAI,EAAE;QACnB,OAAO,CAAC,KAAK,EAAE,CAAA;QAEf,oCAAgB,CAAC,IAAI,CACnB;YACE,yEAAyE;YACzE,yEAAyE;SAC1E,EACD,EAAE,OAAO,EAAE,4CAA4C,EAAE,CAC1D,CAAC,WAAW,CAAC,UAAU,GAAG,EAAE,GAAG;YAC9B,GAAG,CAAC,KAAK,CAAC,OA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AW,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,eAAW,CAAC,GAAG,CAAC,CAAA;IACjE,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,wCAAwC,EAAE,KAAK,IAAI,EAAE;QACxD,MAAM,MAAM,GACV,ohBAAohB,CAAA;QACthB,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;QACrD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAA;IAClC,CAAC,CAAC,CAAA;IAEF,MAAM,OAAO,GAAG;QACd,WAAW,EAAE,QAAQ;QACrB,SAAS,EAAE,oEAAoE;QAC/E,gBAAgB,EAAE,GAAG;QACrB,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,4CAA4C;QACrD,IAAI,EAAE,oEAAoE;QAC1E,MAAM,EAAE;YACN,oEAAoE;YACpE,oEAAoE;YACpE,oEAAoE;SACrE;QACD,eAAe,EAAE,oEAAoE;QACrF,QAAQ,EAAE,GAAG;KACd,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["// TODO move out of this package\n\nimport { expect } from 'chai'\n\nimport { HandlerType } from '..'\n\nimport { GenericProcessor } from '../generic-processor'\nimport { TestProcessorServer } from './test-processor-server'\nimport { firstCounterValue } from './metric-utils'\n\ndescribe('Test Generic Processor', () => {\n const service = new TestProcessorServer()\n\n beforeAll(async () => {\n service.setup()\n\n GenericProcessor.bind(\n [\n 'event Transfer(address indexed from, address indexed to, uint256 value)',\n 'event Approval(address indexed from, address indexed to, uint256 value)',\n ],\n { address: '0x1E4EDE388cbc9F4b5c79681B7f94d36a11ABEBC9' }\n ).onAllEvents(function (log, ctx) {\n ctx.meter.Counter('event_num').add(1)\n })\n\n GenericProcessor.bind('event WalletCreated(address wallet, address owner)', {\n address: '0x57E037F4d2c8BEa011Ad8a9A5AF4AaEEd508650f',\n }).onAllEvents(function (log, ctx) {\n ctx.meter.Counter('wallet').add(1)\n })\n\n await service.start()\n })\n\n test('check configuration', async () => {\n const config = await service.getConfig({})\n expect(config.contractConfigs).length(2)\n expect(config.contractConfigs?.[0].contract?.name).equals('Generic')\n })\n\n test('Check log dispatch', async () => {\n const res = await service.testLogs([logData, logData])\n const counters = res.result?.counters\n expect(counters).length(2)\n expect(firstCounterValue(res.result, 'event_num')).equals(1n)\n expect(counters?.[0].runtimeInfo?.from).equals(HandlerType.LOG)\n })\n\n test('Check log dispatch no buffer over rune', async () => {\n const logStr =\n '{\"address\":\"0x57e037f4d2c8bea011ad8a9a5af4aaeed508650f\",\"topics\":[\"0x5b03bfed1c14a02bdeceb5fa582eb1a5765fc0bc64ca0e6af4c20afc9487f081\"],\"data\":\"0x00000000000000000000000093269483a70c68d5c5bb63aac1e8f4ac59f498800000000000000000000000000c520e51c055cf63bab075715c1b860b2e9b8e24\",\"blockNumber\":\"0xc9d6d7\",\"transactionHash\":\"0x208af3250499672c2f07138b9aa236153c65c78ae4341b23c2763017afdd61a2\",\"transactionIndex\":\"0xf3\",\"blockHash\":\"0x6e3b100c34b510049e922fbe1c1dab1b0793be3d1229b632688e6a518cdd11b6\",\"logIndex\":\"0x14b\",\"removed\":false}'\n const res = await service.testLog(JSON.parse(logStr))\n console.log(JSON.stringify(res))\n })\n\n const logData = {\n blockNumber: 14213252,\n blockHash: '0x83d646fac9350b281def8c4c37626f9d8efc95df801287b848c719edf35cdbaf',\n transactionIndex: 347,\n removed: false,\n address: '0x1E4EDE388cbc9F4b5c79681B7f94d36a11ABEBC9',\n data: '0x00000000000000000000000000000000000000000000009a71db64810aaa0000',\n topics: [\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n '0x0000000000000000000000000000000000000000000000000000000000000000',\n '0x000000000000000000000000b329e39ebefd16f40d38f07643652ce17ca5bac1',\n ],\n transactionHash: '0x93355e0cb2c3490cb8a747029ff2dc8cdbde2407025b8391398436955afae303',\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KACd,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["// TODO move out of this package\n\nimport { expect } from 'chai'\n\nimport { HandlerType } from '..'\n\nimport { GenericProcessor } from '../generic-processor'\nimport { TestProcessorServer } from './test-processor-server'\nimport { firstCounterValue } from './metric-utils'\n\ndescribe('Test Generic Processor', () => {\n const service = new TestProcessorServer(() => {\n GenericProcessor.bind(\n [\n 'event Transfer(address indexed from, address indexed to, uint256 value)',\n 'event Approval(address indexed from, address indexed to, uint256 value)',\n ],\n { address: '0x1E4EDE388cbc9F4b5c79681B7f94d36a11ABEBC9' }\n ).onAllEvents(function (log, ctx) {\n ctx.meter.Counter('event_num').add(1)\n })\n\n GenericProcessor.bind('event WalletCreated(address wallet, address owner)', {\n address: '0x57E037F4d2c8BEa011Ad8a9A5AF4AaEEd508650f',\n }).onAllEvents(function (log, ctx) {\n ctx.meter.Counter('wallet').add(1)\n })\n })\n\n beforeAll(async () => {\n await service.start()\n })\n\n test('check configuration', async () => {\n const config = await service.getConfig({})\n expect(config.contractConfigs).length(2)\n expect(config.contractConfigs?.[0].contract?.name).equals('Generic')\n })\n\n test('Check log dispatch', async () => {\n const res = await service.testLogs([logData, logData])\n const counters = res.result?.counters\n expect(counters).length(2)\n expect(firstCounterValue(res.result, 'event_num')).equals(1n)\n expect(counters?.[0].runtimeInfo?.from).equals(HandlerType.LOG)\n })\n\n test('Check log dispatch no buffer over rune', async () => {\n const logStr =\n '{\"address\":\"0x57e037f4d2c8bea011ad8a9a5af4aaeed508650f\",\"topics\":[\"0x5b03bfed1c14a02bdeceb5fa582eb1a5765fc0bc64ca0e6af4c20afc9487f081\"],\"data\":\"0x00000000000000000000000093269483a70c68d5c5bb63aac1e8f4ac59f498800000000000000000000000000c520e51c055cf63bab075715c1b860b2e9b8e24\",\"blockNumber\":\"0xc9d6d7\",\"transactionHash\":\"0x208af3250499672c2f07138b9aa236153c65c78ae4341b23c2763017afdd61a2\",\"transactionIndex\":\"0xf3\",\"blockHash\":\"0x6e3b100c34b510049e922fbe1c1dab1b0793be3d1229b632688e6a518cdd11b6\",\"logIndex\":\"0x14b\",\"removed\":false}'\n const res = await service.testLog(JSON.parse(logStr))\n console.log(JSON.stringify(res))\n })\n\n const logData = {\n blockNumber: 14213252,\n blockHash: '0x83d646fac9350b281def8c4c37626f9d8efc95df801287b848c719edf35cdbaf',\n transactionIndex: 347,\n removed: false,\n address: '0x1E4EDE388cbc9F4b5c79681B7f94d36a11ABEBC9',\n data: '0x00000000000000000000000000000000000000000000009a71db64810aaa0000',\n topics: [\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n '0x0000000000000000000000000000000000000000000000000000000000000000',\n '0x000000000000000000000000b329e39ebefd16f40d38f07643652ce17ca5bac1',\n ],\n transactionHash: '0x93355e0cb2c3490cb8a747029ff2dc8cdbde2407025b8391398436955afae303',\n logIndex: 428,\n }\n})\n"]}
@@ -11,11 +11,11 @@ const util_1 = require("util");
11
11
  const test_processor_server_1 = require("./test-processor-server");
12
12
  const metric_utils_1 = require("./metric-utils");
13
13
  describe('Test Solana Example', () => {
14
- const service = new test_processor_server_1.TestProcessorServer();
15
- beforeAll(async () => {
16
- await service.setup();
14
+ const service = new test_processor_server_1.TestProcessorServer(() => {
17
15
  require('./mirrorworld');
18
16
  require('./wormhole-token-bridge');
17
+ });
18
+ beforeAll(async () => {
19
19
  await service.start({ templateInstances: [] });
20
20
  });
21
21
  test('check configuration ', async () => {
@@ -1 +1 @@
1
- {"version":3,"file":"solana.test.js","sourceRoot":"","sources":["../../src/test/solana.test.ts"],"names":[],"mappings":";AAAA,gCAAgC;;;;;AAEhC,+BAA6B;AAE7B,0BAA4D;AAE5D,gDAAuB;AACvB,+BAAkC;AAClC,mEAA6D;AAC7D,iDAAkD;AAElD,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,MAAM,OAAO,GAAG,IAAI,2CAAmB,EAAE,CAAA;IAEzC,SAAS,CAAC,KAAK,IAAI,E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,OAAO,GAA+B;YAC1C,YAAY,EAAE;gBACZ;oBACE,eAAe,EAAE,EAAE;oBACnB,IAAI,EAAE,cAAI,CAAC,UAAU,CAAC,CAAC,CAAC;oBACxB,gBAAgB,EAAE,6CAA6C;oBAC/D,MAAM,EAAE,IAAI,kBAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;iBAC5D;aACF;SACF,CAAA;QACD,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAA;QACtD,IAAA,aAAM,EAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;QACtC,IAAA,aAAM,EAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;QACpC,IAAA,aAAM,EAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QACtE,IAAA,aAAM,EAAC,IAAA,gCAAiB,EAAC,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAA;QAC/E,IAAA,aAAM,EAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,eAAW,CAAC,WAAW,CAAC,CAAA;IACnF,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["// TODO move out of this package\n\nimport { expect } from 'chai'\n\nimport { HandlerType, ProcessInstructionsRequest } from '..'\n\nimport Long from 'long'\nimport { TextEncoder } from 'util'\nimport { TestProcessorServer } from './test-processor-server'\nimport { firstCounterValue } from './metric-utils'\n\ndescribe('Test Solana Example', () => {\n const service = new TestProcessorServer()\n\n beforeAll(async () => {\n await service.setup()\n require('./mirrorworld')\n require('./wormhole-token-bridge')\n await service.start({ templateInstances: [] })\n })\n\n test('check configuration ', async () => {\n const config = await service.getConfig({})\n expect(config.contractConfigs).length(3)\n })\n\n test('Check mirrorworld instruction dispatch', async () => {\n const request: ProcessInstructionsRequest = {\n instructions: [\n {\n instructionData: 'CACadoFwjNvan4GP8gh3Jtm1qdeoKX5j2SbSNEiB',\n slot: Long.fromNumber(0),\n programAccountId: 'F78NhTC9XmP1DKsCBRz5LGdQc4n4yFbj2dURiv7T9gGZ',\n },\n ],\n }\n const res = await service.processInstructions(request)\n expect(res.result?.counters).length(3)\n expect(res.result?.gauges).length(0)\n expect(firstCounterValue(res.result, 'deposit_pool_total_value')).equal(5000000000n)\n })\n\n test('Check wormhole token bridge instruction dispatch', async () => {\n const request: ProcessInstructionsRequest = {\n instructions: [\n {\n instructionData: '33G5T8yXAQWdH8FX7fTy1mBJ6e4dUKfQWbViSrT7qJjpS8UAA3ftEQx9sNzrkaJm56xtENhDsWf',\n slot: Long.fromNumber(0),\n programAccountId: 'wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb',\n },\n {\n instructionData: '33G5T8yXAQWdH8FX7fTy1mBJ6e4dUKfQWbViSrT7qJjpS8UAA3ftEQx9sNzrkaJm56xtENhDsWf',\n slot: Long.fromNumber(1),\n programAccountId: 'wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb',\n },\n ],\n }\n const res = await service.processInstructions(request)\n expect(res.result?.counters).length(2)\n expect(res.result?.gauges).length(0)\n expect(res.result?.counters[0].metadata?.blockNumber.toInt()).equal(0)\n expect(firstCounterValue(res.result, 'total_transfer_amount')).equal(1000000n)\n expect(res.result?.counters[0].runtimeInfo?.from).equals(HandlerType.INSTRUCTION)\n })\n\n test('Check SPLToken parsed instruction dispatch', async () => {\n const parsedIns = {\n info: {\n account: '2SDN4vEJdCdW3pGyhx2km9gB3LeHzMGLrG2j4uVNZfrx',\n amount: '12000000000000',\n mint: '7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs',\n mintAuthority: 'BCD75RNBHrJJpW4dXVagL5mPjzRLnVZq4YirJdjEYMV7',\n },\n type: 'mintTo',\n }\n const request: ProcessInstructionsRequest = {\n instructions: [\n {\n instructionData: '',\n slot: Long.fromNumber(0),\n programAccountId: 'wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb',\n parsed: new TextEncoder().encode(JSON.stringify(parsedIns)),\n },\n ],\n }\n const res = await service.processInstructions(request)\n expect(res.result?.counters).length(1)\n expect(res.result?.gauges).length(0)\n expect(res.result?.counters[0].metadata?.blockNumber.toInt()).equal(0)\n expect(firstCounterValue(res.result, 'totalWeth_supply')).equal(12000000000000)\n expect(res.result?.counters[0].runtimeInfo?.from).equals(HandlerType.INSTRUCTION)\n })\n})\n"]}
1
+ {"version":3,"file":"solana.test.js","sourceRoot":"","sources":["../../src/test/solana.test.ts"],"names":[],"mappings":";AAAA,gCAAgC;;;;;AAEhC,+BAA6B;AAE7B,0BAA4D;AAE5D,gDAAuB;AACvB,+BAAkC;AAClC,mEAA6D;AAC7D,iDAAkD;AAElD,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,MAAM,OAAO,GAAG,IAAI,2CAAmB,CAAC,GAAG,EAAE;QAC3C,OAAO,CAAC,eAAe,CAAC,CAAA;QACxB,OAAO,CAAC,yBAAyB,CAAC,CAAA;IACpC,CAAC,CAAC,CAAA;IAEF,SAAS,CAAC,KAAK,IAAI,EAAE;QACnB,MAAM,OAAO,CAAC,KAAK,CAAC,EAAE,iBAAiB,EAAE,EAAE,EAAE,CAAC,CAAA;IAChD,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE;QACtC,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAC1C,IAAA,aAAM,EAAC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AAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;QACtC,IAAA,aAAM,EAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;QACpC,IAAA,aAAM,EAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QACtE,IAAA,aAAM,EAAC,IAAA,gCAAiB,EAAC,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAA;QAC/E,IAAA,aAAM,EAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,eAAW,CAAC,WAAW,CAAC,CAAA;IACnF,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["// TODO move out of this package\n\nimport { expect } from 'chai'\n\nimport { HandlerType, ProcessInstructionsRequest } from '..'\n\nimport Long from 'long'\nimport { TextEncoder } from 'util'\nimport { TestProcessorServer } from './test-processor-server'\nimport { firstCounterValue } from './metric-utils'\n\ndescribe('Test Solana Example', () => {\n const service = new TestProcessorServer(() => {\n require('./mirrorworld')\n require('./wormhole-token-bridge')\n })\n\n beforeAll(async () => {\n await service.start({ templateInstances: [] })\n })\n\n test('check configuration ', async () => {\n const config = await service.getConfig({})\n expect(config.contractConfigs).length(3)\n })\n\n test('Check mirrorworld instruction dispatch', async () => {\n const request: ProcessInstructionsRequest = {\n instructions: [\n {\n instructionData: 'CACadoFwjNvan4GP8gh3Jtm1qdeoKX5j2SbSNEiB',\n slot: Long.fromNumber(0),\n programAccountId: 'F78NhTC9XmP1DKsCBRz5LGdQc4n4yFbj2dURiv7T9gGZ',\n },\n ],\n }\n const res = await service.processInstructions(request)\n expect(res.result?.counters).length(3)\n expect(res.result?.gauges).length(0)\n expect(firstCounterValue(res.result, 'deposit_pool_total_value')).equal(5000000000n)\n })\n\n test('Check wormhole token bridge instruction dispatch', async () => {\n const request: ProcessInstructionsRequest = {\n instructions: [\n {\n instructionData: '33G5T8yXAQWdH8FX7fTy1mBJ6e4dUKfQWbViSrT7qJjpS8UAA3ftEQx9sNzrkaJm56xtENhDsWf',\n slot: Long.fromNumber(0),\n programAccountId: 'wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb',\n },\n {\n instructionData: '33G5T8yXAQWdH8FX7fTy1mBJ6e4dUKfQWbViSrT7qJjpS8UAA3ftEQx9sNzrkaJm56xtENhDsWf',\n slot: Long.fromNumber(1),\n programAccountId: 'wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb',\n },\n ],\n }\n const res = await service.processInstructions(request)\n expect(res.result?.counters).length(2)\n expect(res.result?.gauges).length(0)\n expect(res.result?.counters[0].metadata?.blockNumber.toInt()).equal(0)\n expect(firstCounterValue(res.result, 'total_transfer_amount')).equal(1000000n)\n expect(res.result?.counters[0].runtimeInfo?.from).equals(HandlerType.INSTRUCTION)\n })\n\n test('Check SPLToken parsed instruction dispatch', async () => {\n const parsedIns = {\n info: {\n account: '2SDN4vEJdCdW3pGyhx2km9gB3LeHzMGLrG2j4uVNZfrx',\n amount: '12000000000000',\n mint: '7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs',\n mintAuthority: 'BCD75RNBHrJJpW4dXVagL5mPjzRLnVZq4YirJdjEYMV7',\n },\n type: 'mintTo',\n }\n const request: ProcessInstructionsRequest = {\n instructions: [\n {\n instructionData: '',\n slot: Long.fromNumber(0),\n programAccountId: 'wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb',\n parsed: new TextEncoder().encode(JSON.stringify(parsedIns)),\n },\n ],\n }\n const res = await service.processInstructions(request)\n expect(res.result?.counters).length(1)\n expect(res.result?.gauges).length(0)\n expect(res.result?.counters[0].metadata?.blockNumber.toInt()).equal(0)\n expect(firstCounterValue(res.result, 'totalWeth_supply')).equal(12000000000000)\n expect(res.result?.counters[0].runtimeInfo?.from).equals(HandlerType.INSTRUCTION)\n })\n})\n"]}
@@ -6,7 +6,7 @@ import { Networkish } from '@ethersproject/providers';
6
6
  export declare class TestProcessorServer implements ProcessorServiceImplementation {
7
7
  service: ProcessorServiceImpl;
8
8
  contractConfig: ContractConfig[];
9
- setup(httpEndpoints?: Record<string, string>): void;
9
+ constructor(loader: () => void, httpEndpoints?: Record<string, string>);
10
10
  start(request?: StartRequest, context?: CallContext): Promise<Empty>;
11
11
  stop(request: Empty, context?: CallContext): Promise<Empty>;
12
12
  getConfig(request: ProcessConfigRequest, context?: CallContext): Promise<ProcessConfigResponse>;
@@ -13,10 +13,11 @@ function cleanTest() {
13
13
  global.PROCESSOR_STATE = new sdk_1.ProcessorState();
14
14
  }
15
15
  class TestProcessorServer {
16
- service = new sdk_1.ProcessorServiceImpl();
16
+ service;
17
17
  contractConfig;
18
- setup(httpEndpoints = {}) {
18
+ constructor(loader, httpEndpoints = {}) {
19
19
  cleanTest();
20
+ this.service = new sdk_1.ProcessorServiceImpl(loader);
20
21
  const dummyConfig = {};
21
22
  for (const k in chainmap_1.CHAIN_MAP) {
22
23
  const http = httpEndpoints[k] || '';
@@ -26,12 +27,6 @@ class TestProcessorServer {
26
27
  };
27
28
  }
28
29
  (0, sdk_1.setProvider)(dummyConfig);
29
- // if (!Array.isArray(processorPath)) {
30
- // processorPath = [processorPath]
31
- // }
32
- // for (const path of processorPath) {
33
- // require(path)
34
- // }
35
30
  }
36
31
  async start(request = { templateInstances: [] }, context = TEST_CONTEXT) {
37
32
  const res = await this.service.start(request, context);
@@ -1 +1 @@
1
- {"version":3,"file":"test-processor-server.js","sourceRoot":"","sources":["../../src/test/test-processor-server.ts"],"names":[],"mappings":";;;;;;AAAA,qCAmBoB;AAIpB,gDAA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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;AAtKD,kDAsKC;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 ProcessTransactionsRequest,\n ProcessTransactionsResponse,\n setProvider,\n StartRequest,\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/chainmap'\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 = new ProcessorServiceImpl()\n contractConfig: ContractConfig[]\n\n setup(httpEndpoints: Record<string, string> = {}) {\n cleanTest()\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 // if (!Array.isArray(processorPath)) {\n // processorPath = [processorPath]\n // }\n // for (const path of processorPath) {\n // require(path)\n // }\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 processTransactions(\n request: ProcessTransactionsRequest,\n context = TEST_CONTEXT\n ): Promise<ProcessTransactionsResponse> {\n return this.service.processTransactions(request, context)\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/test/test-processor-server.ts"],"names":[],"mappings":";;;;;;AAAA,qCAmBoB;AAIpB,gDAA6C;AAE7C,gDAAuB;AACvB,wDAAiE;AAEjE,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,IAAI,0BAAoB,CAAC,MAAM,CAAC,CAAA;QAC/C,MAAM,WAAW,GAAgC,EAAE,CAAA;QAEnD,KAAK,MAAM,CAAC,IAAI,oBAAS,EAAE;YACzB,MAAM,IAAI,GAAG,aAAa,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;YACnC,WAAW,CAAC,CAAC,CAAC,GAAG;gBACf,OAAO,EAAE,CAAC;gBACV,KAAK,EAAE,CAAC,IAAI,CAAC;aACd,CAAA;SACF;QAED,IAAA,iBAAW,EAAC,WAAW,CAAC,CAAA;IAC1B,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,UAAwB,EAAE,iBAAiB,EAAE,EAAE,EAAE,EAAE,OAAO,GAAG,YAAY;QACnF,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACtD,IAAI,CAAC,cAAc,GAAG,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,eAAe,CAAA;QAChE,OAAO,GAAG,CAAA;IACZ,CAAC;IAED,IAAI,CAAC,OAAc,EAAE,OAAO,GAAG,YA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AAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;YACrD,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;AAjKD,kDAiKC;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 ProcessTransactionsRequest,\n ProcessTransactionsResponse,\n setProvider,\n StartRequest,\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/chainmap'\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<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 processTransactions(\n request: ProcessTransactionsRequest,\n context = TEST_CONTEXT\n ): Promise<ProcessTransactionsResponse> {\n return this.service.processTransactions(request, context)\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"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sentio/sdk",
3
3
  "license": "Apache-2.0",
4
- "version": "1.7.15",
4
+ "version": "1.7.16",
5
5
  "scripts": {
6
6
  "compile_target": "yarn tsc -b src/target-ethers-sentio/tsconfig.json",
7
7
  "compile": "tsc -p . && cp src/cli/webpack.config.js lib/cli",
package/src/loader.ts ADDED
@@ -0,0 +1,24 @@
1
+ export function load(name: string): { module: any; name: string; path: string } | undefined {
2
+ const req = eval('require')
3
+
4
+ try {
5
+ let path: string
6
+ try {
7
+ path = req.resolve(name, { paths: [process.cwd()] })
8
+ } catch {
9
+ path = req.resolve(name)
10
+ }
11
+
12
+ const module = { module: req(path), name, path }
13
+ console.log('Load successfully: ', name)
14
+ return module
15
+ } catch (err) {
16
+ if (err instanceof Error && err.message.startsWith(`Cannot find module '${name}'`)) {
17
+ // this error is expected
18
+ console.log("Couldn't load (expected): ", name)
19
+ return undefined
20
+ } else {
21
+ throw err
22
+ }
23
+ }
24
+ }
@@ -9,35 +9,11 @@ import { setProvider } from './provider'
9
9
  import path from 'path'
10
10
  import fs from 'fs-extra'
11
11
  import { ProcessorState } from './processor-state'
12
+ import { load } from './loader'
12
13
 
13
14
  global.sentio_sdk = require('.')
14
15
  global.PROCESSOR_STATE = new ProcessorState()
15
16
 
16
- function tryRequire(name: string): { module: any; name: string; path: string } | undefined {
17
- const req = eval('require')
18
-
19
- try {
20
- let path: string
21
- try {
22
- path = req.resolve(name, { paths: [process.cwd()] })
23
- } catch {
24
- path = req.resolve(name)
25
- }
26
-
27
- const module = { module: req(path), name, path }
28
- console.log('Load successfully: ', name)
29
- return module
30
- } catch (err) {
31
- if (err instanceof Error && err.message.startsWith(`Cannot find module '${name}'`)) {
32
- // this error is expected
33
- console.log("Couldn't load (expected): ", name)
34
- return undefined
35
- } else {
36
- throw err
37
- }
38
- }
39
- }
40
-
41
17
  const optionDefinitions = [
42
18
  { name: 'target', type: String, defaultOption: true },
43
19
  { name: 'port', alias: 'p', type: String, defaultValue: '4000' },
@@ -60,8 +36,6 @@ const chainsConfig = fs.readJsonSync(fullPath)
60
36
 
61
37
  setProvider(chainsConfig, options.concurrency, options['use-chainserver'])
62
38
 
63
- tryRequire(options.target)
64
-
65
39
  console.log('Start Server', options)
66
40
 
67
41
  console.log(global.PROCESSOR_STATE.processors.length, ' processors loaded')
@@ -69,7 +43,7 @@ console.log(global.PROCESSOR_STATE.solanaProcessors.length, ' solana processors
69
43
 
70
44
  const server = createServer()
71
45
 
72
- const service = new ProcessorServiceImpl(server.shutdown)
46
+ const service = new ProcessorServiceImpl(() => load(options.target), server.shutdown)
73
47
  server.add(ProcessorDefinition, service)
74
48
 
75
49
  server.listen('0.0.0.0:' + options.port)
package/src/service.ts CHANGED
@@ -40,10 +40,12 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
40
40
  private started = false
41
41
  private contractConfigs: ContractConfig[]
42
42
  private templateInstances: TemplateInstance[]
43
+ private readonly loader: () => void
43
44
 
44
45
  private readonly shutdownHandler?: () => void
45
46
 
46
- constructor(shutdownHandler?: () => void) {
47
+ constructor(loader: () => void, shutdownHandler?: () => void) {
48
+ this.loader = loader
47
49
  this.shutdownHandler = shutdownHandler
48
50
  }
49
51
 
@@ -151,8 +153,8 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
151
153
  endBlock: DEFAULT_MAX_BLOCK,
152
154
  instructionConfig: {
153
155
  innerInstruction: solanaProcessor.processInnerInstruction,
154
- parsedInstruction: solanaProcessor.fromParsedInstruction != null ? true : false,
155
- rawDataInstruction: solanaProcessor.decodeInstruction != null ? true : false,
156
+ parsedInstruction: solanaProcessor.fromParsedInstruction !== null,
157
+ rawDataInstruction: solanaProcessor.decodeInstruction !== null,
156
158
  },
157
159
  }
158
160
  this.contractConfigs.push(contractConfig)
@@ -163,6 +165,9 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
163
165
  if (this.started) {
164
166
  return {}
165
167
  }
168
+
169
+ this.loader()
170
+
166
171
  for (const instance of request.templateInstances) {
167
172
  const template = global.PROCESSOR_STATE.templates[instance.templateId]
168
173
  if (!template) {
@@ -7,11 +7,9 @@ import Long from 'long'
7
7
  import { TestProcessorServer } from './test-processor-server'
8
8
 
9
9
  describe('Test Template', () => {
10
- const service = new TestProcessorServer()
10
+ const service = new TestProcessorServer(() => require('./erc20-template'))
11
11
 
12
12
  beforeAll(async () => {
13
- service.setup()
14
- require('./erc20-template')
15
13
  const request: StartRequest = {
16
14
  templateInstances: [
17
15
  {
@@ -10,11 +10,9 @@ import { BigNumber } from 'ethers'
10
10
  import { mockTransferLog } from '../builtin/erc20/test-utils'
11
11
 
12
12
  describe('Test Basic Examples', () => {
13
- const service = new TestProcessorServer()
13
+ const service = new TestProcessorServer(() => require('./erc20'))
14
14
 
15
15
  beforeAll(async () => {
16
- service.setup()
17
- require('./erc20')
18
16
  await service.start()
19
17
  })
20
18
 
@@ -9,11 +9,7 @@ import { TestProcessorServer } from './test-processor-server'
9
9
  import { firstCounterValue } from './metric-utils'
10
10
 
11
11
  describe('Test Generic Processor', () => {
12
- const service = new TestProcessorServer()
13
-
14
- beforeAll(async () => {
15
- service.setup()
16
-
12
+ const service = new TestProcessorServer(() => {
17
13
  GenericProcessor.bind(
18
14
  [
19
15
  'event Transfer(address indexed from, address indexed to, uint256 value)',
@@ -29,7 +25,9 @@ describe('Test Generic Processor', () => {
29
25
  }).onAllEvents(function (log, ctx) {
30
26
  ctx.meter.Counter('wallet').add(1)
31
27
  })
28
+ })
32
29
 
30
+ beforeAll(async () => {
33
31
  await service.start()
34
32
  })
35
33
 
@@ -10,12 +10,12 @@ import { TestProcessorServer } from './test-processor-server'
10
10
  import { firstCounterValue } from './metric-utils'
11
11
 
12
12
  describe('Test Solana Example', () => {
13
- const service = new TestProcessorServer()
14
-
15
- beforeAll(async () => {
16
- await service.setup()
13
+ const service = new TestProcessorServer(() => {
17
14
  require('./mirrorworld')
18
15
  require('./wormhole-token-bridge')
16
+ })
17
+
18
+ beforeAll(async () => {
19
19
  await service.start({ templateInstances: [] })
20
20
  })
21
21
 
@@ -33,11 +33,13 @@ function cleanTest() {
33
33
  }
34
34
 
35
35
  export class TestProcessorServer implements ProcessorServiceImplementation {
36
- service = new ProcessorServiceImpl()
36
+ service: ProcessorServiceImpl
37
37
  contractConfig: ContractConfig[]
38
38
 
39
- setup(httpEndpoints: Record<string, string> = {}) {
39
+ constructor(loader: () => void, httpEndpoints: Record<string, string> = {}) {
40
40
  cleanTest()
41
+
42
+ this.service = new ProcessorServiceImpl(loader)
41
43
  const dummyConfig: Record<string, ChainConfig> = {}
42
44
 
43
45
  for (const k in CHAIN_MAP) {
@@ -49,13 +51,6 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
49
51
  }
50
52
 
51
53
  setProvider(dummyConfig)
52
-
53
- // if (!Array.isArray(processorPath)) {
54
- // processorPath = [processorPath]
55
- // }
56
- // for (const path of processorPath) {
57
- // require(path)
58
- // }
59
54
  }
60
55
 
61
56
  async start(request: StartRequest = { templateInstances: [] }, context = TEST_CONTEXT): Promise<Empty> {