@sentio/sdk 1.36.4-rc.1 → 1.37.0-rc.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/aptos/api.d.ts +1 -1
- package/lib/aptos/api.js +1 -1
- package/lib/aptos/api.js.map +1 -1
- package/lib/aptos/aptos-plugin.d.ts +2 -2
- package/lib/aptos/aptos-plugin.js +14 -19
- package/lib/aptos/aptos-plugin.js.map +1 -1
- package/lib/aptos/aptos-processor.d.ts +2 -2
- package/lib/aptos/aptos-processor.js +3 -3
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/context.d.ts +1 -1
- package/lib/aptos/context.js +2 -6
- package/lib/aptos/context.js.map +1 -1
- package/lib/binds.d.ts +1 -1
- package/lib/binds.js +2 -2
- package/lib/binds.js.map +1 -1
- package/lib/builtin/internal/eacaggregatorproxy_processor.js +18 -18
- package/lib/builtin/internal/eacaggregatorproxy_processor.js.map +1 -1
- package/lib/builtin/internal/erc1155_processor.js +5 -5
- package/lib/builtin/internal/erc1155_processor.js.map +1 -1
- package/lib/builtin/internal/erc20_processor.js +8 -8
- package/lib/builtin/internal/erc20_processor.js.map +1 -1
- package/lib/builtin/internal/erc20bytes_processor.js +6 -6
- package/lib/builtin/internal/erc20bytes_processor.js.map +1 -1
- package/lib/builtin/internal/erc721_processor.js +9 -9
- package/lib/builtin/internal/erc721_processor.js.map +1 -1
- package/lib/builtin/internal/weth9_processor.js +6 -6
- package/lib/builtin/internal/weth9_processor.js.map +1 -1
- package/lib/core/account-processor.d.ts +1 -1
- package/lib/core/account-processor.js +2 -2
- package/lib/core/account-processor.js.map +1 -1
- package/lib/core/base-context.d.ts +1 -1
- package/lib/core/base-context.js.map +1 -1
- package/lib/core/base-processor-template.d.ts +2 -2
- package/lib/core/base-processor-template.js +7 -21
- package/lib/core/base-processor-template.js.map +1 -1
- package/lib/core/base-processor.d.ts +1 -1
- package/lib/core/base-processor.js +6 -20
- package/lib/core/base-processor.js.map +1 -1
- package/lib/core/bind-options.d.ts +5 -6
- package/lib/core/bind-options.js.map +1 -1
- package/lib/core/context.d.ts +4 -5
- package/lib/core/context.js +6 -10
- package/lib/core/context.js.map +1 -1
- package/lib/core/eth-plugin.d.ts +2 -2
- package/lib/core/eth-plugin.js +8 -12
- package/lib/core/eth-plugin.js.map +1 -1
- package/lib/core/event-tracker.d.ts +1 -1
- package/lib/core/event-tracker.js +2 -2
- package/lib/core/event-tracker.js.map +1 -1
- package/lib/core/exporter.d.ts +1 -1
- package/lib/core/exporter.js +2 -2
- package/lib/core/exporter.js.map +1 -1
- package/lib/core/generic-processor.test.js.map +1 -1
- package/lib/core/index.d.ts +1 -1
- package/lib/core/index.js +2 -1
- package/lib/core/index.js.map +1 -1
- package/lib/core/logger.d.ts +1 -1
- package/lib/core/logger.js +5 -5
- package/lib/core/logger.js.map +1 -1
- package/lib/core/meter.d.ts +2 -2
- package/lib/core/meter.js +10 -10
- package/lib/core/meter.js.map +1 -1
- package/lib/core/numberish.d.ts +3 -3
- package/lib/core/numberish.js +18 -12
- package/lib/core/numberish.js.map +1 -1
- package/lib/core/numberish.test.js.map +1 -1
- package/lib/core/solana-context.d.ts +2 -3
- package/lib/core/solana-context.js.map +1 -1
- package/lib/core/solana-options.d.ts +2 -3
- package/lib/core/solana-options.js.map +1 -1
- package/lib/core/solana-plugin.d.ts +2 -2
- package/lib/core/solana-plugin.js +6 -6
- package/lib/core/solana-plugin.js.map +1 -1
- package/lib/core/solana-processor.d.ts +7 -8
- package/lib/core/solana-processor.js +5 -15
- package/lib/core/solana-processor.js.map +1 -1
- package/lib/core/sui-plugin.d.ts +2 -2
- package/lib/core/sui-plugin.js +5 -5
- package/lib/core/sui-plugin.js.map +1 -1
- package/lib/core/sui-processor.d.ts +8 -9
- package/lib/core/sui-processor.js +5 -15
- package/lib/core/sui-processor.js.map +1 -1
- package/lib/index.d.ts +2 -3
- package/lib/index.js +3 -5
- package/lib/index.js.map +1 -1
- package/lib/processor-runner.js +4 -4
- package/lib/processor-runner.js.map +1 -1
- package/lib/service.d.ts +3 -4
- package/lib/service.js +7 -11
- package/lib/service.js.map +1 -1
- package/lib/target-ethers-sentio/file.js +1 -0
- package/lib/target-ethers-sentio/file.js.map +1 -1
- package/lib/target-ethers-sentio/view-function.js +1 -1
- package/lib/testing/metric-utils.d.ts +1 -1
- package/lib/testing/metric-utils.js.map +1 -1
- package/lib/testing/test-processor-server.d.ts +3 -3
- package/lib/testing/test-processor-server.js +10 -22
- package/lib/testing/test-processor-server.js.map +1 -1
- package/lib/utils/conversion.d.ts +1 -1
- package/lib/utils/conversion.js.map +1 -1
- package/lib/utils/dex-price.test.js.map +1 -1
- package/lib/utils/erc20.test.js.map +1 -1
- package/lib/utils/price.d.ts +10 -10
- package/lib/utils/price.js +1 -1
- package/lib/utils/price.js.map +1 -1
- package/package.json +4 -2
- package/src/aptos/api.ts +1 -1
- package/src/aptos/aptos-plugin.ts +10 -11
- package/src/aptos/aptos-processor.ts +2 -2
- package/src/aptos/context.ts +3 -4
- package/src/binds.ts +1 -1
- package/src/builtin/internal/eacaggregatorproxy_processor.ts +19 -18
- package/src/builtin/internal/erc1155_processor.ts +6 -5
- package/src/builtin/internal/erc20_processor.ts +9 -8
- package/src/builtin/internal/erc20bytes_processor.ts +7 -6
- package/src/builtin/internal/erc721_processor.ts +10 -9
- package/src/builtin/internal/weth9_processor.ts +7 -6
- package/src/core/account-processor.ts +1 -1
- package/src/core/base-context.ts +1 -1
- package/src/core/base-processor-template.ts +6 -15
- package/src/core/base-processor.ts +4 -13
- package/src/core/bind-options.ts +5 -6
- package/src/core/context.ts +10 -11
- package/src/core/eth-plugin.ts +3 -4
- package/src/core/event-tracker.ts +2 -2
- package/src/core/exporter.ts +1 -1
- package/src/core/index.ts +1 -1
- package/src/core/logger.ts +1 -1
- package/src/core/meter.ts +2 -2
- package/src/core/numberish.ts +12 -6
- package/src/core/solana-context.ts +2 -3
- package/src/core/solana-options.ts +2 -4
- package/src/core/solana-plugin.ts +3 -3
- package/src/core/solana-processor.ts +10 -17
- package/src/core/sui-plugin.ts +3 -8
- package/src/core/sui-processor.ts +11 -18
- package/src/index.ts +3 -5
- package/src/processor-runner.ts +3 -3
- package/src/service.ts +5 -5
- package/src/target-ethers-sentio/file.ts +1 -0
- package/src/target-ethers-sentio/view-function.ts +1 -1
- package/src/testing/metric-utils.ts +1 -1
- package/src/testing/test-processor-server.ts +6 -16
- package/src/types/global.d.ts +2 -2
- package/src/utils/conversion.ts +1 -1
- package/src/utils/price.ts +1 -1
- package/lib/gen/builtin.d.ts +0 -6
- package/lib/gen/builtin.js +0 -3
- package/lib/gen/builtin.js.map +0 -1
- package/lib/gen/chainquery/protos/chainquery.d.ts +0 -400
- package/lib/gen/chainquery/protos/chainquery.js +0 -972
- package/lib/gen/chainquery/protos/chainquery.js.map +0 -1
- package/lib/gen/google/protobuf/empty.d.ts +0 -16
- package/lib/gen/google/protobuf/empty.js +0 -47
- package/lib/gen/google/protobuf/empty.js.map +0 -1
- package/lib/gen/google/protobuf/struct.d.ts +0 -73
- package/lib/gen/google/protobuf/struct.js +0 -371
- package/lib/gen/google/protobuf/struct.js.map +0 -1
- package/lib/gen/google/protobuf/timestamp.d.ts +0 -18
- package/lib/gen/google/protobuf/timestamp.js +0 -71
- package/lib/gen/google/protobuf/timestamp.js.map +0 -1
- package/lib/gen/index.d.ts +0 -2
- package/lib/gen/index.js +0 -19
- package/lib/gen/index.js.map +0 -1
- package/lib/gen/processor/protos/processor.d.ts +0 -826
- package/lib/gen/processor/protos/processor.js +0 -3988
- package/lib/gen/processor/protos/processor.js.map +0 -1
- package/lib/gen/service/price/protos/price.d.ts +0 -85
- package/lib/gen/service/price/protos/price.js +0 -269
- package/lib/gen/service/price/protos/price.js.map +0 -1
- package/lib/plugin.d.ts +0 -15
- package/lib/plugin.js +0 -32
- package/lib/plugin.js.map +0 -1
- package/lib/state/processor-state.d.ts +0 -3
- package/lib/state/processor-state.js +0 -8
- package/lib/state/processor-state.js.map +0 -1
- package/lib/state/state-storage.d.ts +0 -17
- package/lib/state/state-storage.js +0 -60
- package/lib/state/state-storage.js.map +0 -1
- package/lib/state/state-storage.test.d.ts +0 -1
- package/lib/state/state-storage.test.js.map +0 -1
- package/src/gen/builtin.ts +0 -22
- package/src/gen/chainquery/protos/chainquery.ts +0 -1212
- package/src/gen/google/protobuf/empty.ts +0 -58
- package/src/gen/google/protobuf/struct.ts +0 -422
- package/src/gen/google/protobuf/timestamp.ts +0 -85
- package/src/gen/index.ts +0 -3
- package/src/gen/processor/protos/processor.ts +0 -4619
- package/src/gen/service/price/protos/price.ts +0 -329
- package/src/plugin.ts +0 -41
- package/src/state/processor-state.ts +0 -3
- package/src/state/state-storage.ts +0 -65
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eth-plugin.js","sourceRoot":"","sources":["../../src/core/eth-plugin.ts"],"names":[],"mappings":";;;;;;AAAA,sCAAiD;AACjD,iEAS0C;AAC1C,wCAAgH;AAEhH,yCAA+C;AAG/C,oCAAyC;AACzC,2DAA2D;AAC3D,gDAAuB;AAEvB,MAAa,SAAS;IACpB,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,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,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,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;AAxOD,8BAwOC;AAED,sBAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,SAAS,EAAE,CAAC,CAAA","sourcesContent":["import { Plugin, PluginManager } from '../plugin'\nimport {\n AccountConfig,\n ContractConfig,\n DataBinding,\n HandlerType,\n LogFilter,\n LogHandlerConfig,\n ProcessConfigResponse,\n ProcessResult,\n} from '../gen/processor/protos/processor'\nimport { DEFAULT_MAX_BLOCK, errorString, mergeProcessResults, USER_PROCESSOR, Utf8ArrayToStr } from '../service'\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 Long from 'long'\n\nexport class EthPlugin implements 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 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: DEFAULT_MAX_BLOCK,\n instructionConfig: undefined,\n aptosEventConfigs: [],\n aptosCallConfigs: [],\n }\n if (processor.config.endBlock) {\n contractConfig.endBlock = processor.config.endBlock\n }\n\n // Step 1. Prepare all the block handlers\n for (const blockHandler of processor.blockHandlers) {\n const handlerId = this.blockHandlers.push(blockHandler.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 ? Long.fromValue(processor.config.startBlock) : Long.ZERO,\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 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 const jsonString = Utf8ArrayToStr(request.data.raw)\n log = JSON.parse(jsonString)\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 const jsonString = Utf8ArrayToStr(binding.data.raw)\n trace = JSON.parse(jsonString)\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 const jsonString = Utf8ArrayToStr(binding.data.raw)\n block = JSON.parse(jsonString)\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,uCAAoD;AACpD,2CASuB;AACvB,wCAAgH;AAEhH,yCAA+C;AAG/C,oCAAyC;AACzC,2DAA2D;AAE3D,MAAa,SAAS;IACpB,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,KAAK,MAAM,SAAS,IAAI,sBAAc,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;YAC3D,yDA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,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;AAxOD,8BAwOC;AAED,oBAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,SAAS,EAAE,CAAC,CAAA","sourcesContent":["import { Plugin, PluginManager } from '@sentio/base'\nimport {\n AccountConfig,\n ContractConfig,\n DataBinding,\n HandlerType,\n LogFilter,\n LogHandlerConfig,\n ProcessConfigResponse,\n ProcessResult,\n} from '@sentio/protos'\nimport { DEFAULT_MAX_BLOCK, errorString, mergeProcessResults, USER_PROCESSOR, Utf8ArrayToStr } from '../service'\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'\n\nexport class EthPlugin implements 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 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: DEFAULT_MAX_BLOCK,\n instructionConfig: undefined,\n aptosEventConfigs: [],\n aptosCallConfigs: [],\n }\n if (processor.config.endBlock) {\n contractConfig.endBlock = processor.config.endBlock\n }\n\n // Step 1. Prepare all the block handlers\n for (const blockHandler of processor.blockHandlers) {\n const handlerId = this.blockHandlers.push(blockHandler.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 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 const jsonString = Utf8ArrayToStr(request.data.raw)\n log = JSON.parse(jsonString)\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 const jsonString = Utf8ArrayToStr(binding.data.raw)\n trace = JSON.parse(jsonString)\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 const jsonString = Utf8ArrayToStr(binding.data.raw)\n block = JSON.parse(jsonString)\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,6 +1,6 @@
|
|
|
1
1
|
import { BaseContext } from './base-context';
|
|
2
2
|
import { NamedResultDescriptor } from './metadata';
|
|
3
|
-
import { MapStateStorage } from '
|
|
3
|
+
import { MapStateStorage } from '@sentio/base';
|
|
4
4
|
export interface Event {
|
|
5
5
|
distinctId: string;
|
|
6
6
|
payload?: Record<string, string>;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AccountEventTracker = exports.EventTracker = exports.EventTrackerState = void 0;
|
|
4
4
|
const metadata_1 = require("./metadata");
|
|
5
|
-
const
|
|
6
|
-
class EventTrackerState extends
|
|
5
|
+
const base_1 = require("@sentio/base");
|
|
6
|
+
class EventTrackerState extends base_1.MapStateStorage {
|
|
7
7
|
static INSTANCE = new EventTrackerState();
|
|
8
8
|
}
|
|
9
9
|
exports.EventTrackerState = EventTrackerState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-tracker.js","sourceRoot":"","sources":["../../src/core/event-tracker.ts"],"names":[],"mappings":";;;AAEA,yCAAkD;AAClD,
|
|
1
|
+
{"version":3,"file":"event-tracker.js","sourceRoot":"","sources":["../../src/core/event-tracker.ts"],"names":[],"mappings":";;;AAEA,yCAAkD;AAClD,uCAA8C;AAgB9C,MAAa,iBAAkB,SAAQ,sBAA6B;IAClE,MAAM,CAAC,QAAQ,GAAG,IAAI,iBAAiB,EAAE,CAAA;;AAD3C,8CAEC;AAED,iDAAiD;AACjD,MAAa,YAAa,SAAQ,gCAAqB;IACrD,MAAM,CAAC,eAAe,GAAmB;QACvC,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,IAAI;KACb,CAAA;IAED,MAAM,CAAC,QAAQ,CAAC,SAAiB,EAAE,OAAwB;QACzD,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,SAAS,EAAE,EAAE,GAAG,YAAY,CAAC,eAAe,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;QAC5F,OAAO,iBAAiB,CAAC,QAAQ,CAAC,aAAa,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IACrE,CAAC;IAED,OAAO,CAAgB;IACvB,YAAsB,SAAiB,EAAE,OAAuB;QAC9D,KAAK,CAAC,SAAS,CAAC,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,UAAU,CAAC,GAAgB,EAAE,KAAY;QACvC,MAAM,GAAG,GAAwB;YAC/B,QAAQ,EAAE,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;YACxC,gBAAgB,EAAE,KAAK,CAAC,UAAU;YAClC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YAC9B,WAAW,EAAE,SAAS;SACvB,CAAA;QACD,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC1B,CAAC;;AAzBH,oCA0BC;AAED,MAAa,mBAAoB,SAAQ,YAAY;IACnD,MAAM,CAAC,eAAe,GAAmB;QACvC,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,IAAI;QACZ,cAAc,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;KAC3B,CAAA;IAED,MAAM,CAAC,QAAQ,CAAC,SAAkB,EAAE,OAAwB;QAC1D,IAAI,SAAS,EAAE;YACb,SAAS,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;SAC1C;aAAM;YACL,SAAS,GAAG,MAAM,CAAA;SACnB;QACD,MAAM,OAAO,GAAG,IAAI,mBAAmB,CAAC,SAAS,EAAE,EAAE,GAAG,mBAAmB,CAAC,eAAe,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;QAC1G,OAAO,iBAAiB,CAAC,QAAQ,CAAC,aAAa,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IACrE,CAAC;;AAfH,kDAgBC","sourcesContent":["import { BaseContext } from './base-context'\nimport { EventTrackingResult } from '@sentio/protos'\nimport { NamedResultDescriptor } from './metadata'\nimport { MapStateStorage } from '@sentio/base'\n\nexport interface Event {\n // The unique identifier of main identity associate with an event\n // .e.g user id / toekn address / account address / contract address id\n //\n distinctId: string\n payload?: Record<string, string>\n}\n\nexport interface TrackerOptions {\n totalByDay?: boolean\n unique?: boolean\n distinctByDays?: number[]\n}\n\nexport class EventTrackerState extends MapStateStorage<EventTracker> {\n static INSTANCE = new EventTrackerState()\n}\n\n// Track Event with an identity associate with it\nexport class EventTracker extends NamedResultDescriptor {\n static DEFAULT_OPTIONS: TrackerOptions = {\n totalByDay: true,\n unique: true,\n }\n\n static register(eventName: string, options?: TrackerOptions) {\n const tracker = new EventTracker(eventName, { ...EventTracker.DEFAULT_OPTIONS, ...options })\n return EventTrackerState.INSTANCE.getOrSetValue(eventName, tracker)\n }\n\n options: TrackerOptions\n protected constructor(eventName: string, options: TrackerOptions) {\n super(eventName)\n this.options = options\n }\n\n trackEvent(ctx: BaseContext, event: Event) {\n const res: EventTrackingResult = {\n metadata: ctx.getMetaData(this.name, {}),\n distinctEntityId: event.distinctId,\n attributes: JSON.stringify({}),\n runtimeInfo: undefined,\n }\n ctx.res.events.push(res)\n }\n}\n\nexport class AccountEventTracker extends EventTracker {\n static DEFAULT_OPTIONS: TrackerOptions = {\n totalByDay: true,\n unique: true,\n distinctByDays: [1, 7, 30],\n }\n\n static register(eventName?: string, options?: TrackerOptions) {\n if (eventName) {\n eventName = ['user', eventName].join('_')\n } else {\n eventName = 'user'\n }\n const tracker = new AccountEventTracker(eventName, { ...AccountEventTracker.DEFAULT_OPTIONS, ...options })\n return EventTrackerState.INSTANCE.getOrSetValue(eventName, tracker)\n }\n}\n"]}
|
package/lib/core/exporter.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseContext } from './base-context';
|
|
2
2
|
import { NamedResultDescriptor } from './metadata';
|
|
3
|
-
import { MapStateStorage } from '
|
|
3
|
+
import { MapStateStorage } from '@sentio/base';
|
|
4
4
|
export declare type Export = Record<string, any>;
|
|
5
5
|
export declare class ExporterState extends MapStateStorage<Exporter> {
|
|
6
6
|
static INSTANCE: ExporterState;
|
package/lib/core/exporter.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Exporter = exports.ExporterState = void 0;
|
|
4
4
|
const metadata_1 = require("./metadata");
|
|
5
|
-
const
|
|
6
|
-
class ExporterState extends
|
|
5
|
+
const base_1 = require("@sentio/base");
|
|
6
|
+
class ExporterState extends base_1.MapStateStorage {
|
|
7
7
|
static INSTANCE = new ExporterState();
|
|
8
8
|
}
|
|
9
9
|
exports.ExporterState = ExporterState;
|
package/lib/core/exporter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exporter.js","sourceRoot":"","sources":["../../src/core/exporter.ts"],"names":[],"mappings":";;;AAEA,yCAAkD;AAClD,
|
|
1
|
+
{"version":3,"file":"exporter.js","sourceRoot":"","sources":["../../src/core/exporter.ts"],"names":[],"mappings":";;;AAEA,yCAAkD;AAClD,uCAA8C;AAI9C,MAAa,aAAc,SAAQ,sBAAyB;IAC1D,MAAM,CAAC,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAA;;AADvC,sCAEC;AAED,MAAa,QAAS,SAAQ,gCAAqB;IACjD,MAAM,CAAC,QAAQ,CAAC,IAAY,EAAE,OAAe;QAC3C,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAC5C,OAAO,aAAa,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;IAC7D,CAAC;IAED,OAAO,CAAQ;IACf,YAAsB,IAAY,EAAE,OAAe;QACjD,KAAK,CAAC,IAAI,CAAC,CAAA;QACX,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,IAAI,CAAC,GAAgB,EAAE,IAAY;QACjC,MAAM,GAAG,GAAiB;YACxB,QAAQ,EAAE,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;YACxC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;YAC7B,WAAW,EAAE,SAAS;SACvB,CAAA;QACD,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC3B,CAAC;CACF;AApBD,4BAoBC","sourcesContent":["import { BaseContext } from './base-context'\nimport { ExportResult } from '@sentio/sdk'\nimport { NamedResultDescriptor } from './metadata'\nimport { MapStateStorage } from '@sentio/base'\n\nexport type Export = Record<string, any>\n\nexport class ExporterState extends MapStateStorage<Exporter> {\n static INSTANCE = new ExporterState()\n}\n\nexport class Exporter extends NamedResultDescriptor {\n static register(name: string, channel: string) {\n const exporter = new Exporter(name, channel)\n return ExporterState.INSTANCE.getOrSetValue(name, exporter)\n }\n\n channel: string\n protected constructor(name: string, channel: string) {\n super(name)\n this.channel = channel\n }\n\n emit(ctx: BaseContext, data: Export) {\n const res: ExportResult = {\n metadata: ctx.getMetaData(this.name, {}),\n payload: JSON.stringify(data),\n runtimeInfo: undefined,\n }\n ctx.res.exports.push(res)\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generic-processor.test.js","sourceRoot":"","sources":["../../src/core/generic-processor.test.ts"],"names":[],"mappings":";AAAA,gCAAgC;;AAEhC,+BAA6B;AAE7B,
|
|
1
|
+
{"version":3,"file":"generic-processor.test.js","sourceRoot":"","sources":["../../src/core/generic-processor.test.ts"],"names":[],"mappings":";AAAA,gCAAgC;;AAEhC,+BAA6B;AAE7B,2CAA4C;AAE5C,2DAAsD;AACtD,wCAAmE;AAEnE,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,MAAM,OAAO,GAAG,IAAI,6BAAmB,CAAC,GAAG,EAAE;QAC3C,oCAAgB,CAAC,IAAI,CACnB;YACE,yEAAyE;YACzE,yEAAyE;SAC1E,EACD,EAAE,OAAO,EAAE,4CAA4C,EAAE,CAC1D,CAAC,WAAW,CAAC,UAAU,GAAG,EAA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,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QAC7D,IAAA,aAAM,EAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,oBAAW,CAAC,OAAO,CAAC,CAAA;IACrE,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,wCAAwC,EAAE,KAAK,IAAI,EAAE;QACxD,MAAM,MAAM,GACV,ohBAAohB,CAAA;QACthB,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;QACrD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAA;IAClC,CAAC,CAAC,CAAA;IAEF,MAAM,OAAO,GAAG;QACd,WAAW,EAAE,QAAQ;QACrB,SAAS,EAAE,oEAAoE;QAC/E,gBAAgB,EAAE,GAAG;QACrB,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,4CAA4C;QACrD,IAAI,EAAE,oEAAoE;QAC1E,MAAM,EAAE;YACN,oEAAoE;YACpE,oEAAoE;YACpE,oEAAoE;SACrE;QACD,eAAe,EAAE,oEAAoE;QACrF,QAAQ,EAAE,GAAG;KACd,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["// TODO move out of this package\n\nimport { expect } from 'chai'\n\nimport { HandlerType } from '@sentio/protos'\n\nimport { GenericProcessor } from './generic-processor'\nimport { TestProcessorServer, firstCounterValue } from '../testing'\n\ndescribe('Test Generic Processor', () => {\n const service = new TestProcessorServer(() => {\n GenericProcessor.bind(\n [\n 'event Transfer(address indexed from, address indexed to, uint256 value)',\n 'event Approval(address indexed from, address indexed to, uint256 value)',\n ],\n { address: '0x1E4EDE388cbc9F4b5c79681B7f94d36a11ABEBC9' }\n ).onAllEvents(function (log, ctx) {\n ctx.meter.Counter('event_num').add(1)\n })\n\n GenericProcessor.bind('event WalletCreated(address wallet, address owner)', {\n address: '0x57E037F4d2c8BEa011Ad8a9A5AF4AaEEd508650f',\n }).onAllEvents(function (log, ctx) {\n ctx.meter.Counter('wallet').add(1)\n })\n })\n\n beforeAll(async () => {\n await service.start()\n })\n\n test('check configuration', async () => {\n const config = await service.getConfig({})\n expect(config.contractConfigs).length(2)\n expect(config.contractConfigs?.[0].contract?.name).equals('Generic')\n })\n\n test('Check log dispatch', async () => {\n const res = await service.testLogs([logData, logData])\n const counters = res.result?.counters\n expect(counters).length(2)\n expect(firstCounterValue(res.result, 'event_num')).equals(1n)\n expect(counters?.[0].runtimeInfo?.from).equals(HandlerType.ETH_LOG)\n })\n\n test('Check log dispatch no buffer over rune', async () => {\n const logStr =\n '{\"address\":\"0x57e037f4d2c8bea011ad8a9a5af4aaeed508650f\",\"topics\":[\"0x5b03bfed1c14a02bdeceb5fa582eb1a5765fc0bc64ca0e6af4c20afc9487f081\"],\"data\":\"0x00000000000000000000000093269483a70c68d5c5bb63aac1e8f4ac59f498800000000000000000000000000c520e51c055cf63bab075715c1b860b2e9b8e24\",\"blockNumber\":\"0xc9d6d7\",\"transactionHash\":\"0x208af3250499672c2f07138b9aa236153c65c78ae4341b23c2763017afdd61a2\",\"transactionIndex\":\"0xf3\",\"blockHash\":\"0x6e3b100c34b510049e922fbe1c1dab1b0793be3d1229b632688e6a518cdd11b6\",\"logIndex\":\"0x14b\",\"removed\":false}'\n const res = await service.testLog(JSON.parse(logStr))\n console.log(JSON.stringify(res))\n })\n\n const logData = {\n blockNumber: 14213252,\n blockHash: '0x83d646fac9350b281def8c4c37626f9d8efc95df801287b848c719edf35cdbaf',\n transactionIndex: 347,\n removed: false,\n address: '0x1E4EDE388cbc9F4b5c79681B7f94d36a11ABEBC9',\n data: '0x00000000000000000000000000000000000000000000009a71db64810aaa0000',\n topics: [\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n '0x0000000000000000000000000000000000000000000000000000000000000000',\n '0x000000000000000000000000b329e39ebefd16f40d38f07643652ce17ca5bac1',\n ],\n transactionHash: '0x93355e0cb2c3490cb8a747029ff2dc8cdbde2407025b8391398436955afae303',\n logIndex: 428,\n }\n})\n"]}
|
package/lib/core/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { BigDecimal } from './big-decimal';
|
|
|
2
2
|
export { ContractContext, ContractView, BoundContractView } from './context';
|
|
3
3
|
export { CounterBinding, Meter, GaugeBinding, Counter, Gauge, MetricOptions } from './meter';
|
|
4
4
|
export { EventTracker, AccountEventTracker } from './event-tracker';
|
|
5
|
-
export { type Numberish, toBigInteger, toMetricValue } from './numberish';
|
|
5
|
+
export { type Numberish, toBigInteger, toMetricValue, toBlockTag } from './numberish';
|
|
6
6
|
export { BindOptions } from './bind-options';
|
|
7
7
|
export { BaseProcessor } from './base-processor';
|
|
8
8
|
export { GenericProcessor } from './generic-processor';
|
package/lib/core/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SuiPlugin = exports.SolanaPlugin = exports.EthPlugin = exports.SolanaBaseProcessor = exports.SolanaBindOptions = exports.SolanaContext = exports.SuiBindOptions = exports.SuiBaseProcessor = exports.BaseProcessorTemplate = exports.GenericProcessor = exports.BaseProcessor = exports.BindOptions = exports.toMetricValue = exports.toBigInteger = exports.AccountEventTracker = exports.EventTracker = exports.MetricOptions = exports.Gauge = exports.Counter = exports.GaugeBinding = exports.Meter = exports.CounterBinding = exports.BoundContractView = exports.ContractView = exports.ContractContext = exports.BigDecimal = void 0;
|
|
3
|
+
exports.SuiPlugin = exports.SolanaPlugin = exports.EthPlugin = exports.SolanaBaseProcessor = exports.SolanaBindOptions = exports.SolanaContext = exports.SuiBindOptions = exports.SuiBaseProcessor = exports.BaseProcessorTemplate = exports.GenericProcessor = exports.BaseProcessor = exports.BindOptions = exports.toBlockTag = exports.toMetricValue = exports.toBigInteger = exports.AccountEventTracker = exports.EventTracker = exports.MetricOptions = exports.Gauge = exports.Counter = exports.GaugeBinding = exports.Meter = exports.CounterBinding = exports.BoundContractView = exports.ContractView = exports.ContractContext = exports.BigDecimal = void 0;
|
|
4
4
|
var big_decimal_1 = require("./big-decimal");
|
|
5
5
|
Object.defineProperty(exports, "BigDecimal", { enumerable: true, get: function () { return big_decimal_1.BigDecimal; } });
|
|
6
6
|
var context_1 = require("./context");
|
|
@@ -20,6 +20,7 @@ Object.defineProperty(exports, "AccountEventTracker", { enumerable: true, get: f
|
|
|
20
20
|
var numberish_1 = require("./numberish");
|
|
21
21
|
Object.defineProperty(exports, "toBigInteger", { enumerable: true, get: function () { return numberish_1.toBigInteger; } });
|
|
22
22
|
Object.defineProperty(exports, "toMetricValue", { enumerable: true, get: function () { return numberish_1.toMetricValue; } });
|
|
23
|
+
Object.defineProperty(exports, "toBlockTag", { enumerable: true, get: function () { return numberish_1.toBlockTag; } });
|
|
23
24
|
var bind_options_1 = require("./bind-options");
|
|
24
25
|
Object.defineProperty(exports, "BindOptions", { enumerable: true, get: function () { return bind_options_1.BindOptions; } });
|
|
25
26
|
var base_processor_1 = require("./base-processor");
|
package/lib/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAAjC,yGAAA,UAAU,OAAA;AACnB,qCAA4E;AAAnE,0GAAA,eAAe,OAAA;AAAE,uGAAA,YAAY,OAAA;AAAE,4GAAA,iBAAiB,OAAA;AACzD,iCAA4F;AAAnF,uGAAA,cAAc,OAAA;AAAE,8FAAA,KAAK,OAAA;AAAE,qGAAA,YAAY,OAAA;AAAE,gGAAA,OAAO,OAAA;AAAE,8FAAA,KAAK,OAAA;AAAE,sGAAA,aAAa,OAAA;AAC3E,iDAAmE;AAA1D,6GAAA,YAAY,OAAA;AAAE,oHAAA,mBAAmB,OAAA;AAC1C,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAAjC,yGAAA,UAAU,OAAA;AACnB,qCAA4E;AAAnE,0GAAA,eAAe,OAAA;AAAE,uGAAA,YAAY,OAAA;AAAE,4GAAA,iBAAiB,OAAA;AACzD,iCAA4F;AAAnF,uGAAA,cAAc,OAAA;AAAE,8FAAA,KAAK,OAAA;AAAE,qGAAA,YAAY,OAAA;AAAE,gGAAA,OAAO,OAAA;AAAE,8FAAA,KAAK,OAAA;AAAE,sGAAA,aAAa,OAAA;AAC3E,iDAAmE;AAA1D,6GAAA,YAAY,OAAA;AAAE,oHAAA,mBAAmB,OAAA;AAC1C,yCAAqF;AAA5D,yGAAA,YAAY,OAAA;AAAE,0GAAA,aAAa,OAAA;AAAE,uGAAA,UAAU,OAAA;AAEhE,+CAA4C;AAAnC,2GAAA,WAAW,OAAA;AAEpB,mDAAgD;AAAvC,+GAAA,aAAa,OAAA;AACtB,yDAAsD;AAA7C,qHAAA,gBAAgB,OAAA;AACzB,qEAAiE;AAAxD,gIAAA,qBAAqB,OAAA;AAC9B,iDAAkE;AAAzD,iHAAA,gBAAgB,OAAA;AAAE,+GAAA,cAAc,OAAA;AAEzC,mDAAgD;AAAvC,+GAAA,aAAa,OAAA;AACtB,mDAAoD;AAA3C,mHAAA,iBAAiB,OAAA;AAC1B,uDAAwD;AAA/C,uHAAA,mBAAmB,OAAA;AAI5B,2CAAwC;AAA/B,uGAAA,SAAS,OAAA;AAClB,iDAA8C;AAArC,6GAAA,YAAY,OAAA;AACrB,2CAAwC;AAA/B,uGAAA,SAAS,OAAA","sourcesContent":["export { BigDecimal } from './big-decimal'\nexport { ContractContext, ContractView, BoundContractView } from './context'\nexport { CounterBinding, Meter, GaugeBinding, Counter, Gauge, MetricOptions } from './meter'\nexport { EventTracker, AccountEventTracker } from './event-tracker'\nexport { type Numberish, toBigInteger, toMetricValue, toBlockTag } from './numberish'\n\nexport { BindOptions } from './bind-options'\n\nexport { BaseProcessor } from './base-processor'\nexport { GenericProcessor } from './generic-processor'\nexport { BaseProcessorTemplate } from './base-processor-template'\nexport { SuiBaseProcessor, SuiBindOptions } from './sui-processor'\n\nexport { SolanaContext } from './solana-context'\nexport { SolanaBindOptions } from './solana-options'\nexport { SolanaBaseProcessor } from './solana-processor'\n\nexport type { TypedCallTrace, Trace } from './trace'\n\nexport { EthPlugin } from './eth-plugin'\nexport { SolanaPlugin } from './solana-plugin'\nexport { SuiPlugin } from './sui-plugin'\n"]}
|
package/lib/core/logger.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseContext } from './base-context';
|
|
2
|
-
import { LogLevel } from '
|
|
2
|
+
import { LogLevel } from '@sentio/protos';
|
|
3
3
|
import { NamedResultDescriptor } from './metadata';
|
|
4
4
|
export declare type Attributes = Record<string, any>;
|
|
5
5
|
export declare class Logger extends NamedResultDescriptor {
|
package/lib/core/logger.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Logger = void 0;
|
|
4
|
-
const
|
|
4
|
+
const protos_1 = require("@sentio/protos");
|
|
5
5
|
const metadata_1 = require("./metadata");
|
|
6
6
|
class Logger extends metadata_1.NamedResultDescriptor {
|
|
7
7
|
ctx;
|
|
@@ -26,16 +26,16 @@ class Logger extends metadata_1.NamedResultDescriptor {
|
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
info(msg, attributes = {}) {
|
|
29
|
-
this.log(
|
|
29
|
+
this.log(protos_1.LogLevel.INFO, msg, attributes);
|
|
30
30
|
}
|
|
31
31
|
warn(msg, attributes = {}) {
|
|
32
|
-
this.log(
|
|
32
|
+
this.log(protos_1.LogLevel.WARNING, msg, attributes);
|
|
33
33
|
}
|
|
34
34
|
error(msg, attributes = {}) {
|
|
35
|
-
this.log(
|
|
35
|
+
this.log(protos_1.LogLevel.ERROR, msg, attributes);
|
|
36
36
|
}
|
|
37
37
|
critical(msg, attributes = {}) {
|
|
38
|
-
this.log(
|
|
38
|
+
this.log(protos_1.LogLevel.CRITICAL, msg, attributes);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
exports.Logger = Logger;
|
package/lib/core/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/core/logger.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/core/logger.ts"],"names":[],"mappings":";;;AACA,2CAAyC;AACzC,yCAAkD;AAIlD,MAAa,MAAO,SAAQ,gCAAqB;IAC9B,GAAG,CAAa;IAEjC,YAAY,GAAgB,EAAE,IAAI,GAAG,EAAE;QACrC,KAAK,CAAC,IAAI,CAAC,CAAA;QACX,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAED,QAAQ,CAAC,IAAY;QACnB,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IACnC,CAAC;IAED,GAAG,CAAC,KAAe,EAAE,OAAY,EAAE,aAAyB,EAAE;QAC5D,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,CAAC,OAAO,YAAY,MAAM,CAAC,EAAE;YAC/D,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;SAClC;QAED,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;YACrB,mBAAmB;YACnB,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;YAC7C,KAAK;YACL,OAAO;YACP,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;YACtC,WAAW,EAAE,SAAS;SACvB,CAAC,CAAA;IACJ,CAAC;IAED,IAAI,CAAC,GAAQ,EAAE,aAAyB,EAAE;QACxC,IAAI,CAAC,GAAG,CAAC,iBAAQ,CAAC,IAAI,EAAE,GAAG,EAAE,UAAU,CAAC,CAAA;IAC1C,CAAC;IAED,IAAI,CAAC,GAAQ,EAAE,aAAyB,EAAE;QACxC,IAAI,CAAC,GAAG,CAAC,iBAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,UAAU,CAAC,CAAA;IAC7C,CAAC;IAED,KAAK,CAAC,GAAQ,EAAE,aAAyB,EAAE;QACzC,IAAI,CAAC,GAAG,CAAC,iBAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,UAAU,CAAC,CAAA;IAC3C,CAAC;IAED,QAAQ,CAAC,GAAQ,EAAE,aAAyB,EAAE;QAC5C,IAAI,CAAC,GAAG,CAAC,iBAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE,UAAU,CAAC,CAAA;IAC9C,CAAC;CACF;AA1CD,wBA0CC","sourcesContent":["import { BaseContext } from './base-context'\nimport { LogLevel } from '@sentio/protos'\nimport { NamedResultDescriptor } from './metadata'\n\nexport type Attributes = Record<string, any>\n\nexport class Logger extends NamedResultDescriptor {\n private readonly ctx: BaseContext\n\n constructor(ctx: BaseContext, name = '') {\n super(name)\n this.ctx = ctx\n }\n\n withName(name: string) {\n return new Logger(this.ctx, name)\n }\n\n log(level: LogLevel, message: any, attributes: Attributes = {}) {\n if (typeof message !== 'string' && !(message instanceof String)) {\n message = JSON.stringify(message)\n }\n\n this.ctx.res.logs.push({\n // name: this.name,\n metadata: this.ctx.getMetaData(this.name, {}), // GetRecordMetaData(this.ctx, this, {}),\n level,\n message,\n attributes: JSON.stringify(attributes),\n runtimeInfo: undefined,\n })\n }\n\n info(msg: any, attributes: Attributes = {}) {\n this.log(LogLevel.INFO, msg, attributes)\n }\n\n warn(msg: any, attributes: Attributes = {}) {\n this.log(LogLevel.WARNING, msg, attributes)\n }\n\n error(msg: any, attributes: Attributes = {}) {\n this.log(LogLevel.ERROR, msg, attributes)\n }\n\n critical(msg: any, attributes: Attributes = {}) {\n this.log(LogLevel.CRITICAL, msg, attributes)\n }\n}\n"]}
|
package/lib/core/meter.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BaseContext } from './base-context';
|
|
2
2
|
import { Numberish } from './numberish';
|
|
3
3
|
import { Labels, NamedResultDescriptor } from './metadata';
|
|
4
|
-
import { AggregationConfig, MetricConfig, MetricType } from '
|
|
5
|
-
import { MapStateStorage } from '
|
|
4
|
+
import { AggregationConfig, MetricConfig, MetricType } from '@sentio/protos';
|
|
5
|
+
import { MapStateStorage } from '@sentio/base';
|
|
6
6
|
export declare function normalizeName(name: string): string;
|
|
7
7
|
export declare function normalizeKey(name: string): string;
|
|
8
8
|
export declare function normalizeValue(name: string): string;
|
package/lib/core/meter.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Meter = exports.GaugeBinding = exports.Gauge = exports.CounterBinding = exports.Counter = exports.MetricState = exports.Metric = exports.CounterOptions = exports.MetricOptions = exports.normalizeLabels = exports.normalizeValue = exports.normalizeKey = exports.normalizeName = void 0;
|
|
4
4
|
const numberish_1 = require("./numberish");
|
|
5
5
|
const metadata_1 = require("./metadata");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const protos_1 = require("@sentio/protos");
|
|
7
|
+
const base_1 = require("@sentio/base");
|
|
8
8
|
function normalizeName(name) {
|
|
9
9
|
const regex = new RegExp('![_.a-zA-Z0-9]');
|
|
10
10
|
return name.slice(0, 100).replace(regex, '_');
|
|
@@ -50,20 +50,20 @@ class Metric extends metadata_1.NamedResultDescriptor {
|
|
|
50
50
|
config;
|
|
51
51
|
constructor(type, name, option) {
|
|
52
52
|
super(name);
|
|
53
|
-
this.config =
|
|
53
|
+
this.config = protos_1.MetricConfig.fromPartial({ name: this.name, type: type, ...option });
|
|
54
54
|
const aggregationConfig = this.config.aggregationConfig;
|
|
55
55
|
if (aggregationConfig && aggregationConfig.intervalInMinutes.length) {
|
|
56
56
|
if (aggregationConfig.intervalInMinutes.length > 1) {
|
|
57
57
|
console.error('current only support one intervalInMinutes, only first interval will be used for', name);
|
|
58
58
|
}
|
|
59
59
|
if (aggregationConfig.intervalInMinutes[0] > 0 && aggregationConfig.types.length === 0) {
|
|
60
|
-
aggregationConfig.types = [
|
|
60
|
+
aggregationConfig.types = [protos_1.AggregationType.SUM, protos_1.AggregationType.COUNT];
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
exports.Metric = Metric;
|
|
66
|
-
class MetricState extends
|
|
66
|
+
class MetricState extends base_1.MapStateStorage {
|
|
67
67
|
static INSTANCE = new MetricState();
|
|
68
68
|
getOrRegisterMetric(type, name, option) {
|
|
69
69
|
const metricMap = this.getOrRegister();
|
|
@@ -72,7 +72,7 @@ class MetricState extends state_storage_1.MapStateStorage {
|
|
|
72
72
|
throw Error(`redefine ${name} of metric type ${type} that is previously ${metric.config.type}`);
|
|
73
73
|
}
|
|
74
74
|
if (!metric) {
|
|
75
|
-
if (type ===
|
|
75
|
+
if (type === protos_1.MetricType.COUNTER) {
|
|
76
76
|
metric = new Counter(name, option);
|
|
77
77
|
}
|
|
78
78
|
else {
|
|
@@ -86,10 +86,10 @@ class MetricState extends state_storage_1.MapStateStorage {
|
|
|
86
86
|
exports.MetricState = MetricState;
|
|
87
87
|
class Counter extends Metric {
|
|
88
88
|
static register(name, option) {
|
|
89
|
-
return MetricState.INSTANCE.getOrRegisterMetric(
|
|
89
|
+
return MetricState.INSTANCE.getOrRegisterMetric(protos_1.MetricType.COUNTER, name, option);
|
|
90
90
|
}
|
|
91
91
|
constructor(name, option) {
|
|
92
|
-
super(
|
|
92
|
+
super(protos_1.MetricType.COUNTER, name, option);
|
|
93
93
|
}
|
|
94
94
|
add(ctx, value, labels = {}) {
|
|
95
95
|
this.record(ctx, value, labels, true);
|
|
@@ -124,10 +124,10 @@ class CounterBinding {
|
|
|
124
124
|
exports.CounterBinding = CounterBinding;
|
|
125
125
|
class Gauge extends Metric {
|
|
126
126
|
static register(name, option) {
|
|
127
|
-
return MetricState.INSTANCE.getOrRegisterMetric(
|
|
127
|
+
return MetricState.INSTANCE.getOrRegisterMetric(protos_1.MetricType.GAUGE, name, option);
|
|
128
128
|
}
|
|
129
129
|
constructor(name, option) {
|
|
130
|
-
super(
|
|
130
|
+
super(protos_1.MetricType.GAUGE, name, option);
|
|
131
131
|
}
|
|
132
132
|
record(ctx, value, labels = {}) {
|
|
133
133
|
ctx.res.gauges.push({
|
package/lib/core/meter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meter.js","sourceRoot":"","sources":["../../src/core/meter.ts"],"names":[],"mappings":";;;AACA,2CAAsD;AACtD,yCAA0D;AAC1D,
|
|
1
|
+
{"version":3,"file":"meter.js","sourceRoot":"","sources":["../../src/core/meter.ts"],"names":[],"mappings":";;;AACA,2CAAsD;AACtD,yCAA0D;AAC1D,2CAA6F;AAC7F,uCAA8C;AAE9C,SAAgB,aAAa,CAAC,IAAY;IACxC,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAAA;IAC1C,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;AAC/C,CAAC;AAHD,sCAGC;AAED,SAAgB,YAAY,CAAC,IAAY;IACvC,IAAI,IAAI,KAAK,QAAQ,EAAE;QACrB,OAAO,SAAS,CAAA;KACjB;IACD,OAAO,aAAa,CAAC,IAAI,CAAC,CAAA;AAC5B,CAAC;AALD,oCAKC;AAED,SAAgB,cAAc,CAAC,IAAY;IACzC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;AAC3B,CAAC;AAFD,wCAEC;AAED,SAAgB,eAAe,CAAC,MAAc;IAC5C,MAAM,UAAU,GAAW,EAAE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","sourcesContent":["import { BaseContext } from './base-context'\nimport { Numberish, toMetricValue } from './numberish'\nimport { Labels, NamedResultDescriptor } from './metadata'\nimport { AggregationConfig, AggregationType, MetricConfig, MetricType } from '@sentio/protos'\nimport { MapStateStorage } from '@sentio/base'\n\nexport function normalizeName(name: string): string {\n const regex = new RegExp('![_.a-zA-Z0-9]')\n return name.slice(0, 100).replace(regex, '_')\n}\n\nexport function normalizeKey(name: string): string {\n if (name === 'labels') {\n return 'labels_'\n }\n return normalizeName(name)\n}\n\nexport function normalizeValue(name: string): string {\n return name.slice(0, 100)\n}\n\nexport function normalizeLabels(labels: Labels): Labels {\n const normLabels: Labels = {}\n for (const key in labels) {\n normLabels[normalizeKey(key)] = normalizeValue(labels[key])\n }\n return normLabels\n}\n\nexport class MetricOptions {\n unit?: string\n description?: string\n sparse?: boolean\n aggregationConfig?: Partial<AggregationConfig>\n}\n\nexport class CounterOptions {\n unit?: string\n description?: string\n sparse?: boolean\n}\n\n// enum MetricType {\n// Counter = 0,\n// Gauge = 1,\n// }\n\nexport class Metric extends NamedResultDescriptor {\n config: MetricConfig\n constructor(type: MetricType, name: string, option?: MetricOptions) {\n super(name)\n this.config = MetricConfig.fromPartial({ name: this.name, type: type, ...option })\n const aggregationConfig = this.config.aggregationConfig\n if (aggregationConfig && aggregationConfig.intervalInMinutes.length) {\n if (aggregationConfig.intervalInMinutes.length > 1) {\n console.error('current only support one intervalInMinutes, only first interval will be used for', name)\n }\n if (aggregationConfig.intervalInMinutes[0] > 0 && aggregationConfig.types.length === 0) {\n aggregationConfig.types = [AggregationType.SUM, AggregationType.COUNT]\n }\n }\n }\n}\n\nexport class MetricState extends MapStateStorage<Metric> {\n static INSTANCE = new MetricState()\n\n getOrRegisterMetric(type: MetricType, name: string, option?: CounterOptions | MetricOptions): Metric {\n const metricMap = this.getOrRegister()\n let metric = metricMap.get(name)\n if (metric && metric.config.type !== type) {\n throw Error(`redefine ${name} of metric type ${type} that is previously ${metric.config.type}`)\n }\n\n if (!metric) {\n if (type === MetricType.COUNTER) {\n metric = new Counter(name, option)\n } else {\n metric = new Gauge(name, option)\n }\n }\n metricMap.set(name, metric)\n return metric\n }\n}\n\nexport class Counter extends Metric {\n static register(name: string, option?: CounterOptions): Counter {\n return MetricState.INSTANCE.getOrRegisterMetric(MetricType.COUNTER, name, option) as Counter\n }\n\n constructor(name: string, option?: MetricOptions) {\n super(MetricType.COUNTER, name, option)\n }\n\n add(ctx: BaseContext, value: Numberish, labels: Labels = {}) {\n this.record(ctx, value, labels, true)\n }\n\n sub(ctx: BaseContext, value: Numberish, labels: Labels = {}) {\n this.record(ctx, value, labels, false)\n }\n\n private record(ctx: BaseContext, value: Numberish, labels: Labels, add: boolean) {\n ctx.res.counters.push({\n metadata: ctx.getMetaData(this.name, labels),\n metricValue: toMetricValue(value),\n add: add,\n runtimeInfo: undefined,\n })\n }\n}\n\nexport class CounterBinding {\n private readonly ctx: BaseContext\n private readonly counter: Counter\n\n constructor(name: string, ctx: BaseContext) {\n this.counter = new Counter(name)\n this.ctx = ctx\n }\n\n add(value: Numberish, labels: Labels = {}) {\n this.counter.add(this.ctx, value, labels)\n }\n\n sub(value: Numberish, labels: Labels = {}) {\n this.counter.sub(this.ctx, value, labels)\n }\n}\n\nexport class Gauge extends Metric {\n static register(name: string, option?: MetricOptions): Gauge {\n return MetricState.INSTANCE.getOrRegisterMetric(MetricType.GAUGE, name, option) as Gauge\n }\n\n constructor(name: string, option?: MetricOptions) {\n super(MetricType.GAUGE, name, option)\n }\n\n record(ctx: BaseContext, value: Numberish, labels: Labels = {}) {\n ctx.res.gauges.push({\n metadata: ctx.getMetaData(this.config.name, labels),\n metricValue: toMetricValue(value),\n runtimeInfo: undefined,\n })\n }\n}\n\nexport class GaugeBinding {\n private readonly gauge: Gauge\n private readonly ctx: BaseContext\n\n constructor(name: string, ctx: BaseContext) {\n this.gauge = new Gauge(name)\n this.ctx = ctx\n }\n\n record(value: Numberish, labels: Labels = {}) {\n this.gauge.record(this.ctx, value, labels)\n }\n}\n\nexport class Meter {\n private readonly ctx: BaseContext\n\n constructor(ctx: BaseContext) {\n this.ctx = ctx\n }\n\n Counter(name: string): CounterBinding {\n return new CounterBinding(name, this.ctx)\n }\n\n Gauge(name: string): GaugeBinding {\n return new GaugeBinding(name, this.ctx)\n }\n}\n"]}
|
package/lib/core/numberish.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BigNumber } from 'ethers';
|
|
2
|
-
import { BigInteger, MetricValue } from '
|
|
2
|
+
import { BigInteger, MetricValue } from '@sentio/protos';
|
|
3
3
|
import { BigDecimal } from '.';
|
|
4
|
-
import
|
|
4
|
+
import { BlockTag } from '@ethersproject/providers';
|
|
5
5
|
export declare type Numberish = number | BigNumber | bigint | BigDecimal;
|
|
6
|
+
export declare function toBlockTag(a: number | bigint): BlockTag;
|
|
6
7
|
export declare function toMetricValue(value: Numberish): MetricValue;
|
|
7
8
|
export declare function toBigInteger(a: Numberish): BigInteger;
|
|
8
|
-
export declare function toBigInt(v: Long): bigint;
|
package/lib/core/numberish.js
CHANGED
|
@@ -1,20 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.toBigInteger = exports.toMetricValue = exports.toBlockTag = void 0;
|
|
4
4
|
const ethers_1 = require("ethers");
|
|
5
|
-
const
|
|
5
|
+
const protos_1 = require("@sentio/protos");
|
|
6
6
|
const _1 = require(".");
|
|
7
7
|
const anchor_1 = require("@project-serum/anchor");
|
|
8
|
+
function toBlockTag(a) {
|
|
9
|
+
if (typeof a === 'number') {
|
|
10
|
+
return a;
|
|
11
|
+
}
|
|
12
|
+
if (a > Number.MAX_SAFE_INTEGER) {
|
|
13
|
+
return '0x' + a.toString(16);
|
|
14
|
+
}
|
|
15
|
+
return Number(a);
|
|
16
|
+
}
|
|
17
|
+
exports.toBlockTag = toBlockTag;
|
|
8
18
|
function toMetricValue(value) {
|
|
9
19
|
if (value instanceof ethers_1.BigNumber) {
|
|
10
|
-
return
|
|
20
|
+
return protos_1.MetricValue.fromPartial({
|
|
11
21
|
bigInteger: toBigInteger(value.toBigInt()),
|
|
12
22
|
});
|
|
13
23
|
}
|
|
14
24
|
if (value instanceof _1.BigDecimal) {
|
|
15
25
|
// Carefully consider the use case here
|
|
16
26
|
if (value.isInteger()) {
|
|
17
|
-
return
|
|
27
|
+
return protos_1.MetricValue.fromPartial({
|
|
18
28
|
bigInteger: bigDecimalToBigInteger(value),
|
|
19
29
|
});
|
|
20
30
|
}
|
|
@@ -26,18 +36,18 @@ function toMetricValue(value) {
|
|
|
26
36
|
// NaN also not finite
|
|
27
37
|
throw new Error('Cannot record infinite value');
|
|
28
38
|
}
|
|
29
|
-
return
|
|
39
|
+
return protos_1.MetricValue.fromPartial({
|
|
30
40
|
bigDecimal: value.toString(), // e.g. -7.350918e-428
|
|
31
41
|
});
|
|
32
42
|
}
|
|
33
43
|
}
|
|
34
44
|
if (anchor_1.BN.isBN(value)) {
|
|
35
|
-
return
|
|
45
|
+
return protos_1.MetricValue.fromPartial({
|
|
36
46
|
bigInteger: bnToBigInteger(value),
|
|
37
47
|
});
|
|
38
48
|
}
|
|
39
49
|
if (typeof value === 'bigint' || Number.isInteger(value)) {
|
|
40
|
-
return
|
|
50
|
+
return protos_1.MetricValue.fromPartial({
|
|
41
51
|
bigInteger: toBigInteger(value),
|
|
42
52
|
});
|
|
43
53
|
}
|
|
@@ -49,7 +59,7 @@ function toMetricValue(value) {
|
|
|
49
59
|
throw new Error('Cannot record infinite value');
|
|
50
60
|
}
|
|
51
61
|
}
|
|
52
|
-
return
|
|
62
|
+
return protos_1.MetricValue.fromPartial({
|
|
53
63
|
doubleValue: Number(value),
|
|
54
64
|
});
|
|
55
65
|
}
|
|
@@ -108,8 +118,4 @@ function hexToBigInteger(hex, negative) {
|
|
|
108
118
|
data: new Uint8Array(buffer),
|
|
109
119
|
};
|
|
110
120
|
}
|
|
111
|
-
function toBigInt(v) {
|
|
112
|
-
return BigInt(v.toString());
|
|
113
|
-
}
|
|
114
|
-
exports.toBigInt = toBigInt;
|
|
115
121
|
//# sourceMappingURL=numberish.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"numberish.js","sourceRoot":"","sources":["../../src/core/numberish.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAClC,
|
|
1
|
+
{"version":3,"file":"numberish.js","sourceRoot":"","sources":["../../src/core/numberish.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAClC,2CAAwD;AACxD,wBAA8B;AAC9B,kDAA0C;AAK1C,SAAgB,UAAU,CAAC,CAAkB;IAC3C,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE;QACzB,OAAO,CAAC,CAAA;KACT;IACD,IAAI,CAAC,GAAG,MAAM,CAAC,gBAAgB,EAAE;QAC/B,OAAO,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;KAC7B;IACD,OAAO,MAAM,CAAC,CAAC,CAAC,CAAA;AAClB,CAAC;AARD,gCAQC;AAED,SAAgB,aAAa,CAAC,KAAgB;IAC5C,IAAI,KAAK,YAAY,kBAAS,EAAE;QAC9B,OAAO,oBAAW,CAAC,WAAW,CAAC;YAC7B,UAAU,EAAE,YAAY,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;SAC3C,CAAC,CAAA;KACH;IACD,IAAI,KAAK,YAAY,aAAU,EAAE;QAC/B,uCAAuC;QACvC,IAAI,KAAK,CAAC,SAAS,EAAE,EAAE;YACrB,OAAO,oBAAW,CAAC,WAAW,CAAC;gBAC7B,UAAU,EAAE,sBAAsB,CAAC,KAAK,CAAC;aAC1C,CAAC,CAAA;SACH;aAAM;YACL,IAAI,KAAK,CAAC,KAAK,EAAE,EAAE;gBACjB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;aAC3C;YACD,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE;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ACL,QAAQ,EAAE,QAAQ;QAClB,IAAI,EAAE,IAAI,UAAU,CAAC,MAAM,CAAC;KAC7B,CAAA;AACH,CAAC","sourcesContent":["import { BigNumber } from 'ethers'\nimport { BigInteger, MetricValue } from '@sentio/protos'\nimport { BigDecimal } from '.'\nimport { BN } from '@project-serum/anchor'\nimport { BlockTag } from '@ethersproject/providers'\n\nexport type Numberish = number | BigNumber | bigint | BigDecimal\n\nexport function toBlockTag(a: number | bigint): BlockTag {\n if (typeof a === 'number') {\n return a\n }\n if (a > Number.MAX_SAFE_INTEGER) {\n return '0x' + a.toString(16)\n }\n return Number(a)\n}\n\nexport function toMetricValue(value: Numberish): MetricValue {\n if (value instanceof BigNumber) {\n return MetricValue.fromPartial({\n bigInteger: toBigInteger(value.toBigInt()),\n })\n }\n if (value instanceof BigDecimal) {\n // Carefully consider the use case here\n if (value.isInteger()) {\n return MetricValue.fromPartial({\n bigInteger: bigDecimalToBigInteger(value),\n })\n } else {\n if (value.isNaN()) {\n throw new Error('Cannot record NaN value')\n }\n if (!value.isFinite()) {\n // NaN also not finite\n throw new Error('Cannot record infinite value')\n }\n return MetricValue.fromPartial({\n bigDecimal: value.toString(), // e.g. -7.350918e-428\n })\n }\n }\n if (BN.isBN(value)) {\n return MetricValue.fromPartial({\n bigInteger: bnToBigInteger(value),\n })\n }\n if (typeof value === 'bigint' || Number.isInteger(value)) {\n return MetricValue.fromPartial({\n bigInteger: toBigInteger(value),\n })\n }\n\n if (typeof value === 'number') {\n if (Number.isNaN(value)) {\n throw new Error('Cannot record NaN value')\n }\n if (!Number.isFinite(value)) {\n throw new Error('Cannot record infinite value')\n }\n }\n\n return MetricValue.fromPartial({\n doubleValue: Number(value),\n })\n}\n\nfunction bigDecimalToBigInteger(a: BigDecimal): BigInteger {\n const negative = a.isNegative()\n if (negative) {\n a = a.abs()\n }\n return hexToBigInteger(a.toString(16), negative)\n}\n\nfunction bnToBigInteger(a: BN): BigInteger {\n const negative = a.isNeg()\n if (negative) {\n a = a.abs()\n }\n return hexToBigInteger(a.toString(16), negative)\n}\n\nfunction intToBigInteger(a: bigint | number): BigInteger {\n const negative = a < 0\n if (negative) {\n a = -a\n }\n return hexToBigInteger(a.toString(16), negative)\n}\n\nexport function toBigInteger(a: Numberish): BigInteger {\n if (a instanceof BigDecimal) {\n return bigDecimalToBigInteger(a)\n }\n if (a instanceof BN) {\n return bnToBigInteger(a)\n }\n if (a instanceof BigNumber) {\n return intToBigInteger(a.toBigInt())\n }\n return intToBigInteger(a)\n\n // Following code is actually very slow\n // while (a > 0) {\n // const d = a & 0xffn\n // a >>= 8n\n // value.push(Number(d))\n // }\n //\n // return {\n // negative, value: new Uint8Array(value.reverse()),\n // }\n}\n\nfunction hexToBigInteger(hex: string, negative: boolean): BigInteger {\n if (hex.length % 2 === 1) {\n hex = '0' + hex\n }\n const buffer = Buffer.from(hex, 'hex')\n\n return {\n negative: negative,\n data: new Uint8Array(buffer),\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"numberish.test.js","sourceRoot":"","sources":["../../src/core/numberish.test.ts"],"names":[],"mappings":";;AAAA,+BAA6B;AAC7B,2CAAyD;AACzD,mCAAkC;AAClC,mCAAkC;AAClC,2CAAwC;AAExC,wBAA8B;AAE9B,oCAAoC;AACpC,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,MAAM,MAAM,GAAa,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,sCAAsC,EAAE,KAAK,EAAE,CAAC,SAAS,EAAE,IAAI,IAAI,IAAI,CAAC,CAAA;IAE3G,IAAI,CAAC,qCAAqC,EAAE,KAAK,IAAI,EAAE;QACrD,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE;YACtB,MAAM,CAAC,GAAG,IAAA,wBAAY,EAAC,CAAC,CAAC,CAAA;YACzB,MAAM,IAAI,GAAG,eAAe,CAAC,CAAC,CAAC,CAAA;YAC/B,MAAM,IAAI,GAAG,CAAC,CAAC,QA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Q,EAAE;QACd,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;KAChB;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,SAAS,kBAAkB,CAAC,CAAa;IACvC,IAAI,GAAG,GAAG,kBAAS,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAA;IAC3C,IAAI,CAAC,CAAC,QAAQ,EAAE;QACd,GAAG,GAAG,CAAC,GAAG,CAAA;KACX;IACD,OAAO,GAAG,CAAA;AACZ,CAAC","sourcesContent":["import { expect } from 'chai'\nimport { toBigInteger, toMetricValue } from './numberish'\nimport { webcrypto } from 'crypto'\nimport { BigNumber } from 'ethers'\nimport { performance } from 'perf_hooks'\nimport { BigInteger } from '
|
|
1
|
+
{"version":3,"file":"numberish.test.js","sourceRoot":"","sources":["../../src/core/numberish.test.ts"],"names":[],"mappings":";;AAAA,+BAA6B;AAC7B,2CAAyD;AACzD,mCAAkC;AAClC,mCAAkC;AAClC,2CAAwC;AAExC,wBAA8B;AAE9B,oCAAoC;AACpC,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,MAAM,MAAM,GAAa,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,sCAAsC,EAAE,KAAK,EAAE,CAAC,SAAS,EAAE,IAAI,IAAI,IAAI,CAAC,CAAA;IAE3G,IAAI,CAAC,qCAAqC,EAAE,KAAK,IAAI,EAAE;QACrD,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE;YACtB,MAAM,CAAC,GAAG,IAAA,wBAAY,EAAC,CAAC,CAAC,CAAA;YACzB,MAAM,IAAI,GAAG,eAAe,CAAC,CAAC,CAAC,CAAA;YAC/B,MAAM,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;YAC3B,IAAA,aAAM,EAAC,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;SAC1B;IACH,CAAC,CAAC,CAAA;IAEF,IAAI,C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,kBAAS,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAA;IAC3C,IAAI,CAAC,CAAC,QAAQ,EAAE;QACd,GAAG,GAAG,CAAC,GAAG,CAAA;KACX;IACD,OAAO,GAAG,CAAA;AACZ,CAAC","sourcesContent":["import { expect } from 'chai'\nimport { toBigInteger, toMetricValue } from './numberish'\nimport { webcrypto } from 'crypto'\nimport { BigNumber } from 'ethers'\nimport { performance } from 'perf_hooks'\nimport { BigInteger } from '@sentio/protos'\nimport { BigDecimal } from '.'\n\n// TODO add test for type conversion\ndescribe('Numberish tests', () => {\n const values: bigint[] = [0n, -0n, 3815372408723498172304781320847103784n, 2132n, -18708707n, 123n << 100n]\n\n test('big integer conversion correctness ', async () => {\n for (const v of values) {\n const b = toBigInteger(v)\n const hex1 = BigIntegerToHex(b)\n const hex2 = v.toString(16)\n expect(hex1).equals(hex2)\n }\n })\n\n test('random big integer conversion correctness ', async () => {\n for (let i = 0; i < 1000; i++) {\n const random = webcrypto.getRandomValues(new Uint8Array(256))\n const v = BigNumber.from(random).toBigInt()\n const b = toBigInteger(v)\n\n expect(BigNumber.from(b.data).eq(v)).to.equals(true)\n }\n })\n\n test.skip('random big integer performance', async () => {\n jest.setTimeout(100000)\n jest.retryTimes(3)\n\n let timer1 = 0\n let timer2 = 0\n for (let i = 0; i < 1000; i++) {\n // Use higher value for local debugging\n const random = webcrypto.getRandomValues(new Uint8Array(256))\n const v = BigNumber.from(random).toBigInt()\n\n let start = performance.now()\n toBigInteger(v)\n timer1 += performance.now() - start\n\n start = performance.now()\n v.toString(16)\n timer2 += performance.now() - start\n }\n\n console.log(timer1, timer2)\n expect(timer1).to.lessThan(timer2 * 3)\n })\n\n test('metric values', async () => {\n const longDec = '12.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002'\n expect(toMetricValue(new BigDecimal(longDec)).bigDecimal == longDec)\n\n const complexDec = '-7.350918e-428'\n expect(toMetricValue(new BigDecimal(complexDec)).bigDecimal == complexDec)\n\n expect(BigIntegerToBigInt(toMetricValue(new BigDecimal('100000')).bigInteger!) === 100000n)\n })\n})\n\n// Performance very bad\nfunction BigIntegerToHex(b: BigInteger): string {\n let res = BigNumber.from(b.data).toBigInt().toString(16)\n if (b.negative) {\n res = '-' + res\n }\n return res\n}\n\nfunction BigIntegerToBigInt(b: BigInteger): bigint {\n let res = BigNumber.from(b.data).toBigInt()\n if (b.negative) {\n res = -res\n }\n return res\n}\n"]}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { BaseContext } from './base-context';
|
|
2
|
-
import Long from 'long';
|
|
3
2
|
import { Labels } from './metadata';
|
|
4
3
|
import { RecordMetaData } from '@sentio/sdk';
|
|
5
4
|
export declare class SolanaContext extends BaseContext {
|
|
6
5
|
network: string;
|
|
7
6
|
address: string;
|
|
8
7
|
programName: string;
|
|
9
|
-
blockNumber:
|
|
10
|
-
constructor(programName: string, network: string, address: string, slot:
|
|
8
|
+
blockNumber: bigint;
|
|
9
|
+
constructor(programName: string, network: string, address: string, slot: bigint);
|
|
11
10
|
getMetaData(name: string, labels: Labels): RecordMetaData;
|
|
12
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solana-context.js","sourceRoot":"","sources":["../../src/core/solana-context.ts"],"names":[],"mappings":";;;AAAA,iDAA4C;
|
|
1
|
+
{"version":3,"file":"solana-context.js","sourceRoot":"","sources":["../../src/core/solana-context.ts"],"names":[],"mappings":";;;AAAA,iDAA4C;AAG5C,0CAA0C;AAC1C,mCAAyC;AAEzC,MAAa,aAAc,SAAQ,0BAAW;IAC5C,OAAO,CAAQ;IACf,OAAO,CAAQ;IACf,WAAW,CAAQ;IACnB,WAAW,CAAQ;IAEnB,YAAY,WAAmB,EAAE,OAAe,EAAE,OAAe,EAAE,IAAY;QAC7E,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,iBAAS,CAAC,cAAc,CAAA;QAClD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAA;IACzB,CAAC;IAED,WAAW,CAAC,IAAY,EAAE,MAAc;QACtC,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,YAAY,EAAE,IAAI,CAAC,WAAW;YAC9B,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,gBAAgB,EAAE,CAAC;YACnB,eAAe,EAAE,EAAE;YACnB,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,IAAA,uBAAe,EAAC,MAAM,CAAC;SAChC,CAAA;IACH,CAAC;CACF;AA3BD,sCA2BC","sourcesContent":["import { BaseContext } from './base-context'\nimport { Labels } from './metadata'\nimport { RecordMetaData } from '@sentio/sdk'\nimport { CHAIN_IDS } from '../utils/chain'\nimport { normalizeLabels } from './meter'\n\nexport class SolanaContext extends BaseContext {\n network: string\n address: string\n programName: string\n blockNumber: bigint\n\n constructor(programName: string, network: string, address: string, slot: bigint) {\n super()\n this.network = network || CHAIN_IDS.SOLANA_MAINNET\n this.programName = programName\n this.address = address\n this.blockNumber = slot\n }\n\n getMetaData(name: string, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: this.programName,\n blockNumber: this.blockNumber,\n transactionIndex: 0,\n transactionHash: '', // TODO add\n logIndex: 0,\n chainId: this.network,\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n}\n"]}
|