@sentio/sdk 1.8.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/service.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CallContext } from 'nice-grpc';
2
- import { BlockBinding, O11yResult, ProcessBlocksRequest, ProcessBlocksResponse, ProcessConfigRequest, ProcessConfigResponse, ProcessInstructionsRequest, ProcessInstructionsResponse, ProcessLogsRequest, ProcessLogsResponse, ProcessorServiceImplementation, ProcessTracesRequest, ProcessTracesResponse, ProcessTransactionsRequest, ProcessTransactionsResponse, StartRequest } from './gen/processor/protos/processor';
2
+ import { BlockBinding, ProcessResult, ProcessBlocksRequest, ProcessBlocksResponse, ProcessConfigRequest, ProcessConfigResponse, ProcessInstructionsRequest, ProcessInstructionsResponse, ProcessLogsRequest, ProcessLogsResponse, ProcessorServiceImplementation, ProcessTracesRequest, ProcessTracesResponse, ProcessTransactionsRequest, ProcessTransactionsResponse, StartRequest } from './gen/processor/protos/processor';
3
3
  import { Empty } from './gen/google/protobuf/empty';
4
4
  export declare class ProcessorServiceImpl implements ProcessorServiceImplementation {
5
5
  private eventHandlers;
@@ -18,6 +18,6 @@ export declare class ProcessorServiceImpl implements ProcessorServiceImplementat
18
18
  processTransactions(request: ProcessTransactionsRequest, context: CallContext): Promise<ProcessTransactionsResponse>;
19
19
  processInstructions(request: ProcessInstructionsRequest, context: CallContext): Promise<ProcessInstructionsResponse>;
20
20
  processBlocks(request: ProcessBlocksRequest, context: CallContext): Promise<ProcessBlocksResponse>;
21
- processBlock(binding: BlockBinding): Promise<O11yResult>;
21
+ processBlock(binding: BlockBinding): Promise<ProcessResult>;
22
22
  processTraces(request: ProcessTracesRequest, context: CallContext): Promise<ProcessTracesResponse>;
23
23
  }
