@sentio/sdk 1.37.5-rc.1 → 1.37.5-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/builtin/internal/EACAggregatorProxy.d.ts +8 -8
- package/lib/builtin/internal/ERC1155.d.ts +8 -8
- package/lib/builtin/internal/ERC20.d.ts +6 -6
- package/lib/builtin/internal/ERC20Bytes.d.ts +4 -4
- package/lib/builtin/internal/ERC721.d.ts +6 -6
- package/lib/builtin/internal/WETH9.d.ts +8 -8
- package/lib/builtin/internal/common.d.ts +5 -5
- package/lib/builtin/internal/eacaggregatorproxy_processor.d.ts +24 -24
- package/lib/builtin/internal/erc1155_processor.d.ts +9 -9
- package/lib/builtin/internal/erc20_processor.d.ts +19 -19
- package/lib/builtin/internal/erc20bytes_processor.d.ts +10 -10
- package/lib/builtin/internal/erc721_processor.d.ts +15 -15
- package/lib/builtin/internal/weth9_processor.d.ts +12 -12
- package/lib/core/account-processor.js +2 -2
- package/lib/core/account-processor.js.map +1 -1
- package/lib/core/base-processor.d.ts +4 -4
- package/lib/core/base-processor.js +19 -6
- package/lib/core/base-processor.js.map +1 -1
- package/lib/core/context.d.ts +3 -2
- package/lib/core/context.js +5 -3
- package/lib/core/context.js.map +1 -1
- package/lib/core/eth-plugin.js +12 -30
- package/lib/core/eth-plugin.js.map +1 -1
- package/lib/core/exporter.d.ts +1 -1
- package/lib/core/logger.d.ts +1 -1
- package/lib/core/metadata.d.ts +1 -1
- package/lib/core/numberish.d.ts +1 -1
- package/lib/core/sui-processor.d.ts +1 -1
- package/lib/promise-or-void.d.ts +1 -1
- package/lib/testing/test-processor-server.js +6 -3
- package/lib/testing/test-processor-server.js.map +1 -1
- package/package.json +4 -4
- package/src/core/account-processor.ts +3 -3
- package/src/core/base-processor.ts +30 -10
- package/src/core/context.ts +6 -3
- package/src/core/eth-plugin.ts +24 -32
- package/src/testing/test-processor-server.ts +6 -3
package/lib/core/eth-plugin.js
CHANGED
|
@@ -174,59 +174,41 @@ class EthPlugin extends runtime_1.Plugin {
|
|
|
174
174
|
return base_processor_template_1.TemplateInstanceState.INSTANCE.getValues().length !== config.templateInstances.length;
|
|
175
175
|
}
|
|
176
176
|
async processLog(request) {
|
|
177
|
-
if (!request.data) {
|
|
177
|
+
if (!request.data?.ethLog?.log) {
|
|
178
178
|
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Log can't be null");
|
|
179
179
|
}
|
|
180
|
+
const ethLog = request.data.ethLog;
|
|
180
181
|
const promises = [];
|
|
181
|
-
let log;
|
|
182
|
-
if (request.data.ethLog) {
|
|
183
|
-
log = request.data.ethLog.log;
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Log can't be null");
|
|
187
|
-
}
|
|
188
182
|
for (const handlerId of request.handlerIds) {
|
|
189
183
|
const handler = this.eventHandlers[handlerId];
|
|
190
|
-
promises.push(handler(
|
|
191
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'error processing log: ' + JSON.stringify(log) + '\n' + (0, runtime_1.errorString)(e));
|
|
184
|
+
promises.push(handler(ethLog).catch((e) => {
|
|
185
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'error processing log: ' + JSON.stringify(ethLog.log) + '\n' + (0, runtime_1.errorString)(e));
|
|
192
186
|
}));
|
|
193
187
|
}
|
|
194
188
|
return (0, runtime_1.mergeProcessResults)(await Promise.all(promises));
|
|
195
189
|
}
|
|
196
190
|
async processTrace(binding) {
|
|
197
|
-
if (!binding.data) {
|
|
198
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Trace can't be empty");
|
|
199
|
-
}
|
|
200
|
-
let trace;
|
|
201
|
-
if (binding.data.ethTrace?.trace) {
|
|
202
|
-
trace = binding.data.ethTrace.trace;
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
191
|
+
if (!binding.data?.ethTrace?.trace) {
|
|
205
192
|
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Trace can't be null");
|
|
206
193
|
}
|
|
194
|
+
const ethTrace = binding.data.ethTrace;
|
|
207
195
|
const promises = [];
|
|
208
196
|
for (const handlerId of binding.handlerIds) {
|
|
209
|
-
promises.push(this.traceHandlers[handlerId](
|
|
210
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'error processing trace: ' + JSON.stringify(trace) + '\n' + (0, runtime_1.errorString)(e));
|
|
197
|
+
promises.push(this.traceHandlers[handlerId](ethTrace).catch((e) => {
|
|
198
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'error processing trace: ' + JSON.stringify(ethTrace.trace) + '\n' + (0, runtime_1.errorString)(e));
|
|
211
199
|
}));
|
|
212
200
|
}
|
|
213
201
|
return (0, runtime_1.mergeProcessResults)(await Promise.all(promises));
|
|
214
202
|
}
|
|
215
203
|
async processBlock(binding) {
|
|
216
|
-
if (!binding.data) {
|
|
217
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Block can't be empty");
|
|
218
|
-
}
|
|
219
|
-
let block;
|
|
220
|
-
if (binding.data.ethBlock?.block) {
|
|
221
|
-
block = binding.data.ethBlock.block;
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
204
|
+
if (!binding.data?.ethBlock?.block) {
|
|
224
205
|
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Block can't be empty");
|
|
225
206
|
}
|
|
207
|
+
const ethBlock = binding.data.ethBlock;
|
|
226
208
|
const promises = [];
|
|
227
209
|
for (const handlerId of binding.handlerIds) {
|
|
228
|
-
promises.push(this.blockHandlers[handlerId](
|
|
229
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'error processing block: ' + block
|
|
210
|
+
promises.push(this.blockHandlers[handlerId](ethBlock).catch((e) => {
|
|
211
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'error processing block: ' + ethBlock.block?.number + '\n' + (0, runtime_1.errorString)(e));
|
|
230
212
|
}));
|
|
231
213
|
}
|
|
232
214
|
return (0, runtime_1.mergeProcessResults)(await Promise.all(promises));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eth-plugin.js","sourceRoot":"","sources":["../../src/core/eth-plugin.ts"],"names":[],"mappings":";;;AAAA,6CAAyG;AACzG,2CAUuB;AAEvB,yCAA+C;AAG/C,oCAAyC;AACzC,2DAA2D;AAC3D,uEAAkG;AAElG,MAAa,SAAU,SAAQ,gBAAM;IACnC,IAAI,GAAW,WAAW,CAAA;IAElB,aAAa,GAA+C,EAAE,CAAA;IAC9D,aAAa,GAAiD,EAAE,CAAA;IAChE,aAAa,GAAiD,EAAE,CAAA;IAExE,SAAS,CAAC,MAA6B;QACrC,4DAA4D;QAC5D,MAAM,CAAC,iBAAiB,GAAG,CAAC,GAAG,+CAAqB,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAA;QAE1E,KAAK,MAAM,SAAS,IAAI,sBAAc,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;YAC3D,yDAAyD;YACzD,kCAAkC;YAClC,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,EAAE,CAAA;YACtC,mDAAmD;YAEnD,MAAM,cAAc,GAAmB;gBACrC,aAAa,EAAE,wBAAc;gBAC7B,QAAQ,EAAE;oBACR,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,IAAI;oBAC3B,OAAO,EAAE,OAAO,CAAC,QAAQ,EAAE;oBAC3B,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,OAAO;oBACjC,GAAG,EAAE,EAAE;iBACR;gBACD,eAAe,EAAE,EAAE;gBACnB,UAAU,EAAE,EAAE;gBACd,YAAY,EAAE,EAAE;gBAChB,UAAU,EAAE,SAAS,CAAC,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AAA;SACvE;QACD,IAAI,KAAY,CAAA;QAChB,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE;YAChC,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAc,CAAA;SAC7C;aAAM;YACL,MAAM,IAAI,uBAAW,CAAC,kBAAM,CAAC,gBAAgB,EAAE,sBAAsB,CAAC,CAAA;SACvE;QAED,MAAM,QAAQ,GAA6B,EAAE,CAAA;QAC7C,KAAK,MAAM,SAAS,IAAI,OAAO,CAAC,UAAU,EAAE;YAC1C,QAAQ,CAAC,IAAI,CACX,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBAC/C,MAAM,IAAI,uBAAW,CAAC,kBAAM,CAAC,QAAQ,EAAE,0BAA0B,GAAG,KAAK,CAAC,MAAM,GAAG,IAAI,GAAG,IAAA,qBAAW,EAAC,CAAC,CAAC,CAAC,CAAA;YAC3G,CAAC,CAAC,CACH,CAAA;SACF;QACD,OAAO,IAAA,6BAAmB,EAAC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IACzD,CAAC;CACF;AA/PD,8BA+PC;AAED,uBAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,SAAS,EAAE,CAAC,CAAA","sourcesContent":["import { Plugin, PluginManager, errorString, mergeProcessResults, USER_PROCESSOR } from '@sentio/runtime'\nimport {\n AccountConfig,\n ContractConfig,\n DataBinding,\n HandlerType,\n LogFilter,\n LogHandlerConfig,\n ProcessConfigResponse,\n ProcessResult,\n StartRequest,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\nimport { Block, Log } from '@ethersproject/abstract-provider'\nimport { Trace } from '@sentio/sdk'\nimport { ProcessorState } from '../binds'\nimport { AccountProcessorState } from './account-processor'\nimport { ProcessorTemplateProcessorState, TemplateInstanceState } from './base-processor-template'\n\nexport class EthPlugin extends Plugin {\n name: string = 'EthPlugin'\n\n private eventHandlers: ((event: Log) => Promise<ProcessResult>)[] = []\n private traceHandlers: ((trace: Trace) => Promise<ProcessResult>)[] = []\n private blockHandlers: ((block: Block) => Promise<ProcessResult>)[] = []\n\n configure(config: ProcessConfigResponse): void {\n // This syntax is to copy values instead of using references\n config.templateInstances = [...TemplateInstanceState.INSTANCE.getValues()]\n\n for (const processor of ProcessorState.INSTANCE.getValues()) {\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 intervalConfigs: [],\n logConfigs: [],\n traceConfigs: [],\n startBlock: processor.config.startBlock,\n endBlock: 0n,\n instructionConfig: undefined,\n aptosEventConfigs: [],\n aptosCallConfigs: [],\n }\n if (processor.config.endBlock) {\n contractConfig.endBlock = processor.config.endBlock\n }\n\n // Step 1. Prepare all the block handlers\n for (const blockHandler of processor.blockHandlers) {\n const handlerId = this.blockHandlers.push(blockHandler.handler) - 1\n // TODO wrap the block handler into one\n\n contractConfig.intervalConfigs.push({\n slot: 0,\n slotInterval: blockHandler.blockInterval,\n minutes: 0,\n minutesInterval: blockHandler.timeIntervalInMinutes,\n handlerId: handlerId,\n })\n }\n\n // Step 2. Prepare all trace handlers\n for (const traceHandler of processor.traceHandlers) {\n const handlerId = this.traceHandlers.push(traceHandler.handler) - 1\n contractConfig.traceConfigs.push({\n signature: traceHandler.signature,\n handlerId: handlerId,\n })\n }\n\n // Step 3. Prepare all the event handlers\n for (const eventsHandler of processor.eventHandlers) {\n // associate id with filter\n const handlerId = this.eventHandlers.push(eventsHandler.handler) - 1\n const logConfig: LogHandlerConfig = {\n handlerId: handlerId,\n filters: [],\n }\n\n for (const filter of eventsHandler.filters) {\n if (!filter.topics) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Topic should not be null')\n }\n const logFilter: LogFilter = {\n addressType: undefined,\n address: contractConfig.contract?.address,\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 config.contractConfigs.push(contractConfig)\n }\n\n // part 1.b prepare EVM account processors\n for (const processor of AccountProcessorState.INSTANCE.getValues()) {\n const accountConfig: AccountConfig = {\n address: processor.config.address,\n chainId: processor.getChainId().toString(),\n startBlock: processor.config.startBlock ? BigInt(processor.config.startBlock) : 0n,\n aptosIntervalConfigs: [],\n intervalConfigs: [],\n logConfigs: [],\n }\n // TODO add interval\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 addressType: filter.addressType,\n address: filter.address,\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 accountConfig.logConfigs.push(logConfig)\n }\n\n config.accountConfigs.push(accountConfig)\n }\n }\n\n supportedHandlers = [HandlerType.ETH_LOG, HandlerType.ETH_BLOCK, HandlerType.ETH_TRACE]\n\n processBinding(request: DataBinding): Promise<ProcessResult> {\n // return Promise.resolve(undefined);\n switch (request.handlerType) {\n case HandlerType.ETH_LOG:\n return this.processLog(request)\n case HandlerType.ETH_TRACE:\n return this.processTrace(request)\n case HandlerType.ETH_BLOCK:\n return this.processBlock(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n\n start(request: StartRequest) {\n for (const instance of request.templateInstances) {\n const template = ProcessorTemplateProcessorState.INSTANCE.getValues()[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 }\n\n stateDiff(config: ProcessConfigResponse): boolean {\n return TemplateInstanceState.INSTANCE.getValues().length !== config.templateInstances.length\n }\n\n async processLog(request: DataBinding): Promise<ProcessResult> {\n if (!request.data) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Log can't be null\")\n }\n\n const promises: Promise<ProcessResult>[] = []\n let log: Log\n if (request.data.ethLog) {\n log = request.data.ethLog.log as Log\n } else {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Log can't be null\")\n }\n\n for (const handlerId of request.handlerIds) {\n const handler = this.eventHandlers[handlerId]\n promises.push(\n handler(log).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing log: ' + JSON.stringify(log) + '\\n' + errorString(e))\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processTrace(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Trace can't be empty\")\n }\n let trace: Trace\n if (binding.data.ethTrace?.trace) {\n trace = binding.data.ethTrace.trace as Trace\n } else {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Trace can't be null\")\n }\n\n const promises: Promise<ProcessResult>[] = []\n\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.traceHandlers[handlerId](trace).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing trace: ' + JSON.stringify(trace) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processBlock(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Block can't be empty\")\n }\n let block: Block\n if (binding.data.ethBlock?.block) {\n block = binding.data.ethBlock.block as Block\n } else {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Block can't be empty\")\n }\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.blockHandlers[handlerId](block).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing block: ' + block.number + '\\n' + errorString(e))\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n}\n\nPluginManager.INSTANCE.register(new EthPlugin())\n"]}
|
|
1
|
+
{"version":3,"file":"eth-plugin.js","sourceRoot":"","sources":["../../src/core/eth-plugin.ts"],"names":[],"mappings":";;;AAAA,6CAAyG;AACzG,2CAauB;AAEvB,yCAA+C;AAE/C,oCAAyC;AACzC,2DAA2D;AAC3D,uEAAkG;AAElG,MAAa,SAAU,SAAQ,gBAAM;IACnC,IAAI,GAAW,WAAW,CAAA;IAElB,aAAa,GAAuD,EAAE,CAAA;IACtE,aAAa,GAAyD,EAAE,CAAA;IACxE,aAAa,GAAyD,EAAE,CAAA;IAEhF,SAAS,CAAC,MAA6B;QACrC,4DAA4D;QAC5D,MAAM,CAAC,iBAAiB,GAAG,CAAC,GAAG,+CAAqB,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAA;QAE1E,KAAK,MAAM,SAAS,IAAI,sBAAc,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;YAC3D,yDAAyD;YACzD,kCAAkC;YAClC,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,EAAE,CAAA;YACtC,mDAAmD;YAEnD,MAAM,cAAc,GAAmB;gBACrC,aAAa,EAAE,wBAAc;gB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AM,CAAC,gBAAgB,EAAE,sBAAsB,CAAC,CAAA;SACvE;QACD,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAA;QAEtC,MAAM,QAAQ,GAA6B,EAAE,CAAA;QAC7C,KAAK,MAAM,SAAS,IAAI,OAAO,CAAC,UAAU,EAAE;YAC1C,QAAQ,CAAC,IAAI,CACX,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBAClD,MAAM,IAAI,uBAAW,CACnB,kBAAM,CAAC,QAAQ,EACf,0BAA0B,GAAG,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAA,qBAAW,EAAC,CAAC,CAAC,CAC5E,CAAA;YACH,CAAC,CAAC,CACH,CAAA;SACF;QACD,OAAO,IAAA,6BAAmB,EAAC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IACzD,CAAC;CACF;AArPD,8BAqPC;AAED,uBAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,SAAS,EAAE,CAAC,CAAA","sourcesContent":["import { Plugin, PluginManager, errorString, mergeProcessResults, USER_PROCESSOR } from '@sentio/runtime'\nimport {\n AccountConfig,\n ContractConfig,\n Data_EthBlock,\n Data_EthLog,\n Data_EthTrace,\n DataBinding,\n HandlerType,\n LogFilter,\n LogHandlerConfig,\n ProcessConfigResponse,\n ProcessResult,\n StartRequest,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\nimport { Block, Log } from '@ethersproject/abstract-provider'\nimport { ProcessorState } from '../binds'\nimport { AccountProcessorState } from './account-processor'\nimport { ProcessorTemplateProcessorState, TemplateInstanceState } from './base-processor-template'\n\nexport class EthPlugin extends Plugin {\n name: string = 'EthPlugin'\n\n private eventHandlers: ((event: Data_EthLog) => Promise<ProcessResult>)[] = []\n private traceHandlers: ((trace: Data_EthTrace) => Promise<ProcessResult>)[] = []\n private blockHandlers: ((block: Data_EthBlock) => Promise<ProcessResult>)[] = []\n\n configure(config: ProcessConfigResponse): void {\n // This syntax is to copy values instead of using references\n config.templateInstances = [...TemplateInstanceState.INSTANCE.getValues()]\n\n for (const processor of ProcessorState.INSTANCE.getValues()) {\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 intervalConfigs: [],\n logConfigs: [],\n traceConfigs: [],\n startBlock: processor.config.startBlock,\n endBlock: 0n,\n instructionConfig: undefined,\n aptosEventConfigs: [],\n aptosCallConfigs: [],\n }\n if (processor.config.endBlock) {\n contractConfig.endBlock = processor.config.endBlock\n }\n\n // Step 1. Prepare all the block handlers\n for (const blockHandler of processor.blockHandlers) {\n const handlerId = this.blockHandlers.push(blockHandler.handler) - 1\n // TODO wrap the block handler into one\n\n contractConfig.intervalConfigs.push({\n slot: 0,\n slotInterval: blockHandler.blockInterval,\n minutes: 0,\n minutesInterval: blockHandler.timeIntervalInMinutes,\n handlerId: handlerId,\n })\n }\n\n // Step 2. Prepare all trace handlers\n for (const traceHandler of processor.traceHandlers) {\n const handlerId = this.traceHandlers.push(traceHandler.handler) - 1\n contractConfig.traceConfigs.push({\n signature: traceHandler.signature,\n handlerId: handlerId,\n })\n }\n\n // Step 3. Prepare all the event handlers\n for (const eventsHandler of processor.eventHandlers) {\n // associate id with filter\n const handlerId = this.eventHandlers.push(eventsHandler.handler) - 1\n const logConfig: LogHandlerConfig = {\n handlerId: handlerId,\n filters: [],\n }\n\n for (const filter of eventsHandler.filters) {\n if (!filter.topics) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Topic should not be null')\n }\n const logFilter: LogFilter = {\n addressType: undefined,\n address: contractConfig.contract?.address,\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 config.contractConfigs.push(contractConfig)\n }\n\n // part 1.b prepare EVM account processors\n for (const processor of AccountProcessorState.INSTANCE.getValues()) {\n const accountConfig: AccountConfig = {\n address: processor.config.address,\n chainId: processor.getChainId().toString(),\n startBlock: processor.config.startBlock ? BigInt(processor.config.startBlock) : 0n,\n aptosIntervalConfigs: [],\n intervalConfigs: [],\n logConfigs: [],\n }\n // TODO add interval\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 addressType: filter.addressType,\n address: filter.address,\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 accountConfig.logConfigs.push(logConfig)\n }\n\n config.accountConfigs.push(accountConfig)\n }\n }\n\n supportedHandlers = [HandlerType.ETH_LOG, HandlerType.ETH_BLOCK, HandlerType.ETH_TRACE]\n\n processBinding(request: DataBinding): Promise<ProcessResult> {\n // return Promise.resolve(undefined);\n switch (request.handlerType) {\n case HandlerType.ETH_LOG:\n return this.processLog(request)\n case HandlerType.ETH_TRACE:\n return this.processTrace(request)\n case HandlerType.ETH_BLOCK:\n return this.processBlock(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n\n start(request: StartRequest) {\n for (const instance of request.templateInstances) {\n const template = ProcessorTemplateProcessorState.INSTANCE.getValues()[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 }\n\n stateDiff(config: ProcessConfigResponse): boolean {\n return TemplateInstanceState.INSTANCE.getValues().length !== config.templateInstances.length\n }\n\n async processLog(request: DataBinding): Promise<ProcessResult> {\n if (!request.data?.ethLog?.log) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Log can't be null\")\n }\n const ethLog = request.data.ethLog\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of request.handlerIds) {\n const handler = this.eventHandlers[handlerId]\n promises.push(\n handler(ethLog).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing log: ' + JSON.stringify(ethLog.log) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processTrace(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.ethTrace?.trace) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Trace can't be null\")\n }\n const ethTrace = binding.data.ethTrace\n\n const promises: Promise<ProcessResult>[] = []\n\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.traceHandlers[handlerId](ethTrace).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing trace: ' + JSON.stringify(ethTrace.trace) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processBlock(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.ethBlock?.block) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Block can't be empty\")\n }\n const ethBlock = binding.data.ethBlock\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.blockHandlers[handlerId](ethBlock).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing block: ' + ethBlock.block?.number + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n}\n\nPluginManager.INSTANCE.register(new EthPlugin())\n"]}
|
package/lib/core/exporter.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseContext } from './base-context';
|
|
2
2
|
import { NamedResultDescriptor } from './metadata';
|
|
3
3
|
import { MapStateStorage } from '@sentio/runtime';
|
|
4
|
-
export
|
|
4
|
+
export type Export = Record<string, any>;
|
|
5
5
|
export declare class ExporterState extends MapStateStorage<Exporter> {
|
|
6
6
|
static INSTANCE: ExporterState;
|
|
7
7
|
}
|
package/lib/core/logger.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseContext } from './base-context';
|
|
2
2
|
import { LogLevel } from '@sentio/protos';
|
|
3
3
|
import { NamedResultDescriptor } from './metadata';
|
|
4
|
-
export
|
|
4
|
+
export type Attributes = Record<string, any>;
|
|
5
5
|
export declare class Logger extends NamedResultDescriptor {
|
|
6
6
|
private readonly ctx;
|
|
7
7
|
constructor(ctx: BaseContext, name?: string);
|
package/lib/core/metadata.d.ts
CHANGED
package/lib/core/numberish.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { BigNumber } from 'ethers';
|
|
|
2
2
|
import { BigInteger, MetricValue } from '@sentio/protos';
|
|
3
3
|
import { BigDecimal } from '.';
|
|
4
4
|
import { BlockTag } from '@ethersproject/providers';
|
|
5
|
-
export
|
|
5
|
+
export type Numberish = number | BigNumber | bigint | BigDecimal | string;
|
|
6
6
|
export declare function toBlockTag(a: number | bigint): BlockTag;
|
|
7
7
|
export declare function toMetricValue(value: Numberish): MetricValue;
|
|
8
8
|
export declare function toBigInteger(a: Numberish): BigInteger;
|
package/lib/promise-or-void.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type PromiseOrVoid = void | Promise<any>;
|
|
@@ -80,7 +80,10 @@ class TestProcessorServer {
|
|
|
80
80
|
if (config.signature == signature) {
|
|
81
81
|
return {
|
|
82
82
|
data: {
|
|
83
|
-
ethTrace: {
|
|
83
|
+
ethTrace: {
|
|
84
|
+
trace,
|
|
85
|
+
timestamp: new Date(),
|
|
86
|
+
},
|
|
84
87
|
},
|
|
85
88
|
handlerIds: [config.handlerId],
|
|
86
89
|
handlerType: protos_1.HandlerType.ETH_TRACE,
|
|
@@ -137,7 +140,7 @@ class TestProcessorServer {
|
|
|
137
140
|
if (match) {
|
|
138
141
|
return {
|
|
139
142
|
data: {
|
|
140
|
-
ethLog: { log },
|
|
143
|
+
ethLog: { log, timestamp: new Date() },
|
|
141
144
|
},
|
|
142
145
|
handlerIds: [config.handlerId],
|
|
143
146
|
handlerType: protos_1.HandlerType.ETH_LOG,
|
|
@@ -195,7 +198,7 @@ class TestProcessorServer {
|
|
|
195
198
|
if (match) {
|
|
196
199
|
return {
|
|
197
200
|
data: {
|
|
198
|
-
ethLog: { log },
|
|
201
|
+
ethLog: { log, timestamp: new Date() },
|
|
199
202
|
},
|
|
200
203
|
handlerIds: [config.handlerId],
|
|
201
204
|
handlerType: protos_1.HandlerType.ETH_LOG,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-processor-server.js","sourceRoot":"","sources":["../../src/testing/test-processor-server.ts"],"names":[],"mappings":";;;AAAA,2CAYuB;AAGvB,6CAAkG;AAClG,0CAA0C;AAE1C,wDAAiE;AAGpD,QAAA,YAAY,GAA6B,EAAE,CAAA;AAExD,SAAgB,SAAS;IACvB,eAAK,CAAC,KAAK,EAAE,CAAA;IACb,mBAAS,CAAC,KAAK,EAAE,CAAA;AACnB,CAAC;AAHD,8BAGC;AAED,MAAa,mBAAmB;IAC9B,OAAO,CAAsB;IAC7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OAAO,CAAC,CAAA;IACvD,CAAC;IAED,qBAAqB,CAAC,OAAmC,EAAE,OAAoB;QAC7E,OAAO,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IAC7D,CAAC;CACF;AA7RD,kDA6RC","sourcesContent":["import {\n AccountConfig,\n ContractConfig,\n DataBinding,\n HandlerType,\n Data_SolInstruction,\n ProcessBindingResponse,\n ProcessBindingsRequest,\n ProcessConfigRequest,\n ProcessConfigResponse,\n ProcessorServiceImplementation,\n StartRequest,\n} from '@sentio/protos'\nimport { CallContext } from 'nice-grpc-common'\nimport { Empty } from '@sentio/protos/lib/google/protobuf/empty'\nimport { ChainConfig, ProcessorServiceImpl, setProvider, Endpoints, State } from '@sentio/runtime'\nimport { CHAIN_MAP } from '../utils/chain'\nimport { Block, Log } from '@ethersproject/abstract-provider'\nimport { getNetwork, Networkish } from '@ethersproject/providers'\nimport { Trace } from '../core/trace'\n\nexport const TEST_CONTEXT: CallContext = <CallContext>{}\n\nexport function cleanTest() {\n State.reset()\n Endpoints.reset()\n}\n\nexport class TestProcessorServer implements ProcessorServiceImplementation {\n service: ProcessorServiceImpl\n contractConfigs: ContractConfig[]\n accountConfigs: AccountConfig[]\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 const config = await this.getConfig({})\n this.contractConfigs = config.contractConfigs\n this.accountConfigs = config.accountConfigs\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 // processLogs(request: ProcessBindingsRequest, context = TEST_CONTEXT): Promise<ProcessBindingResponse> {\n // return this.service.processLogs(request, context)\n // }\n //\n // processTraces(request: ProcessBindingsRequest, context: CallContext = TEST_CONTEXT): Promise<ProcessBindingResponse> {\n // return this.service.processTraces(request, context)\n // }\n\n testTrace(trace: Trace, network: Networkish = 1): Promise<ProcessBindingResponse> {\n return this.testTraces([trace], network)\n }\n\n testTraces(traces: Trace[], network: Networkish = 1): Promise<ProcessBindingResponse> {\n const bindings = []\n for (const trace of traces) {\n const binding = this.buildTraceBinding(trace, network)\n if (!binding) {\n throw Error('Invalid test trace: ' + JSON.stringify(trace))\n }\n bindings.push(binding)\n }\n return this.processBindings({\n bindings: bindings,\n })\n }\n\n buildTraceBinding(trace: Trace, network: Networkish = 1): DataBinding | undefined {\n if (trace.type !== 'call' || !trace.action.input) {\n throw Error('Invalid test trace: ' + JSON.stringify(trace))\n }\n const signature = trace.action.input.slice(0, 10)\n\n for (const contract of this.contractConfigs) {\n if (contract.contract?.chainId !== getNetwork(network).chainId.toString()) {\n continue\n }\n if (trace.action.to?.toLowerCase() !== contract.contract?.address.toLowerCase()) {\n continue\n }\n for (const config of contract.traceConfigs) {\n if (config.signature == signature) {\n return {\n data: {\n ethTrace: { trace },\n },\n handlerIds: [config.handlerId],\n handlerType: HandlerType.ETH_TRACE,\n }\n }\n }\n }\n return undefined\n }\n\n testLog(log: Log, network: Networkish = 1): Promise<ProcessBindingResponse> {\n return this.testLogs([log], network)\n }\n\n testLogs(logs: Log[], network: Networkish = 1): Promise<ProcessBindingResponse> {\n const bindings = []\n for (const log of logs) {\n const binding = this.buildLogBinding(log, network)\n if (!binding) {\n throw Error('Invalid test log: ' + JSON.stringify(log))\n }\n bindings.push(binding)\n }\n return this.processBindings({\n bindings: bindings,\n })\n }\n\n buildLogBinding(log: Log, network: Networkish = 1): DataBinding | undefined {\n for (const contract of this.contractConfigs) {\n if (contract.contract?.chainId !== getNetwork(network).chainId.toString()) {\n continue\n }\n if (log.address.toLowerCase() !== contract.contract?.address.toLowerCase()) {\n continue\n }\n for (const config of contract.logConfigs) {\n for (const filter of config.filters) {\n // if (filter.topics.length != log.topics.length) {\n // continue\n // }\n\n let match = true\n for (const topicIdx in filter.topics) {\n const logTopic = log.topics[topicIdx]\n const possibleTopic = filter.topics[topicIdx].hashes\n if (possibleTopic.length === 0) {\n // match all\n continue\n }\n if (possibleTopic.find((e) => e.toLowerCase() === logTopic.toLowerCase())) {\n // find one\n continue\n }\n match = false\n break\n }\n if (match) {\n return {\n data: {\n ethLog: { log },\n },\n handlerIds: [config.handlerId],\n handlerType: HandlerType.ETH_LOG,\n }\n }\n }\n }\n }\n return undefined\n }\n testAccountLog(address: string, log: Log, network: Networkish = 1): Promise<ProcessBindingResponse> {\n return this.testAccountLogs(address, [log], network)\n }\n\n testAccountLogs(address: string, logs: Log[], network: Networkish = 1): Promise<ProcessBindingResponse> {\n const bindings = []\n for (const log of logs) {\n const binding = this.buildAccountLogBinding(address, log, network)\n if (!binding) {\n throw Error('Invalid test log: ' + JSON.stringify(log))\n }\n bindings.push(binding)\n }\n return this.processBindings({\n bindings: bindings,\n })\n }\n\n buildAccountLogBinding(address: string, log: Log, network: Networkish = 1): DataBinding | undefined {\n for (const account of this.accountConfigs) {\n if (account.chainId !== getNetwork(network).chainId.toString()) {\n continue\n }\n if (address.toLowerCase() !== account.address.toLowerCase()) {\n continue\n }\n for (const config of account.logConfigs) {\n for (const filter of config.filters) {\n // if (filter.topics.length != log.topics.length) {\n // continue\n // }\n\n let match = true\n for (const topicIdx in filter.topics) {\n const logTopic = log.topics[topicIdx]\n const possibleTopic = filter.topics[topicIdx].hashes\n if (possibleTopic.length === 0) {\n // match all\n continue\n }\n if (possibleTopic.find((e) => e.toLowerCase() === logTopic.toLowerCase())) {\n // find one\n continue\n }\n match = false\n break\n }\n if (match) {\n return {\n data: {\n ethLog: { log },\n },\n handlerIds: [config.handlerId],\n handlerType: HandlerType.ETH_LOG,\n }\n }\n }\n }\n }\n return undefined\n }\n\n testBlock(block: Partial<Block> & { number: number }, network: Networkish = 1): Promise<ProcessBindingResponse> {\n return this.testBlocks([block], network)\n }\n\n testBlocks(blocks: Partial<Block> & { number: number }[], network: Networkish = 1) {\n const bindings = []\n for (const block of blocks) {\n const binding = this.buildBlockBinding(block, network)\n if (!binding) {\n throw Error('Invalid test block: ' + JSON.stringify(block))\n }\n bindings.push(binding)\n }\n return this.processBindings({\n bindings: bindings,\n })\n }\n\n buildBlockBinding(block: Partial<Block> & { number: number }, network: Networkish = 1): DataBinding {\n const binding: DataBinding = {\n data: {\n ethBlock: { block },\n },\n handlerType: HandlerType.ETH_BLOCK,\n handlerIds: [],\n }\n for (const contract of this.contractConfigs) {\n if (contract.contract?.chainId !== getNetwork(network).chainId.toString()) {\n continue\n }\n const longBlockNumber = block.number\n if (longBlockNumber < contract.startBlock) {\n continue\n }\n if (contract.endBlock !== 0n && longBlockNumber >= contract.endBlock) {\n continue\n }\n\n for (const config of contract.intervalConfigs) {\n binding.handlerIds.push(config.handlerId)\n }\n }\n return binding\n }\n\n testInstructions(instructions: Data_SolInstruction[]): Promise<ProcessBindingResponse> {\n return this.processBindings({\n bindings: instructions.map((instruction) => {\n return {\n data: {\n raw: new Uint8Array(),\n solInstruction: instruction,\n },\n handlerIds: [],\n handlerType: HandlerType.SOL_INSTRUCTION,\n }\n }),\n })\n }\n\n processBindings(\n request: ProcessBindingsRequest,\n context: CallContext = TEST_CONTEXT\n ): Promise<ProcessBindingResponse> {\n return this.service.processBindings(request, context)\n }\n\n processBindingsStream(request: AsyncIterable<DataBinding>, context: CallContext) {\n return this.service.processBindingsStream(request, context)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"test-processor-server.js","sourceRoot":"","sources":["../../src/testing/test-processor-server.ts"],"names":[],"mappings":";;;AAAA,2CAYuB;AAGvB,6CAAkG;AAClG,0CAA0C;AA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OAAO;oBACL,IAAI,EAAE;wBACJ,GAAG,EAAE,IAAI,UAAU,EAAE;wBACrB,cAAc,EAAE,WAAW;qBAC5B;oBACD,UAAU,EAAE,EAAE;oBACd,WAAW,EAAE,oBAAW,CAAC,eAAe;iBACzC,CAAA;YACH,CAAC,CAAC;SACH,CAAC,CAAA;IACJ,CAAC;IAED,eAAe,CACb,OAA+B,EAC/B,UAAuB,oBAAY;QAEnC,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IACvD,CAAC;IAED,qBAAqB,CAAC,OAAmC,EAAE,OAAoB;QAC7E,OAAO,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IAC7D,CAAC;CACF;AAhSD,kDAgSC","sourcesContent":["import {\n AccountConfig,\n ContractConfig,\n DataBinding,\n HandlerType,\n Data_SolInstruction,\n ProcessBindingResponse,\n ProcessBindingsRequest,\n ProcessConfigRequest,\n ProcessConfigResponse,\n ProcessorServiceImplementation,\n StartRequest,\n} from '@sentio/protos'\nimport { CallContext } from 'nice-grpc-common'\nimport { Empty } from '@sentio/protos/lib/google/protobuf/empty'\nimport { ChainConfig, ProcessorServiceImpl, setProvider, Endpoints, State } from '@sentio/runtime'\nimport { CHAIN_MAP } from '../utils/chain'\nimport { Block, Log } from '@ethersproject/abstract-provider'\nimport { getNetwork, Networkish } from '@ethersproject/providers'\nimport { Trace } from '../core/trace'\n\nexport const TEST_CONTEXT: CallContext = <CallContext>{}\n\nexport function cleanTest() {\n State.reset()\n Endpoints.reset()\n}\n\nexport class TestProcessorServer implements ProcessorServiceImplementation {\n service: ProcessorServiceImpl\n contractConfigs: ContractConfig[]\n accountConfigs: AccountConfig[]\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 const config = await this.getConfig({})\n this.contractConfigs = config.contractConfigs\n this.accountConfigs = config.accountConfigs\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 // processLogs(request: ProcessBindingsRequest, context = TEST_CONTEXT): Promise<ProcessBindingResponse> {\n // return this.service.processLogs(request, context)\n // }\n //\n // processTraces(request: ProcessBindingsRequest, context: CallContext = TEST_CONTEXT): Promise<ProcessBindingResponse> {\n // return this.service.processTraces(request, context)\n // }\n\n testTrace(trace: Trace, network: Networkish = 1): Promise<ProcessBindingResponse> {\n return this.testTraces([trace], network)\n }\n\n testTraces(traces: Trace[], network: Networkish = 1): Promise<ProcessBindingResponse> {\n const bindings = []\n for (const trace of traces) {\n const binding = this.buildTraceBinding(trace, network)\n if (!binding) {\n throw Error('Invalid test trace: ' + JSON.stringify(trace))\n }\n bindings.push(binding)\n }\n return this.processBindings({\n bindings: bindings,\n })\n }\n\n buildTraceBinding(trace: Trace, network: Networkish = 1): DataBinding | undefined {\n if (trace.type !== 'call' || !trace.action.input) {\n throw Error('Invalid test trace: ' + JSON.stringify(trace))\n }\n const signature = trace.action.input.slice(0, 10)\n\n for (const contract of this.contractConfigs) {\n if (contract.contract?.chainId !== getNetwork(network).chainId.toString()) {\n continue\n }\n if (trace.action.to?.toLowerCase() !== contract.contract?.address.toLowerCase()) {\n continue\n }\n for (const config of contract.traceConfigs) {\n if (config.signature == signature) {\n return {\n data: {\n ethTrace: {\n trace,\n timestamp: new Date(),\n },\n },\n handlerIds: [config.handlerId],\n handlerType: HandlerType.ETH_TRACE,\n }\n }\n }\n }\n return undefined\n }\n\n testLog(log: Log, network: Networkish = 1): Promise<ProcessBindingResponse> {\n return this.testLogs([log], network)\n }\n\n testLogs(logs: Log[], network: Networkish = 1): Promise<ProcessBindingResponse> {\n const bindings = []\n for (const log of logs) {\n const binding = this.buildLogBinding(log, network)\n if (!binding) {\n throw Error('Invalid test log: ' + JSON.stringify(log))\n }\n bindings.push(binding)\n }\n return this.processBindings({\n bindings: bindings,\n })\n }\n\n buildLogBinding(log: Log, network: Networkish = 1): DataBinding | undefined {\n for (const contract of this.contractConfigs) {\n if (contract.contract?.chainId !== getNetwork(network).chainId.toString()) {\n continue\n }\n if (log.address.toLowerCase() !== contract.contract?.address.toLowerCase()) {\n continue\n }\n for (const config of contract.logConfigs) {\n for (const filter of config.filters) {\n // if (filter.topics.length != log.topics.length) {\n // continue\n // }\n\n let match = true\n for (const topicIdx in filter.topics) {\n const logTopic = log.topics[topicIdx]\n const possibleTopic = filter.topics[topicIdx].hashes\n if (possibleTopic.length === 0) {\n // match all\n continue\n }\n if (possibleTopic.find((e) => e.toLowerCase() === logTopic.toLowerCase())) {\n // find one\n continue\n }\n match = false\n break\n }\n if (match) {\n return {\n data: {\n ethLog: { log, timestamp: new Date() },\n },\n handlerIds: [config.handlerId],\n handlerType: HandlerType.ETH_LOG,\n }\n }\n }\n }\n }\n return undefined\n }\n testAccountLog(address: string, log: Log, network: Networkish = 1): Promise<ProcessBindingResponse> {\n return this.testAccountLogs(address, [log], network)\n }\n\n testAccountLogs(address: string, logs: Log[], network: Networkish = 1): Promise<ProcessBindingResponse> {\n const bindings = []\n for (const log of logs) {\n const binding = this.buildAccountLogBinding(address, log, network)\n if (!binding) {\n throw Error('Invalid test log: ' + JSON.stringify(log))\n }\n bindings.push(binding)\n }\n return this.processBindings({\n bindings: bindings,\n })\n }\n\n buildAccountLogBinding(address: string, log: Log, network: Networkish = 1): DataBinding | undefined {\n for (const account of this.accountConfigs) {\n if (account.chainId !== getNetwork(network).chainId.toString()) {\n continue\n }\n if (address.toLowerCase() !== account.address.toLowerCase()) {\n continue\n }\n for (const config of account.logConfigs) {\n for (const filter of config.filters) {\n // if (filter.topics.length != log.topics.length) {\n // continue\n // }\n\n let match = true\n for (const topicIdx in filter.topics) {\n const logTopic = log.topics[topicIdx]\n const possibleTopic = filter.topics[topicIdx].hashes\n if (possibleTopic.length === 0) {\n // match all\n continue\n }\n if (possibleTopic.find((e) => e.toLowerCase() === logTopic.toLowerCase())) {\n // find one\n continue\n }\n match = false\n break\n }\n if (match) {\n return {\n data: {\n ethLog: { log, timestamp: new Date() },\n },\n handlerIds: [config.handlerId],\n handlerType: HandlerType.ETH_LOG,\n }\n }\n }\n }\n }\n return undefined\n }\n\n testBlock(block: Partial<Block> & { number: number }, network: Networkish = 1): Promise<ProcessBindingResponse> {\n return this.testBlocks([block], network)\n }\n\n testBlocks(blocks: Partial<Block> & { number: number }[], network: Networkish = 1) {\n const bindings = []\n for (const block of blocks) {\n const binding = this.buildBlockBinding(block, network)\n if (!binding) {\n throw Error('Invalid test block: ' + JSON.stringify(block))\n }\n bindings.push(binding)\n }\n return this.processBindings({\n bindings: bindings,\n })\n }\n\n buildBlockBinding(block: Partial<Block> & { number: number }, network: Networkish = 1): DataBinding {\n const binding: DataBinding = {\n data: {\n ethBlock: { block },\n },\n handlerType: HandlerType.ETH_BLOCK,\n handlerIds: [],\n }\n for (const contract of this.contractConfigs) {\n if (contract.contract?.chainId !== getNetwork(network).chainId.toString()) {\n continue\n }\n const longBlockNumber = block.number\n if (longBlockNumber < contract.startBlock) {\n continue\n }\n if (contract.endBlock !== 0n && longBlockNumber >= contract.endBlock) {\n continue\n }\n\n for (const config of contract.intervalConfigs) {\n binding.handlerIds.push(config.handlerId)\n }\n }\n return binding\n }\n\n testInstructions(instructions: Data_SolInstruction[]): Promise<ProcessBindingResponse> {\n return this.processBindings({\n bindings: instructions.map((instruction) => {\n return {\n data: {\n raw: new Uint8Array(),\n solInstruction: instruction,\n },\n handlerIds: [],\n handlerType: HandlerType.SOL_INSTRUCTION,\n }\n }),\n })\n }\n\n processBindings(\n request: ProcessBindingsRequest,\n context: CallContext = TEST_CONTEXT\n ): Promise<ProcessBindingResponse> {\n return this.service.processBindings(request, context)\n }\n\n processBindingsStream(request: AsyncIterable<DataBinding>, context: CallContext) {\n return this.service.processBindingsStream(request, context)\n }\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.37.5-rc.
|
|
4
|
+
"version": "1.37.5-rc.3",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"compile_target": "yarn tsc -b src/target-ethers-sentio/tsconfig.json",
|
|
7
7
|
"compile": "tsc -p . && cp src/utils/*.csv lib/utils",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@ethersproject/providers": "~5.7.0",
|
|
21
21
|
"@sentio/cli": "^1.0.0",
|
|
22
|
-
"@sentio/protos": "^1.37.5-rc.
|
|
23
|
-
"@sentio/runtime": "^1.37.5-rc.
|
|
22
|
+
"@sentio/protos": "^1.37.5-rc.3",
|
|
23
|
+
"@sentio/runtime": "^1.37.5-rc.3",
|
|
24
24
|
"@typechain/ethers-v5": "^10.0.0",
|
|
25
25
|
"bignumber.js": "^9.1.0",
|
|
26
26
|
"command-line-args": "^5.2.1",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"typedoc": {
|
|
58
58
|
"entryPoint": "./src/index.ts"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "91efb0c0a1853f1c3158c8abd5d9dcbc152c53c0"
|
|
61
61
|
}
|
|
@@ -191,10 +191,10 @@ export class AccountProcessor {
|
|
|
191
191
|
|
|
192
192
|
this.eventHandlers.push({
|
|
193
193
|
filters: _filters,
|
|
194
|
-
handler: async function (
|
|
194
|
+
handler: async function (data) {
|
|
195
|
+
const log = data.log as Event
|
|
195
196
|
const ctx = new AccountContext(chainId, config.address, undefined, log)
|
|
196
|
-
|
|
197
|
-
const event: Event = <Event>log
|
|
197
|
+
const event: Event = log
|
|
198
198
|
const parsed = ERC20_CONTRACT.interface.parseLog(log)
|
|
199
199
|
if (parsed) {
|
|
200
200
|
event.args = parsed.args
|
|
@@ -3,10 +3,11 @@ import { Block, Log, getNetwork } from '@ethersproject/providers'
|
|
|
3
3
|
import { BaseContract, Event, EventFilter } from '@ethersproject/contracts'
|
|
4
4
|
|
|
5
5
|
import { BoundContractView, ContractContext, ContractView } from './context'
|
|
6
|
-
import { AddressType, HandleInterval, ProcessResult } from '@sentio/protos'
|
|
6
|
+
import { AddressType, Data_EthBlock, Data_EthLog, Data_EthTrace, HandleInterval, ProcessResult } from '@sentio/protos'
|
|
7
7
|
import { BindInternalOptions, BindOptions } from './bind-options'
|
|
8
8
|
import { PromiseOrVoid } from '../promise-or-void'
|
|
9
9
|
import { Trace } from './trace'
|
|
10
|
+
import { ServerError, Status } from 'nice-grpc'
|
|
10
11
|
|
|
11
12
|
export interface AddressOrTypeEventFilter extends EventFilter {
|
|
12
13
|
addressType?: AddressType
|
|
@@ -14,18 +15,18 @@ export interface AddressOrTypeEventFilter extends EventFilter {
|
|
|
14
15
|
|
|
15
16
|
export class EventsHandler {
|
|
16
17
|
filters: AddressOrTypeEventFilter[]
|
|
17
|
-
handler: (event:
|
|
18
|
+
handler: (event: Data_EthLog) => Promise<ProcessResult>
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export class TraceHandler {
|
|
21
22
|
signature: string
|
|
22
|
-
handler: (trace:
|
|
23
|
+
handler: (trace: Data_EthTrace) => Promise<ProcessResult>
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export class BlockHandlder {
|
|
26
27
|
blockInterval?: HandleInterval
|
|
27
28
|
timeIntervalInMinutes?: HandleInterval
|
|
28
|
-
handler: (block:
|
|
29
|
+
handler: (block: Data_EthBlock) => Promise<ProcessResult>
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
export abstract class BaseProcessor<
|
|
@@ -77,7 +78,12 @@ export abstract class BaseProcessor<
|
|
|
77
78
|
const processor = this
|
|
78
79
|
this.eventHandlers.push({
|
|
79
80
|
filters: _filters,
|
|
80
|
-
handler: async function (
|
|
81
|
+
handler: async function (data: Data_EthLog) {
|
|
82
|
+
if (!data.log) {
|
|
83
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'Log is empty')
|
|
84
|
+
}
|
|
85
|
+
const log = data.log as Log
|
|
86
|
+
|
|
81
87
|
const contractView = processor.CreateBoundContractView()
|
|
82
88
|
|
|
83
89
|
const ctx = new ContractContext<TContract, TBoundContractView>(
|
|
@@ -85,7 +91,9 @@ export abstract class BaseProcessor<
|
|
|
85
91
|
contractView,
|
|
86
92
|
chainId,
|
|
87
93
|
undefined,
|
|
88
|
-
log
|
|
94
|
+
log,
|
|
95
|
+
undefined,
|
|
96
|
+
data.timestamp
|
|
89
97
|
)
|
|
90
98
|
// let event: Event = <Event>deepCopy(log);
|
|
91
99
|
const event: Event = <Event>log
|
|
@@ -145,7 +153,12 @@ export abstract class BaseProcessor<
|
|
|
145
153
|
const contractName = this.config.name
|
|
146
154
|
|
|
147
155
|
this.blockHandlers.push({
|
|
148
|
-
handler: async function (
|
|
156
|
+
handler: async function (data: Data_EthBlock) {
|
|
157
|
+
if (!data.block) {
|
|
158
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'Block is empty')
|
|
159
|
+
}
|
|
160
|
+
const block = data.block as Block
|
|
161
|
+
|
|
149
162
|
const contractView = processor.CreateBoundContractView()
|
|
150
163
|
|
|
151
164
|
const ctx = new ContractContext<TContract, TBoundContractView>(
|
|
@@ -153,7 +166,9 @@ export abstract class BaseProcessor<
|
|
|
153
166
|
contractView,
|
|
154
167
|
chainId,
|
|
155
168
|
block,
|
|
156
|
-
undefined
|
|
169
|
+
undefined,
|
|
170
|
+
undefined,
|
|
171
|
+
new Date(block.timestamp * 1000)
|
|
157
172
|
)
|
|
158
173
|
await handler(block, ctx)
|
|
159
174
|
return ctx.getProcessResult()
|
|
@@ -186,10 +201,14 @@ export abstract class BaseProcessor<
|
|
|
186
201
|
|
|
187
202
|
this.traceHandlers.push({
|
|
188
203
|
signature,
|
|
189
|
-
handler: async function (
|
|
204
|
+
handler: async function (data: Data_EthTrace) {
|
|
190
205
|
const contractView = processor.CreateBoundContractView()
|
|
191
206
|
const contractInterface = contractView.rawContract.interface
|
|
192
207
|
const fragment = contractInterface.getFunction(signature)
|
|
208
|
+
if (!data.trace) {
|
|
209
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'trace is null')
|
|
210
|
+
}
|
|
211
|
+
const trace = data.trace as Trace
|
|
193
212
|
if (!trace.action.input) {
|
|
194
213
|
return ProcessResult.fromPartial({})
|
|
195
214
|
}
|
|
@@ -202,7 +221,8 @@ export abstract class BaseProcessor<
|
|
|
202
221
|
chainId,
|
|
203
222
|
undefined,
|
|
204
223
|
undefined,
|
|
205
|
-
trace
|
|
224
|
+
trace,
|
|
225
|
+
data.timestamp
|
|
206
226
|
)
|
|
207
227
|
await handler(trace, ctx)
|
|
208
228
|
return ctx.getProcessResult()
|
package/src/core/context.ts
CHANGED
|
@@ -15,14 +15,16 @@ export abstract class EthContext extends BaseContext {
|
|
|
15
15
|
trace?: Trace
|
|
16
16
|
blockNumber: bigint | number
|
|
17
17
|
transactionHash?: string
|
|
18
|
+
timestamp: Date
|
|
18
19
|
|
|
19
|
-
protected constructor(chainId: number, address: string, block?: Block, log?: Log, trace?: Trace) {
|
|
20
|
+
protected constructor(chainId: number, address: string, block?: Block, log?: Log, trace?: Trace, timestamp?: Date) {
|
|
20
21
|
super()
|
|
21
22
|
this.chainId = chainId
|
|
22
23
|
this.log = log
|
|
23
24
|
this.block = block
|
|
24
25
|
this.trace = trace
|
|
25
26
|
this.address = address
|
|
27
|
+
this.timestamp = timestamp || new Date(0)
|
|
26
28
|
if (log) {
|
|
27
29
|
this.blockNumber = log.blockNumber
|
|
28
30
|
this.transactionHash = log.transactionHash
|
|
@@ -102,9 +104,10 @@ export class ContractContext<
|
|
|
102
104
|
chainId: number,
|
|
103
105
|
block?: Block,
|
|
104
106
|
log?: Log,
|
|
105
|
-
trace?: Trace
|
|
107
|
+
trace?: Trace,
|
|
108
|
+
timestamp?: Date
|
|
106
109
|
) {
|
|
107
|
-
super(chainId, view.rawContract.address, block, log, trace)
|
|
110
|
+
super(chainId, view.rawContract.address, block, log, trace, timestamp)
|
|
108
111
|
view.context = this
|
|
109
112
|
this.contractName = contractName
|
|
110
113
|
this.contract = view
|
package/src/core/eth-plugin.ts
CHANGED
|
@@ -2,6 +2,9 @@ import { Plugin, PluginManager, errorString, mergeProcessResults, USER_PROCESSOR
|
|
|
2
2
|
import {
|
|
3
3
|
AccountConfig,
|
|
4
4
|
ContractConfig,
|
|
5
|
+
Data_EthBlock,
|
|
6
|
+
Data_EthLog,
|
|
7
|
+
Data_EthTrace,
|
|
5
8
|
DataBinding,
|
|
6
9
|
HandlerType,
|
|
7
10
|
LogFilter,
|
|
@@ -13,7 +16,6 @@ import {
|
|
|
13
16
|
|
|
14
17
|
import { ServerError, Status } from 'nice-grpc'
|
|
15
18
|
import { Block, Log } from '@ethersproject/abstract-provider'
|
|
16
|
-
import { Trace } from '@sentio/sdk'
|
|
17
19
|
import { ProcessorState } from '../binds'
|
|
18
20
|
import { AccountProcessorState } from './account-processor'
|
|
19
21
|
import { ProcessorTemplateProcessorState, TemplateInstanceState } from './base-processor-template'
|
|
@@ -21,9 +23,9 @@ import { ProcessorTemplateProcessorState, TemplateInstanceState } from './base-p
|
|
|
21
23
|
export class EthPlugin extends Plugin {
|
|
22
24
|
name: string = 'EthPlugin'
|
|
23
25
|
|
|
24
|
-
private eventHandlers: ((event:
|
|
25
|
-
private traceHandlers: ((trace:
|
|
26
|
-
private blockHandlers: ((block:
|
|
26
|
+
private eventHandlers: ((event: Data_EthLog) => Promise<ProcessResult>)[] = []
|
|
27
|
+
private traceHandlers: ((trace: Data_EthTrace) => Promise<ProcessResult>)[] = []
|
|
28
|
+
private blockHandlers: ((block: Data_EthBlock) => Promise<ProcessResult>)[] = []
|
|
27
29
|
|
|
28
30
|
configure(config: ProcessConfigResponse): void {
|
|
29
31
|
// This syntax is to copy values instead of using references
|
|
@@ -203,23 +205,20 @@ export class EthPlugin extends Plugin {
|
|
|
203
205
|
}
|
|
204
206
|
|
|
205
207
|
async processLog(request: DataBinding): Promise<ProcessResult> {
|
|
206
|
-
if (!request.data) {
|
|
208
|
+
if (!request.data?.ethLog?.log) {
|
|
207
209
|
throw new ServerError(Status.INVALID_ARGUMENT, "Log can't be null")
|
|
208
210
|
}
|
|
211
|
+
const ethLog = request.data.ethLog
|
|
209
212
|
|
|
210
213
|
const promises: Promise<ProcessResult>[] = []
|
|
211
|
-
let log: Log
|
|
212
|
-
if (request.data.ethLog) {
|
|
213
|
-
log = request.data.ethLog.log as Log
|
|
214
|
-
} else {
|
|
215
|
-
throw new ServerError(Status.INVALID_ARGUMENT, "Log can't be null")
|
|
216
|
-
}
|
|
217
|
-
|
|
218
214
|
for (const handlerId of request.handlerIds) {
|
|
219
215
|
const handler = this.eventHandlers[handlerId]
|
|
220
216
|
promises.push(
|
|
221
|
-
handler(
|
|
222
|
-
throw new ServerError(
|
|
217
|
+
handler(ethLog).catch((e) => {
|
|
218
|
+
throw new ServerError(
|
|
219
|
+
Status.INTERNAL,
|
|
220
|
+
'error processing log: ' + JSON.stringify(ethLog.log) + '\n' + errorString(e)
|
|
221
|
+
)
|
|
223
222
|
})
|
|
224
223
|
)
|
|
225
224
|
}
|
|
@@ -227,24 +226,19 @@ export class EthPlugin extends Plugin {
|
|
|
227
226
|
}
|
|
228
227
|
|
|
229
228
|
async processTrace(binding: DataBinding): Promise<ProcessResult> {
|
|
230
|
-
if (!binding.data) {
|
|
231
|
-
throw new ServerError(Status.INVALID_ARGUMENT, "Trace can't be empty")
|
|
232
|
-
}
|
|
233
|
-
let trace: Trace
|
|
234
|
-
if (binding.data.ethTrace?.trace) {
|
|
235
|
-
trace = binding.data.ethTrace.trace as Trace
|
|
236
|
-
} else {
|
|
229
|
+
if (!binding.data?.ethTrace?.trace) {
|
|
237
230
|
throw new ServerError(Status.INVALID_ARGUMENT, "Trace can't be null")
|
|
238
231
|
}
|
|
232
|
+
const ethTrace = binding.data.ethTrace
|
|
239
233
|
|
|
240
234
|
const promises: Promise<ProcessResult>[] = []
|
|
241
235
|
|
|
242
236
|
for (const handlerId of binding.handlerIds) {
|
|
243
237
|
promises.push(
|
|
244
|
-
this.traceHandlers[handlerId](
|
|
238
|
+
this.traceHandlers[handlerId](ethTrace).catch((e) => {
|
|
245
239
|
throw new ServerError(
|
|
246
240
|
Status.INTERNAL,
|
|
247
|
-
'error processing trace: ' + JSON.stringify(trace) + '\n' + errorString(e)
|
|
241
|
+
'error processing trace: ' + JSON.stringify(ethTrace.trace) + '\n' + errorString(e)
|
|
248
242
|
)
|
|
249
243
|
})
|
|
250
244
|
)
|
|
@@ -253,21 +247,19 @@ export class EthPlugin extends Plugin {
|
|
|
253
247
|
}
|
|
254
248
|
|
|
255
249
|
async processBlock(binding: DataBinding): Promise<ProcessResult> {
|
|
256
|
-
if (!binding.data) {
|
|
257
|
-
throw new ServerError(Status.INVALID_ARGUMENT, "Block can't be empty")
|
|
258
|
-
}
|
|
259
|
-
let block: Block
|
|
260
|
-
if (binding.data.ethBlock?.block) {
|
|
261
|
-
block = binding.data.ethBlock.block as Block
|
|
262
|
-
} else {
|
|
250
|
+
if (!binding.data?.ethBlock?.block) {
|
|
263
251
|
throw new ServerError(Status.INVALID_ARGUMENT, "Block can't be empty")
|
|
264
252
|
}
|
|
253
|
+
const ethBlock = binding.data.ethBlock
|
|
265
254
|
|
|
266
255
|
const promises: Promise<ProcessResult>[] = []
|
|
267
256
|
for (const handlerId of binding.handlerIds) {
|
|
268
257
|
promises.push(
|
|
269
|
-
this.blockHandlers[handlerId](
|
|
270
|
-
throw new ServerError(
|
|
258
|
+
this.blockHandlers[handlerId](ethBlock).catch((e) => {
|
|
259
|
+
throw new ServerError(
|
|
260
|
+
Status.INTERNAL,
|
|
261
|
+
'error processing block: ' + ethBlock.block?.number + '\n' + errorString(e)
|
|
262
|
+
)
|
|
271
263
|
})
|
|
272
264
|
)
|
|
273
265
|
}
|