package/lib/service.js CHANGED
@@ -13,7 +13,7 @@ class ProcessorServiceImpl {
13
13
  eventHandlers = [];
14
14
  blockHandlers = [];
15
15
  // map from chain id to list of processors
16
- // private blockHandlers = new Map<string, ((block: Block) => Promise<O11yResult>)[]>()
16
+ // private blockHandlers = new Map<string, ((block: Block) => Promise<ProcessResult>)[]>()
17
17
  // private processorsByChainId = new Map<string, BaseProcessor<BaseContract, BoundContractView<BaseContract, any>>>()
18
18
  started = false;
19
19
  contractConfigs;
@@ -165,6 +165,7 @@ class ProcessorServiceImpl {
165
165
  const resp = {
166
166
  gauges: [],
167
167
  counters: [],
168
+ logs: [],
168
169
  };
169
170
  const promises = [];
170
171
  for (const l of request.logBindings) {
@@ -216,6 +217,7 @@ class ProcessorServiceImpl {
216
217
  const result = {
217
218
  gauges: [],
218
219
  counters: [],
220
+ logs: [],
219
221
  };
220
222
  // Only have instruction handlers for solana processors
221
223
  if (global.PROCESSOR_STATE.solanaProcessors) {
@@ -277,7 +279,7 @@ class ProcessorServiceImpl {
277
279
  }
278
280
  const promises = request.blockBindings.map((binding) => this.processBlock(binding));
279
281
  const results = await Promise.all(promises);
280
- const res = processor_1.O11yResult.fromPartial({});
282
+ const res = processor_1.ProcessResult.fromPartial({});
281
283
  for (const r of results) {
282
284
  res.counters = res.counters.concat(r.counters);
283
285
  res.gauges = res.gauges.concat(r.gauges);
@@ -296,6 +298,7 @@ class ProcessorServiceImpl {
296
298
  const resp = {
297
299
  gauges: [],
298
300
  counters: [],
301
+ logs: [],
299
302
  };
300
303
  const promises = [];
301
304
  for (const handlerId of binding.handlerIds) {
@@ -1 +1 @@
1
- {"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":";;;;;;AACA,yCAA4D;AAE5D,gEAsByC;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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C,CAAC,EAAE,CAAC,CAAA;gBAClB,GAAG,IAAI,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,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 ProcessTracesRequest,\n ProcessTracesResponse,\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 async processTraces(request: ProcessTracesRequest, context: CallContext): Promise<ProcessTracesResponse> {\n return {\n result: undefined,\n }\n }\n}\n\n// https://ourcodeworld.com/articles/read/164/how-to-convert-an-uint8array-to-string-in-javascript\n/* eslint-disable */\nfunction Utf8ArrayToStr(array: Uint8Array) {\n let out, i, len, c\n let char2, char3\n\n out = ''\n len = array.length\n i = 0\n while (i < len) {\n c = array[i++]\n switch (c >> 4) {\n case 0:\n case 1:\n case 2:\n case 3:\n case 4:\n case 5:\n case 6:\n case 7:\n // 0xxxxxxx\n out += String.fromCharCode(c)\n break\n case 12:\n case 13:\n // 110x xxxx 10xx xxxx\n char2 = array[i++]\n out += String.fromCharCode(((c & 0x1f) << 6) | (char2 & 0x3f))\n break\n case 14:\n // 1110 xxxx 10xx xxxx 10xx xxxx\n char2 = array[i++]\n char3 = array[i++]\n out += String.fromCharCode(((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0))\n break\n }\n }\n\n return out\n}\n\nfunction 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":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YACR,KAAK,EAAE;gBACL,wBAAwB;gBACxB,KAAK,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAAA;gBAClB,GAAG,IAAI,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAA;gBAC9D,MAAK;YACP,KAAK,EAAE;gBACL,kCAAkC;gBAClC,KAAK,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAAA;gBAClB,KAAK,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAAA;gBAClB,GAAG,IAAI,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,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,OAAsB,EAAE,WAAwB;IACzE,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QAC3B,CAAC,CAAC,WAAW,GAAG;YACd,IAAI,EAAE,WAAW;SAClB,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QAC7B,CAAC,CAAC,WAAW,GAAG;YACd,IAAI,EAAE,WAAW;SAClB,CAAA;IACH,CAAC,CAAC,CAAA;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 ProcessResult,\n ProcessBlocksRequest,\n ProcessBlocksResponse,\n ProcessConfigRequest,\n ProcessConfigResponse,\n ProcessInstructionsRequest,\n ProcessInstructionsResponse,\n ProcessLogsRequest,\n ProcessLogsResponse,\n ProcessorServiceImplementation,\n ProcessTracesRequest,\n ProcessTracesResponse,\n ProcessTransactionsRequest,\n ProcessTransactionsResponse,\n StartRequest,\n TemplateInstance,\n} 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<ProcessResult>)[] = []\n private blockHandlers: ((block: Block) => Promise<ProcessResult>)[] = []\n\n // map from chain id to list of processors\n // private blockHandlers = new Map<string, ((block: Block) => Promise<ProcessResult>)[]>()\n // private processorsByChainId = new Map<string, BaseProcessor<BaseContract, BoundContractView<BaseContract, any>>>()\n\n private started = false\n private contractConfigs: ContractConfig[]\n private templateInstances: TemplateInstance[]\n private readonly loader: () => void\n\n private readonly shutdownHandler?: () => void\n\n constructor(loader: () => void, shutdownHandler?: () => void) {\n this.loader = loader\n this.shutdownHandler = shutdownHandler\n }\n\n async getConfig(request: ProcessConfigRequest, context: CallContext): Promise<ProcessConfigResponse> {\n if (!this.started) {\n throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')\n }\n return {\n // TODO project setting\n config: undefined,\n contractConfigs: this.contractConfigs,\n templateInstances: this.templateInstances,\n }\n }\n\n async configure() {\n this.eventHandlers = []\n this.templateInstances = []\n // this.processorsByChainId.clear()\n this.contractConfigs = []\n\n this.templateInstances = [...global.PROCESSOR_STATE.templatesInstances]\n\n // Part 1, prepare EVM processors\n for (const processor of global.PROCESSOR_STATE.processors) {\n // If server favor incremental update this need to change\n // Start basic config for contract\n const chainId = processor.getChainId()\n // this.processorsByChainId.set(chainId, processor)\n\n const contractConfig: ContractConfig = {\n processorType: 'user_processor',\n contract: {\n name: processor.config.name,\n chainId: chainId.toString(),\n address: processor.config.address,\n abi: '',\n },\n blockConfigs: [],\n logConfigs: [],\n 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: ProcessResult = {\n gauges: [],\n counters: [],\n logs: [],\n }\n\n const promises: Promise<ProcessResult>[] = []\n for (const l of request.logBindings) {\n if (!l.log) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Log can't be null\")\n }\n // const jsonString = Buffer.from(l.log.raw.buffer).toString(\"utf-8\")\n // const jsonString = String.fromCharCode.apply(null, l.log.raw)\n\n try {\n const jsonString = Utf8ArrayToStr(l.log.raw)\n const log: Log = JSON.parse(jsonString)\n const handler = this.eventHandlers[l.handlerId]\n const promise = handler(log).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing log: ' + jsonString + '\\n' + 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: ProcessResult = {\n gauges: [],\n counters: [],\n logs: [],\n }\n\n // Only have instruction handlers for solana processors\n if (global.PROCESSOR_STATE.solanaProcessors) {\n const processorPromises: Promise<void>[] = []\n for (const instruction of request.instructions) {\n if (!instruction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'instruction cannot be null')\n }\n\n processorPromises.push(\n new Promise((resolve, _) => {\n for (const processor of global.PROCESSOR_STATE.solanaProcessors) {\n if (processor.address === instruction.programAccountId) {\n let res: ProcessResult | null\n if (instruction.parsed) {\n res = processor.handleInstruction(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 = ProcessResult.fromPartial({})\n\n for (const r of results) {\n res.counters = res.counters.concat(r.counters)\n res.gauges = res.gauges.concat(r.gauges)\n }\n\n recordRuntimeInfo(res, HandlerType.BLOCK)\n return {\n result: res,\n }\n }\n\n async processBlock(binding: BlockBinding): Promise<ProcessResult> {\n if (!binding.block) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Block can't be empty\")\n }\n const jsonString = Utf8ArrayToStr(binding.block.raw)\n\n const block: Block = JSON.parse(jsonString)\n\n const resp: ProcessResult = {\n gauges: [],\n counters: [],\n logs: [],\n }\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n const promise = this.blockHandlers[handlerId](block).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing block: ' + block.number + '\\n' + 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 async processTraces(request: ProcessTracesRequest, context: CallContext): Promise<ProcessTracesResponse> {\n return {\n result: undefined,\n }\n }\n}\n\n// https://ourcodeworld.com/articles/read/164/how-to-convert-an-uint8array-to-string-in-javascript\n/* eslint-disable */\nfunction Utf8ArrayToStr(array: Uint8Array) {\n let out, i, len, c\n let char2, char3\n\n out = ''\n len = array.length\n i = 0\n while (i < len) {\n c = array[i++]\n switch (c >> 4) {\n case 0:\n case 1:\n case 2:\n case 3:\n case 4:\n case 5:\n case 6:\n case 7:\n // 0xxxxxxx\n out += String.fromCharCode(c)\n break\n case 12:\n case 13:\n // 110x xxxx 10xx xxxx\n char2 = array[i++]\n out += String.fromCharCode(((c & 0x1f) << 6) | (char2 & 0x3f))\n break\n case 14:\n // 1110 xxxx 10xx xxxx 10xx xxxx\n char2 = array[i++]\n char3 = array[i++]\n out += String.fromCharCode(((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0))\n break\n }\n }\n\n return out\n}\n\nfunction recordRuntimeInfo(results: ProcessResult, handlerType: HandlerType) {\n results.gauges.forEach((e) => {\n e.runtimeInfo = {\n from: handlerType,\n }\n })\n\n results.counters.forEach((e) => {\n e.runtimeInfo = {\n from: handlerType,\n }\n })\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { O11yResult } from './gen/processor/protos/processor';
1
+ import { ProcessResult } from './gen/processor/protos/processor';
2
2
  import { SolanaContext } from './context';
3
3
  import Long from 'long';
4
4
  import { Instruction } from '@project-serum/anchor';
@@ -26,7 +26,7 @@ export declare class SolanaBaseProcessor {
26
26
  handleInstruction(ins: string | {
27
27
  type: string;
28
28
  info: any;
29
- }): O11yResult | null;
29
+ }): ProcessResult | null;
30
30
  isBind(): boolean;
31
31
  startSlot(startSlot: Long | number): this;
32
32
  endBlock(endBlock: Long | number): this;
@@ -70,6 +70,7 @@ class SolanaBaseProcessor {
70
70
  return {
71
71
  gauges: ctx.gauges,
72
72
  counters: ctx.counters,
73
+ logs: [],
73
74
  };
74
75
  }
75
76
  isBind() {
@@ -1 +1 @@
1
- {"version":3,"file":"solana-processor.js","sourceRoot":"","sources":["../src/solana-processor.ts"],"names":[],"mappings":";;;;;;AACA,uCAAyC;AACzC,gDAAuB;AASvB,MAAa,mBAAmB;IACvB,qBAAqB,GAAwE,IAAI,GAAG,EAAE,CAAA;IAC7G,OAAO,CAAQ;IACf,QAAQ,CAAQ;IAChB,YAAY,CAAQ;IACpB,uBAAuB,CAAS;IAChC,MAAM,GAAmB,EAAE,SAAS,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC,EAAE,CAAA;IACnD,iBAAiB,CAAgD;IACjE,qBAAqB,CAAkE;IAEvF,YAAY,OAA0B;QACp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from './context'\nimport Long from 'long'\nimport { Instruction } from '@project-serum/anchor'\nimport { SolanaBindOptions } from './bind-options'\n\ntype IndexConfigure = {\n startSlot: Long\n endSlot?: Long\n}\n\nexport class SolanaBaseProcessor {\n public instructionHanlderMap: Map<string, (instruction: Instruction, ctx: SolanaContext) => void> = new Map()\n address: string\n endpoint: string\n contractName: string\n processInnerInstruction: boolean\n config: IndexConfigure = { startSlot: new Long(0) }\n decodeInstruction: (rawInstruction: string) => Instruction | null\n fromParsedInstruction: (instruction: { type: string; info: any }) => Instruction | null\n\n constructor(options: SolanaBindOptions) {\n if (options) {\n this.bind(options)\n }\n global.PROCESSOR_STATE.solanaProcessors.push(this)\n }\n\n bind(options: SolanaBindOptions) {\n this.address = options.address\n this.contractName = options.name || ''\n this.processInnerInstruction = options.processInnerInstruction || false\n if (options.startBlock) {\n this.startSlot(options.startBlock)\n }\n if (options.endBlock) {\n this.endBlock(options.endBlock)\n }\n this.endpoint = options.network || 'https://api.mainnet-beta.solana.com'\n }\n\n innerInstruction(flag: boolean) {\n this.processInnerInstruction = flag\n return this\n }\n\n public onInstruction(instructionName: string, handler: (instruction: Instruction, ctx: SolanaContext) => void) {\n if (!this.isBind()) {\n throw new Error(\"Processor doesn't bind to an address\")\n }\n\n this.instructionHanlderMap.set(instructionName, handler)\n\n return this\n }\n\n public handleInstruction(ins: string | { type: string; info: any }): O11yResult | null {\n const ctx = new SolanaContext(this.address)\n let parsedInstruction: Instruction | null = null\n\n if (ins) {\n if ((ins as { type: string; info: any }).info) {\n if (this.fromParsedInstruction == null) {\n return null\n }\n parsedInstruction = this.fromParsedInstruction(ins as { type: string; info: any })\n } else {\n if (this.decodeInstruction == null) {\n return null\n }\n parsedInstruction = this.decodeInstruction(ins as string)\n }\n if (parsedInstruction) {\n const handler = this.instructionHanlderMap.get(parsedInstruction.name)\n if (handler) {\n handler(parsedInstruction, ctx)\n }\n }\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n }\n }\n\n public isBind() {\n return this.address !== null\n }\n\n public startSlot(startSlot: Long | number) {\n if (typeof startSlot === 'number') {\n startSlot = Long.fromNumber(startSlot)\n }\n this.config.startSlot = startSlot\n return this\n }\n\n public endBlock(endBlock: Long | number) {\n if (typeof endBlock === 'number') {\n endBlock = Long.fromNumber(endBlock)\n }\n this.config.endSlot = endBlock\n return this\n }\n}\n"]}
1
+ {"version":3,"file":"solana-processor.js","sourceRoot":"","sources":["../src/solana-processor.ts"],"names":[],"mappings":";;;;;;AACA,uCAAyC;AACzC,gDAAuB;AASvB,MAAa,mBAAmB;IACvB,qBAAqB,GAAwE,IAAI,GAAG,EAAE,CAAA;IAC7G,OAAO,CAAQ;IACf,QAAQ,CAAQ;IAChB,YAAY,CAAQ;IACpB,uBAAuB,CAAS;IAChC,MAAM,GAAmB,EAAE,SAAS,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC,EAAE,CAAA;IACnD,iBAAiB,CAAgD;IACjE,qBAAqB,CAAkE;IAEvF,YAAY,OAA0B;QACpC,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SACnB;QACD,MAAM,CAAC,eAAe,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACpD,CAAC;IAED,IAAI,CAAC,OAA0B;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;QAC9B,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,IAAI,IAAI,EAAE,CAAA;QACtC,IAAI,CAAC,uBAAuB,GAAG,OAAO,CAAC,uBAAuB,IAAI,KAAK,CAAA;QACvE,IAAI,OAAO,CAAC,UAAU,EAAE;YACtB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;SACnC;QACD,IAAI,OAAO,CAAC,QAAQ,EAAE;YACpB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;SAChC;QACD,IAAI,CAAC,QAAQ,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AAQ;YACtB,IAAI,EAAE,EAAE;SACT,CAAA;IACH,CAAC;IAEM,MAAM;QACX,OAAO,IAAI,CAAC,OAAO,KAAK,IAAI,CAAA;IAC9B,CAAC;IAEM,SAAS,CAAC,SAAwB;QACvC,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;YACjC,SAAS,GAAG,cAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;SACvC;QACD,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,SAAS,CAAA;QACjC,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,QAAQ,CAAC,QAAuB;QACrC,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;YAChC,QAAQ,GAAG,cAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;SACrC;QACD,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAA;QAC9B,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA9FD,kDA8FC","sourcesContent":["import { ProcessResult } from './gen/processor/protos/processor'\nimport { SolanaContext } from './context'\nimport Long from 'long'\nimport { Instruction } from '@project-serum/anchor'\nimport { SolanaBindOptions } from './bind-options'\n\ntype IndexConfigure = {\n startSlot: Long\n endSlot?: Long\n}\n\nexport class SolanaBaseProcessor {\n public instructionHanlderMap: Map<string, (instruction: Instruction, ctx: SolanaContext) => void> = new Map()\n address: string\n endpoint: string\n contractName: string\n processInnerInstruction: boolean\n config: IndexConfigure = { startSlot: new Long(0) }\n decodeInstruction: (rawInstruction: string) => Instruction | null\n fromParsedInstruction: (instruction: { type: string; info: any }) => Instruction | null\n\n constructor(options: SolanaBindOptions) {\n if (options) {\n this.bind(options)\n }\n global.PROCESSOR_STATE.solanaProcessors.push(this)\n }\n\n bind(options: SolanaBindOptions) {\n this.address = options.address\n this.contractName = options.name || ''\n this.processInnerInstruction = options.processInnerInstruction || false\n if (options.startBlock) {\n this.startSlot(options.startBlock)\n }\n if (options.endBlock) {\n this.endBlock(options.endBlock)\n }\n this.endpoint = options.network || 'https://api.mainnet-beta.solana.com'\n }\n\n innerInstruction(flag: boolean) {\n this.processInnerInstruction = flag\n return this\n }\n\n public onInstruction(instructionName: string, handler: (instruction: Instruction, ctx: SolanaContext) => void) {\n if (!this.isBind()) {\n throw new Error(\"Processor doesn't bind to an address\")\n }\n\n this.instructionHanlderMap.set(instructionName, handler)\n\n return this\n }\n\n public handleInstruction(ins: string | { type: string; info: any }): ProcessResult | null {\n const ctx = new SolanaContext(this.address)\n let parsedInstruction: Instruction | null = null\n\n if (ins) {\n if ((ins as { type: string; info: any }).info) {\n if (this.fromParsedInstruction == null) {\n return null\n }\n parsedInstruction = this.fromParsedInstruction(ins as { type: string; info: any })\n } else {\n if (this.decodeInstruction == null) {\n return null\n }\n parsedInstruction = this.decodeInstruction(ins as string)\n }\n if (parsedInstruction) {\n const handler = this.instructionHanlderMap.get(parsedInstruction.name)\n if (handler) {\n handler(parsedInstruction, ctx)\n }\n }\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: [],\n }\n }\n\n public isBind() {\n return this.address !== null\n }\n\n public startSlot(startSlot: Long | number) {\n if (typeof startSlot === 'number') {\n startSlot = Long.fromNumber(startSlot)\n }\n this.config.startSlot = startSlot\n return this\n }\n\n public endBlock(endBlock: Long | number) {\n if (typeof endBlock === 'number') {\n endBlock = Long.fromNumber(endBlock)\n }\n this.config.endSlot = endBlock\n return this\n }\n}\n"]}
@@ -22,19 +22,17 @@ describe('Test Basic Examples', () => {
22
22
  (0, chai_1.expect)(config.contractConfigs?.[4].contract?.name).equals('ERC20_1');
23
23
  });
24
24
  test('Check block dispatch', async () => {
25
- const res = await service.testBlock(blockData);
26
- const o11yRes = res.result;
27
- (0, chai_1.expect)(o11yRes?.counters).length(0);
28
- (0, chai_1.expect)(o11yRes?.gauges).length(1);
29
- (0, chai_1.expect)((0, metric_utils_1.firstGaugeValue)(o11yRes, 'g1')).equals(10n);
30
- const gauge = o11yRes?.gauges?.[0];
25
+ const res = (await service.testBlock(blockData)).result;
26
+ (0, chai_1.expect)(res?.counters).length(0);
27
+ (0, chai_1.expect)(res?.gauges).length(1);
28
+ (0, chai_1.expect)((0, metric_utils_1.firstGaugeValue)(res, 'g1')).equals(10n);
29
+ const gauge = res?.gauges?.[0];
31
30
  (0, chai_1.expect)(gauge?.metadata?.blockNumber?.toString()).equals('14373295');
32
31
  (0, chai_1.expect)(gauge?.runtimeInfo?.from).equals(__1.HandlerType.BLOCK);
33
- const res2 = await service.testBlock(blockData, 56);
34
- const o11yRes2 = res2.result;
35
- (0, chai_1.expect)(o11yRes2?.counters).length(0);
36
- (0, chai_1.expect)(o11yRes2?.gauges).length(1);
37
- (0, chai_1.expect)((0, metric_utils_1.firstGaugeValue)(o11yRes2, 'g2')).equals(20n);
32
+ const res2 = (await service.testBlock(blockData, 56)).result;
33
+ (0, chai_1.expect)(res2?.counters).length(0);
34
+ (0, chai_1.expect)(res2?.gauges).length(1);
35
+ (0, chai_1.expect)((0, metric_utils_1.firstGaugeValue)(res2, 'g2')).equals(20n);
38
36
  });
39
37
  test('Check log dispatch', async () => {
40
38
  const logData = (0, test_utils_1.mockTransferLog)('0x1E4EDE388cbc9F4b5c79681B7f94d36a11ABEBC9', {
@@ -1 +1 @@
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,EAA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AA;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"]}
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,I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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)).result\n expect(res?.counters).length(0)\n expect(res?.gauges).length(1)\n expect(firstGaugeValue(res, 'g1')).equals(10n)\n\n const gauge = res?.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)).result\n expect(res2?.counters).length(0)\n expect(res2?.gauges).length(1)\n expect(firstGaugeValue(res2, '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,6 +1,6 @@
1
1
  import { DeepPartial } from '../gen/builtin';
2
- import { MetricValue, O11yResult } from '@sentio/sdk';
2
+ import { MetricValue, ProcessResult } from '@sentio/sdk';
3
3
  import { Numberish } from '../numberish';
4
4
  export declare function MetricValueToNumber(v: DeepPartial<MetricValue> | undefined): Numberish | undefined;
5
- export declare function firstCounterValue(result: O11yResult | undefined, name: string): Numberish | undefined;
6
- export declare function firstGaugeValue(result: O11yResult | undefined, name: string): Numberish | undefined;
5
+ export declare function firstCounterValue(result: ProcessResult | undefined, name: string): Numberish | undefined;
6
+ export declare function firstGaugeValue(result: ProcessResult | undefined, name: string): Numberish | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"metric-utils.js","sourceRoot":"","sources":["../../src/test/metric-utils.ts"],"names":[],"mappings":";;;AACA,qCAAiE;AAEjE,mCAAkC;AAElC,SAAgB,mBAAmB,CAAC,CAAuC;IACzE,IAAI,CAAC,KAAK,SAAS,EAAE;QACnB,OAAO,SAAS,CAAA;KACjB;IAED,IAAI,CAAC,CAAC,WAAW,KAAK,SAAS,EAAE;QAC/B,OAAO,CAAC,CAAC,WAAW,CAAA;KACrB;IACD,IAAI,CAAC,CAAC,UAAU,KAAK,SAAS,EAAE;QAC9B,IAAI,QAAQ,GAAG,kBAAS,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAA;QAC3D,IAAI,CAAC,CAAC,UAAU,CAAC,QAAQ,EAAE;YACzB,QAAQ,GAAG,CAAC,QAAQ,CAAA;SACrB;QACD,OAAO,QAAQ,CAAA;KAChB;IACD,IAAI,CAAC,CAAC,UAAU,KAAK,SAAS,EAAE;QAC9B,OAAO,IAAI,gBAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAA;KACpC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAnBD,kDAmBC;AAED,SAAgB,iBAAiB,CAAC,MAA8B,EAAE,IAAY;IAC5E,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,SAAS,CAAA;KACjB;IACD,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,QAAQ,EAAE;QACrC,IAAI,OAAO,CAAC,QAAQ,EAAE,IAAI,KAAK,IAAI,EAAE;YACnC,OAAO,mBAAmB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;SAChD;KACF;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAVD,8CAUC;AAED,SAAgB,eAAe,CAAC,MAA8B,EAAE,IAAY;IAC1E,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,SAAS,CAAA;KACjB;IACD,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE;QACjC,IAAI,KAAK,CAAC,QAAQ,EAAE,IAAI,KAAK,IAAI,EAAE;YACjC,OAAO,mBAAmB,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;SAC9C;KACF;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAVD,0CAUC","sourcesContent":["import { DeepPartial } from '../gen/builtin'\nimport { BigDecimal, MetricValue, O11yResult } from '@sentio/sdk'\nimport { Numberish } from '../numberish'\nimport { BigNumber } from 'ethers'\n\nexport function MetricValueToNumber(v: DeepPartial<MetricValue> | undefined): Numberish | undefined {\n if (v === undefined) {\n return undefined\n }\n\n if (v.doubleValue !== undefined) {\n return v.doubleValue\n }\n if (v.bigInteger !== undefined) {\n let intValue = BigNumber.from(v.bigInteger.data).toBigInt()\n if (v.bigInteger.negative) {\n intValue = -intValue\n }\n return intValue\n }\n if (v.bigDecimal !== undefined) {\n return new BigDecimal(v.bigDecimal)\n }\n return undefined\n}\n\nexport function firstCounterValue(result: O11yResult | undefined, name: string): Numberish | undefined {\n if (!result) {\n return undefined\n }\n for (const counter of result.counters) {\n if (counter.metadata?.name === name) {\n return MetricValueToNumber(counter.metricValue)\n }\n }\n return undefined\n}\n\nexport function firstGaugeValue(result: O11yResult | undefined, name: string): Numberish | undefined {\n if (!result) {\n return undefined\n }\n for (const gauge of result.gauges) {\n if (gauge.metadata?.name === name) {\n return MetricValueToNumber(gauge.metricValue)\n }\n }\n return undefined\n}\n"]}
1
+ {"version":3,"file":"metric-utils.js","sourceRoot":"","sources":["../../src/test/metric-utils.ts"],"names":[],"mappings":";;;AACA,qCAAoE;AAEpE,mCAAkC;AAElC,SAAgB,mBAAmB,CAAC,CAAuC;IACzE,IAAI,CAAC,KAAK,SAAS,EAAE;QACnB,OAAO,SAAS,CAAA;KACjB;IAED,IAAI,CAAC,CAAC,WAAW,KAAK,SAAS,EAAE;QAC/B,OA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\nimport { Numberish } from '../numberish'\nimport { BigNumber } from 'ethers'\n\nexport function MetricValueToNumber(v: DeepPartial<MetricValue> | undefined): Numberish | undefined {\n if (v === undefined) {\n return undefined\n }\n\n if (v.doubleValue !== undefined) {\n return v.doubleValue\n }\n if (v.bigInteger !== undefined) {\n let intValue = BigNumber.from(v.bigInteger.data).toBigInt()\n if (v.bigInteger.negative) {\n intValue = -intValue\n }\n return intValue\n }\n if (v.bigDecimal !== undefined) {\n return new BigDecimal(v.bigDecimal)\n }\n return undefined\n}\n\nexport function firstCounterValue(result: ProcessResult | undefined, name: string): Numberish | undefined {\n if (!result) {\n return undefined\n }\n for (const counter of result.counters) {\n if (counter.metadata?.name === name) {\n return MetricValueToNumber(counter.metricValue)\n }\n }\n return undefined\n}\n\nexport function firstGaugeValue(result: ProcessResult | undefined, name: string): Numberish | undefined {\n if (!result) {\n return undefined\n }\n for (const gauge of result.gauges) {\n if (gauge.metadata?.name === name) {\n return MetricValueToNumber(gauge.metricValue)\n }\n }\n return undefined\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.8.0",
4
+ "version": "1.8.1",
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",
@@ -5,20 +5,20 @@ import { BaseContract, EventFilter } from '@ethersproject/contracts'
5
5
  import Long from 'long'
6
6
 
7
7
  import { BoundContractView, Context, ContractView } from './context'
8
- import { O11yResult } from './gen/processor/protos/processor'
8
+ import { ProcessResult } from './gen/processor/protos/processor'
9
9
  import { BindInternalOptions, BindOptions } from './bind-options'
10
10
  import { PromiseOrVoid } from './promise-or-void'
11
11
 
12
12
  export class EventsHandler {
13
13
  filters: EventFilter[]
14
- handler: (event: Log) => Promise<O11yResult>
14
+ handler: (event: Log) => Promise<ProcessResult>
15
15
  }
16
16
 
17
17
  export abstract class BaseProcessor<
18
18
  TContract extends BaseContract,
19
19
  TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>
20
20
  > {
21
- blockHandlers: ((block: Block) => Promise<O11yResult>)[] = []
21
+ blockHandlers: ((block: Block) => Promise<ProcessResult>)[] = []
22
22
  eventHandlers: EventsHandler[] = []
23
23
 
24
24
  name: string
@@ -88,11 +88,13 @@ export abstract class BaseProcessor<
88
88
  return {
89
89
  gauges: ctx.gauges,
90
90
  counters: ctx.counters,
91
+ logs: [],
91
92
  }
92
93
  }
93
94
  return {
94
95
  gauges: [],
95
96
  counters: [],
97
+ logs: [],
96
98
  }
97
99
  },
98
100
  })
@@ -109,6 +111,7 @@ export abstract class BaseProcessor<
109
111
  return {
110
112
  gauges: ctx.gauges,
111
113
  counters: ctx.counters,
114
+ logs: [],
112
115
  }
113
116
  })
114
117
  return this