@subql/node-ethereum 3.1.1 → 3.1.2-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/CHANGELOG.md +5 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/ethereum/api.ethereum.js +2 -1
- package/dist/ethereum/api.ethereum.js.map +1 -1
- package/dist/ethereum/api.ethereum.test.js +3 -2
- package/dist/ethereum/api.ethereum.test.js.map +1 -1
- package/dist/ethereum/api.service.ethereum.test.js +2 -1
- package/dist/ethereum/api.service.ethereum.test.js.map +1 -1
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js +1 -6
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js.map +1 -1
- package/dist/indexer/fetch.service.spec.js +2 -1
- package/dist/indexer/fetch.service.spec.js.map +1 -1
- package/dist/indexer/project.service.test.js +2 -1
- package/dist/indexer/project.service.test.js.map +1 -1
- package/dist/indexer/worker/worker.d.ts +0 -5
- package/dist/indexer/worker/worker.js.map +1 -1
- package/dist/indexer/worker-fetch.module.js +1 -2
- package/dist/indexer/worker-fetch.module.js.map +1 -1
- package/dist/subcommands/testing.module.js +2 -0
- package/dist/subcommands/testing.module.js.map +1 -1
- package/dist/yargs.js +1 -1
- package/dist/yargs.js.map +1 -1
- package/package.json +7 -6
- package/dist/indexer/worker/worker.inMemoryCache.service.d.ts +0 -7
- package/dist/indexer/worker/worker.inMemoryCache.service.js +0 -34
- package/dist/indexer/worker/worker.inMemoryCache.service.js.map +0 -1
|
@@ -168,7 +168,8 @@ class EthereumApi {
|
|
|
168
168
|
return (await this.getFinalizedBlock()).number;
|
|
169
169
|
}
|
|
170
170
|
async getBestBlockHeight() {
|
|
171
|
-
|
|
171
|
+
// Cronos "safe" tag doesn't currently work as indended
|
|
172
|
+
const tag = this.supportsFinalization && this.chainId !== 25 ? 'safe' : 'latest';
|
|
172
173
|
return (await this.client.getBlock(tag)).number;
|
|
173
174
|
}
|
|
174
175
|
getR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E,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5C,OAAO,IAAI,KAAK,CAAC,6BAA6B,QAAQ,EAAE,CAAC,CAAC;SAC3D;QAED,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AAzWD,kCAyWC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport fs from 'fs';\nimport http from 'http';\nimport https from 'https';\nimport { Interface } from '@ethersproject/abi';\nimport {\n BlockTag,\n Provider,\n Block,\n TransactionReceipt,\n} from '@ethersproject/abstract-provider';\nimport { WebSocketProvider } from '@ethersproject/providers';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { getLogger, timeout } from '@subql/node-core';\nimport {\n ApiWrapper,\n EthereumBlock,\n EthereumTransaction,\n EthereumResult,\n EthereumLog,\n SubqlRuntimeDatasource,\n LightEthereumBlock,\n LightEthereumLog,\n} from '@subql/types-ethereum';\nimport CacheableLookup from 'cacheable-lookup';\nimport { hexDataSlice, hexValue } from 'ethers/lib/utils';\nimport { retryOnFailEth } from '../utils/project';\nimport { CeloJsonRpcBatchProvider } from './ethers/celo/celo-json-rpc-batch-provider';\nimport { CeloJsonRpcProvider } from './ethers/celo/celo-json-rpc-provider';\nimport { CeloWsProvider } from './ethers/celo/celo-ws-provider';\nimport { JsonRpcBatchProvider } from './ethers/json-rpc-batch-provider';\nimport { JsonRpcProvider } from './ethers/json-rpc-provider';\nimport { ConnectionInfo } from './ethers/web';\nimport SafeEthProvider from './safe-api';\nimport {\n formatBlock,\n formatLog,\n formatReceipt,\n formatTransaction,\n} from './utils.ethereum';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../../package.json');\n\nconst logger = getLogger('api.ethereum');\n\nasync function loadAssets(\n ds: SubqlRuntimeDatasource,\n): Promise<Record<string, string>> {\n if (!ds.assets) {\n return {};\n }\n const res: Record<string, string> = {};\n\n for (const [name, { file }] of Object.entries(ds.assets)) {\n try {\n res[name] = await fs.promises.readFile(file, { encoding: 'utf8' });\n } catch (e) {\n throw new Error(`Failed to load datasource asset ${file}`);\n }\n }\n\n return res;\n}\n\nfunction getHttpAgents() {\n // By default Nodejs doesn't cache DNS lookups\n // https://httptoolkit.com/blog/configuring-nodejs-dns/\n const lookup = new CacheableLookup();\n\n const options: http.AgentOptions = {\n keepAlive: true,\n /*, maxSockets: 100*/\n };\n\n const httpAgent = new http.Agent(options);\n const httpsAgent = new https.Agent(options);\n\n lookup.install(httpAgent);\n lookup.install(httpsAgent);\n\n return {\n http: httpAgent,\n https: httpsAgent,\n };\n}\n\nexport class EthereumApi implements ApiWrapper {\n private client: JsonRpcProvider;\n\n // This is used within the sandbox when HTTP is used\n private nonBatchClient?: JsonRpcProvider;\n private genesisBlock: Record<string, any>;\n private contractInterfaces: Record<string, Interface> = {};\n private chainId: number;\n private name: string;\n\n // Ethereum POS\n private supportsFinalization = true;\n\n /**\n * @param {string} endpoint - The endpoint of the RPC provider\n * @param {number} blockConfirmations - Used to determine how many blocks behind the head a block is considered finalized. Not used if the network has a concrete finalization mechanism.\n * @param {object} eventEmitter - Used to monitor the number of RPC requests\n */\n constructor(\n private endpoint: string,\n private blockConfirmations: number,\n private eventEmitter: EventEmitter2,\n ) {\n const { hostname, protocol, searchParams } = new URL(endpoint);\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(`Api host: ${hostname}, method: ${protocolStr}`);\n if (protocolStr === 'https' || protocolStr === 'http') {\n const connection: ConnectionInfo = {\n url: this.endpoint.split('?')[0],\n headers: {\n 'User-Agent': `Subquery-Node ${packageVersion}`,\n },\n allowGzip: true,\n throttleLimit: 5,\n throttleSlotInterval: 1,\n agents: getHttpAgents(),\n };\n searchParams.forEach((value, name, searchParams) => {\n (connection.headers as any)[name] = value;\n });\n this.client = new JsonRpcBatchProvider(connection);\n this.nonBatchClient = new JsonRpcProvider(connection);\n } else if (protocolStr === 'ws' || protocolStr === 'wss') {\n this.client = new WebSocketProvider(this.endpoint);\n } else {\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n }\n\n async init(): Promise<void> {\n this.injectClient();\n\n const network = await this.client.getNetwork();\n\n //celo\n if (network.chainId === 42220) {\n if (this.client instanceof WebSocketProvider) {\n this.client = new CeloWsProvider(this.client.connection.url);\n } else {\n this.client = new CeloJsonRpcBatchProvider(this.client.connection);\n this.nonBatchClient = new CeloJsonRpcProvider(this.client.connection);\n }\n }\n\n try {\n const [genesisBlock, supportsFinalization, supportsSafe] =\n await Promise.all([\n this.client.getBlock('earliest'),\n this.getSupportsTag('finalized'),\n this.getSupportsTag('safe'),\n ]);\n\n this.genesisBlock = genesisBlock;\n this.supportsFinalization = supportsFinalization && supportsSafe;\n this.chainId = network.chainId;\n this.name = network.name;\n } catch (e) {\n if ((e as Error).message.startsWith('Invalid response')) {\n this.client = this.nonBatchClient;\n\n logger.warn(\n `The RPC Node at ${this.endpoint} cannot process batch requests. ` +\n `Switching to non-batch mode for subsequent requests. Please consider checking if batch processing is supported on the RPC node.`,\n );\n\n return this.init();\n }\n\n throw e;\n }\n }\n\n private async getSupportsTag(tag: BlockTag): Promise<boolean> {\n try {\n // We set the timeout here because theres a bug in ethers where it will never resolve\n // It was happening with arbitrum on a syncing node\n const result = await timeout(this.client.getBlock(tag), 2);\n\n return true;\n } catch (e) {\n logger.info(`Chain doesnt support ${tag} tag`);\n return false;\n }\n }\n\n private injectClient(): void {\n const orig = this.client.send.bind(this.client);\n Object.defineProperty(this.client, 'send', {\n value: (...args) => {\n this.eventEmitter.emit('rpcCall');\n return orig(...args);\n },\n });\n }\n\n async getFinalizedBlock(): Promise<Block> {\n const height = this.supportsFinalization\n ? 'finalized'\n : (await this.getBestBlockHeight()) - this.blockConfirmations;\n\n const block = await this.client.getBlock(height);\n // The finalized block could sometimes fail to fetch,\n // due to some nodes on the network falling behind the synced node.\n if (!block) {\n throw new Error(`get finalized block \"${height}\" failed `);\n }\n return block;\n }\n\n async getFinalizedBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlock()).number;\n }\n\n async getBestBlockHeight(): Promise<number> {\n const tag = this.supportsFinalization ? 'safe' : 'latest';\n return (await this.client.getBlock(tag)).number;\n }\n\n getRuntimeChain(): string {\n return this.name;\n }\n\n getChainId(): number {\n return this.chainId;\n }\n\n getGenesisHash(): string {\n return this.genesisBlock.hash;\n }\n\n getSpecName(): string {\n return 'ethereum';\n }\n\n async getBlockByHeightOrHash(heightOrHash: number | string): Promise<Block> {\n if (typeof heightOrHash === 'number') {\n heightOrHash = hexValue(heightOrHash);\n }\n return this.client.getBlock(heightOrHash);\n }\n\n private async getBlockPromise(num: number, includeTx = true): Promise<any> {\n const rawBlock = await this.client.send('eth_getBlockByNumber', [\n hexValue(num),\n includeTx,\n ]);\n\n if (!rawBlock) {\n throw new Error(`Failed to fetch block ${num}`);\n }\n\n const block = formatBlock(rawBlock);\n\n block.stateRoot = this.client.formatter.hash(block.stateRoot);\n\n return block;\n }\n\n async getTransactionReceipt(\n transactionHash: string | Promise<string>,\n ): Promise<TransactionReceipt> {\n return retryOnFailEth<TransactionReceipt>(\n this.client.getTransactionReceipt.bind(this.client, transactionHash),\n );\n }\n\n async fetchBlock(blockNumber: number): Promise<EthereumBlock> {\n try {\n const block = await this.getBlockPromise(blockNumber, true);\n const logsRaw = await this.client.getLogs({ blockHash: block.hash });\n\n const logs = logsRaw.map((l) => formatLog(l, block));\n const transactions = block.transactions.map((tx) => ({\n ...formatTransaction(tx, block),\n receipt: () =>\n this.getTransactionReceipt(tx.hash).then((r) =>\n formatReceipt(r, block),\n ),\n logs: logs.filter((l) => l.transactionHash === tx.hash),\n }));\n\n const ret = {\n ...block,\n transactions,\n logs,\n };\n\n this.eventEmitter.emit('fetchBlock');\n return ret;\n } catch (e) {\n throw this.handleError(e);\n }\n }\n\n private async fetchLightBlock(\n blockNumber: number,\n ): Promise<LightEthereumBlock> {\n const block = await this.getBlockPromise(blockNumber, false);\n const logs = await this.client.getLogs({ blockHash: block.hash });\n\n return {\n ...block,\n logs: logs.map((l) => formatLog(l, block)),\n };\n }\n\n async fetchBlocks(bufferBlocks: number[]): Promise<EthereumBlock[]> {\n return Promise.all(bufferBlocks.map(async (num) => this.fetchBlock(num)));\n }\n\n async fetchBlocksLight(\n bufferBlocks: number[],\n ): Promise<LightEthereumBlock[]> {\n console.log('FETCH BLOCKS LIGHT');\n return Promise.all(\n bufferBlocks.map(async (num) => this.fetchLightBlock(num)),\n );\n }\n\n get api(): Provider {\n return this.client;\n }\n\n getSafeApi(blockHeight: number): SafeEthProvider {\n // We cannot use a batch http client because OnF don't support routing historical queries in batches to an archive nodes\n const client =\n this.client instanceof WebSocketProvider\n ? this.client\n : this.nonBatchClient;\n\n return new SafeEthProvider(client, blockHeight);\n }\n\n private buildInterface(\n abiName: string,\n assets: Record<string, string>,\n ): Interface | undefined {\n if (!assets[abiName]) {\n throw new Error(`ABI named \"${abiName}\" not referenced in assets`);\n }\n\n // This assumes that all datasources have a different abi name or they are the same abi\n if (!this.contractInterfaces[abiName]) {\n // Constructing the interface validates the ABI\n try {\n let abiObj = JSON.parse(assets[abiName]);\n\n /*\n * Allows parsing JSON artifacts as well as ABIs\n * https://trufflesuite.github.io/artifact-updates/background.html#what-are-artifacts\n */\n if (!Array.isArray(abiObj) && abiObj.abi) {\n abiObj = abiObj.abi;\n }\n\n this.contractInterfaces[abiName] = new Interface(abiObj);\n } catch (e) {\n logger.error(`Unable to parse ABI: ${e.message}`);\n throw new Error('ABI is invalid');\n }\n }\n\n return this.contractInterfaces[abiName];\n }\n\n async parseLog<T extends EthereumResult = EthereumResult>(\n log: EthereumLog | LightEthereumLog,\n ds: SubqlRuntimeDatasource,\n ): Promise<\n EthereumLog | LightEthereumLog | EthereumLog<T> | LightEthereumLog<T>\n > {\n try {\n if (!ds?.options?.abi) {\n logger.warn('No ABI provided for datasource');\n return log;\n }\n const iface = this.buildInterface(ds.options.abi, await loadAssets(ds));\n return {\n ...log,\n args: iface?.parseLog(log).args as T,\n };\n } catch (e) {\n logger.warn(`Failed to parse log data: ${e.message}`);\n return log;\n }\n }\n\n async parseTransaction<T extends EthereumResult = EthereumResult>(\n transaction: EthereumTransaction,\n ds: SubqlRuntimeDatasource,\n ): Promise<EthereumTransaction<T> | EthereumTransaction> {\n try {\n if (!ds?.options?.abi) {\n logger.warn('No ABI provided for datasource');\n return transaction;\n }\n const assets = await loadAssets(ds);\n const iface = this.buildInterface(ds.options.abi, assets);\n const func = iface.getFunction(hexDataSlice(transaction.input, 0, 4));\n const args = iface.decodeFunctionData(func, transaction.input) as T;\n\n transaction.logs =\n transaction.logs &&\n ((await Promise.all(\n transaction.logs.map(async (log) => this.parseLog(log, ds)),\n )) as Array<EthereumLog | EthereumLog<T>>);\n\n return {\n ...transaction,\n args,\n };\n } catch (e) {\n logger.warn(`Failed to parse transaction data: ${e.message}`);\n return transaction;\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async connect(): Promise<void> {\n logger.error('Ethereum API connect is not implemented');\n throw new Error('Not implemented');\n }\n\n async disconnect(): Promise<void> {\n if (this.client instanceof WebSocketProvider) {\n await this.client.destroy();\n } else {\n logger.warn('Disconnect called on HTTP provider');\n }\n }\n\n handleError(e: Error): Error {\n if ((e as any)?.status === 429) {\n const { hostname } = new URL(this.endpoint);\n return new Error(`Rate Limited at endpoint: ${hostname}`);\n }\n\n return e;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"api.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/api.ethereum.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAEnC,4CAAoB;AACpB,gDAAwB;AACxB,kDAA0B;AAC1B,4CAA+C;AAO/C,wDAA6D;AAE7D,gDAAsD;AAWtD,wEAA+C;AAC/C,4CAA0D;AAC1D,8CAAkD;AAClD,6FAAsF;AACtF,iFAA2E;AAC3E,qEAAgE;AAChE,8EAAwE;AACxE,kEAA6D;AAE7D,0DAAyC;AACzC,q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AI;gBACd,WAAW,CAAC,IAAI;oBACf,CAAC,MAAM,OAAO,CAAC,GAAG,CACjB,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAC5D,CAAyC,CAAC;YAE7C,uCACK,WAAW,KACd,IAAI,IACJ;SACH;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YAC9D,OAAO,WAAW,CAAC;SACpB;IACH,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,OAAO;QACX,MAAM,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;QACxD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,UAAU;QACd,IAAI,IAAI,CAAC,MAAM,YAAY,6BAAiB,EAAE;YAC5C,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;SAC7B;aAAM;YACL,MAAM,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;SACnD;IACH,CAAC;IAED,WAAW,CAAC,CAAQ;QAClB,IAAI,CAAC,CAAS,aAAT,CAAC,uBAAD,CAAC,CAAU,MAAM,MAAK,GAAG,EAAE;YAC9B,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5C,OAAO,IAAI,KAAK,CAAC,6BAA6B,QAAQ,EAAE,CAAC,CAAC;SAC3D;QAED,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AA3WD,kCA2WC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport fs from 'fs';\nimport http from 'http';\nimport https from 'https';\nimport { Interface } from '@ethersproject/abi';\nimport {\n BlockTag,\n Provider,\n Block,\n TransactionReceipt,\n} from '@ethersproject/abstract-provider';\nimport { WebSocketProvider } from '@ethersproject/providers';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { getLogger, timeout } from '@subql/node-core';\nimport {\n ApiWrapper,\n EthereumBlock,\n EthereumTransaction,\n EthereumResult,\n EthereumLog,\n SubqlRuntimeDatasource,\n LightEthereumBlock,\n LightEthereumLog,\n} from '@subql/types-ethereum';\nimport CacheableLookup from 'cacheable-lookup';\nimport { hexDataSlice, hexValue } from 'ethers/lib/utils';\nimport { retryOnFailEth } from '../utils/project';\nimport { CeloJsonRpcBatchProvider } from './ethers/celo/celo-json-rpc-batch-provider';\nimport { CeloJsonRpcProvider } from './ethers/celo/celo-json-rpc-provider';\nimport { CeloWsProvider } from './ethers/celo/celo-ws-provider';\nimport { JsonRpcBatchProvider } from './ethers/json-rpc-batch-provider';\nimport { JsonRpcProvider } from './ethers/json-rpc-provider';\nimport { ConnectionInfo } from './ethers/web';\nimport SafeEthProvider from './safe-api';\nimport {\n formatBlock,\n formatLog,\n formatReceipt,\n formatTransaction,\n} from './utils.ethereum';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../../package.json');\n\nconst logger = getLogger('api.ethereum');\n\nasync function loadAssets(\n ds: SubqlRuntimeDatasource,\n): Promise<Record<string, string>> {\n if (!ds.assets) {\n return {};\n }\n const res: Record<string, string> = {};\n\n for (const [name, { file }] of Object.entries(ds.assets)) {\n try {\n res[name] = await fs.promises.readFile(file, { encoding: 'utf8' });\n } catch (e) {\n throw new Error(`Failed to load datasource asset ${file}`);\n }\n }\n\n return res;\n}\n\nfunction getHttpAgents() {\n // By default Nodejs doesn't cache DNS lookups\n // https://httptoolkit.com/blog/configuring-nodejs-dns/\n const lookup = new CacheableLookup();\n\n const options: http.AgentOptions = {\n keepAlive: true,\n /*, maxSockets: 100*/\n };\n\n const httpAgent = new http.Agent(options);\n const httpsAgent = new https.Agent(options);\n\n lookup.install(httpAgent);\n lookup.install(httpsAgent);\n\n return {\n http: httpAgent,\n https: httpsAgent,\n };\n}\n\nexport class EthereumApi implements ApiWrapper {\n private client: JsonRpcProvider;\n\n // This is used within the sandbox when HTTP is used\n private nonBatchClient?: JsonRpcProvider;\n private genesisBlock: Record<string, any>;\n private contractInterfaces: Record<string, Interface> = {};\n private chainId: number;\n private name: string;\n\n // Ethereum POS\n private supportsFinalization = true;\n\n /**\n * @param {string} endpoint - The endpoint of the RPC provider\n * @param {number} blockConfirmations - Used to determine how many blocks behind the head a block is considered finalized. Not used if the network has a concrete finalization mechanism.\n * @param {object} eventEmitter - Used to monitor the number of RPC requests\n */\n constructor(\n private endpoint: string,\n private blockConfirmations: number,\n private eventEmitter: EventEmitter2,\n ) {\n const { hostname, protocol, searchParams } = new URL(endpoint);\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(`Api host: ${hostname}, method: ${protocolStr}`);\n if (protocolStr === 'https' || protocolStr === 'http') {\n const connection: ConnectionInfo = {\n url: this.endpoint.split('?')[0],\n headers: {\n 'User-Agent': `Subquery-Node ${packageVersion}`,\n },\n allowGzip: true,\n throttleLimit: 5,\n throttleSlotInterval: 1,\n agents: getHttpAgents(),\n };\n searchParams.forEach((value, name, searchParams) => {\n (connection.headers as any)[name] = value;\n });\n this.client = new JsonRpcBatchProvider(connection);\n this.nonBatchClient = new JsonRpcProvider(connection);\n } else if (protocolStr === 'ws' || protocolStr === 'wss') {\n this.client = new WebSocketProvider(this.endpoint);\n } else {\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n }\n\n async init(): Promise<void> {\n this.injectClient();\n\n const network = await this.client.getNetwork();\n\n //celo\n if (network.chainId === 42220) {\n if (this.client instanceof WebSocketProvider) {\n this.client = new CeloWsProvider(this.client.connection.url);\n } else {\n this.client = new CeloJsonRpcBatchProvider(this.client.connection);\n this.nonBatchClient = new CeloJsonRpcProvider(this.client.connection);\n }\n }\n\n try {\n const [genesisBlock, supportsFinalization, supportsSafe] =\n await Promise.all([\n this.client.getBlock('earliest'),\n this.getSupportsTag('finalized'),\n this.getSupportsTag('safe'),\n ]);\n\n this.genesisBlock = genesisBlock;\n this.supportsFinalization = supportsFinalization && supportsSafe;\n this.chainId = network.chainId;\n this.name = network.name;\n } catch (e) {\n if ((e as Error).message.startsWith('Invalid response')) {\n this.client = this.nonBatchClient;\n\n logger.warn(\n `The RPC Node at ${this.endpoint} cannot process batch requests. ` +\n `Switching to non-batch mode for subsequent requests. Please consider checking if batch processing is supported on the RPC node.`,\n );\n\n return this.init();\n }\n\n throw e;\n }\n }\n\n private async getSupportsTag(tag: BlockTag): Promise<boolean> {\n try {\n // We set the timeout here because theres a bug in ethers where it will never resolve\n // It was happening with arbitrum on a syncing node\n const result = await timeout(this.client.getBlock(tag), 2);\n\n return true;\n } catch (e) {\n logger.info(`Chain doesnt support ${tag} tag`);\n return false;\n }\n }\n\n private injectClient(): void {\n const orig = this.client.send.bind(this.client);\n Object.defineProperty(this.client, 'send', {\n value: (...args) => {\n this.eventEmitter.emit('rpcCall');\n return orig(...args);\n },\n });\n }\n\n async getFinalizedBlock(): Promise<Block> {\n const height = this.supportsFinalization\n ? 'finalized'\n : (await this.getBestBlockHeight()) - this.blockConfirmations;\n\n const block = await this.client.getBlock(height);\n // The finalized block could sometimes fail to fetch,\n // due to some nodes on the network falling behind the synced node.\n if (!block) {\n throw new Error(`get finalized block \"${height}\" failed `);\n }\n return block;\n }\n\n async getFinalizedBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlock()).number;\n }\n\n async getBestBlockHeight(): Promise<number> {\n // Cronos \"safe\" tag doesn't currently work as indended\n const tag =\n this.supportsFinalization && this.chainId !== 25 ? 'safe' : 'latest';\n return (await this.client.getBlock(tag)).number;\n }\n\n getRuntimeChain(): string {\n return this.name;\n }\n\n getChainId(): number {\n return this.chainId;\n }\n\n getGenesisHash(): string {\n return this.genesisBlock.hash;\n }\n\n getSpecName(): string {\n return 'ethereum';\n }\n\n async getBlockByHeightOrHash(heightOrHash: number | string): Promise<Block> {\n if (typeof heightOrHash === 'number') {\n heightOrHash = hexValue(heightOrHash);\n }\n return this.client.getBlock(heightOrHash);\n }\n\n private async getBlockPromise(num: number, includeTx = true): Promise<any> {\n const rawBlock = await this.client.send('eth_getBlockByNumber', [\n hexValue(num),\n includeTx,\n ]);\n\n if (!rawBlock) {\n throw new Error(`Failed to fetch block ${num}`);\n }\n\n const block = formatBlock(rawBlock);\n\n block.stateRoot = this.client.formatter.hash(block.stateRoot);\n\n return block;\n }\n\n async getTransactionReceipt(\n transactionHash: string | Promise<string>,\n ): Promise<TransactionReceipt> {\n return retryOnFailEth<TransactionReceipt>(\n this.client.getTransactionReceipt.bind(this.client, transactionHash),\n );\n }\n\n async fetchBlock(blockNumber: number): Promise<EthereumBlock> {\n try {\n const block = await this.getBlockPromise(blockNumber, true);\n const logsRaw = await this.client.getLogs({ blockHash: block.hash });\n\n const logs = logsRaw.map((l) => formatLog(l, block));\n const transactions = block.transactions.map((tx) => ({\n ...formatTransaction(tx, block),\n receipt: () =>\n this.getTransactionReceipt(tx.hash).then((r) =>\n formatReceipt(r, block),\n ),\n logs: logs.filter((l) => l.transactionHash === tx.hash),\n }));\n\n const ret = {\n ...block,\n transactions,\n logs,\n };\n\n this.eventEmitter.emit('fetchBlock');\n return ret;\n } catch (e) {\n throw this.handleError(e);\n }\n }\n\n private async fetchLightBlock(\n blockNumber: number,\n ): Promise<LightEthereumBlock> {\n const block = await this.getBlockPromise(blockNumber, false);\n const logs = await this.client.getLogs({ blockHash: block.hash });\n\n return {\n ...block,\n logs: logs.map((l) => formatLog(l, block)),\n };\n }\n\n async fetchBlocks(bufferBlocks: number[]): Promise<EthereumBlock[]> {\n return Promise.all(bufferBlocks.map(async (num) => this.fetchBlock(num)));\n }\n\n async fetchBlocksLight(\n bufferBlocks: number[],\n ): Promise<LightEthereumBlock[]> {\n console.log('FETCH BLOCKS LIGHT');\n return Promise.all(\n bufferBlocks.map(async (num) => this.fetchLightBlock(num)),\n );\n }\n\n get api(): Provider {\n return this.client;\n }\n\n getSafeApi(blockHeight: number): SafeEthProvider {\n // We cannot use a batch http client because OnF don't support routing historical queries in batches to an archive nodes\n const client =\n this.client instanceof WebSocketProvider\n ? this.client\n : this.nonBatchClient;\n\n return new SafeEthProvider(client, blockHeight);\n }\n\n private buildInterface(\n abiName: string,\n assets: Record<string, string>,\n ): Interface | undefined {\n if (!assets[abiName]) {\n throw new Error(`ABI named \"${abiName}\" not referenced in assets`);\n }\n\n // This assumes that all datasources have a different abi name or they are the same abi\n if (!this.contractInterfaces[abiName]) {\n // Constructing the interface validates the ABI\n try {\n let abiObj = JSON.parse(assets[abiName]);\n\n /*\n * Allows parsing JSON artifacts as well as ABIs\n * https://trufflesuite.github.io/artifact-updates/background.html#what-are-artifacts\n */\n if (!Array.isArray(abiObj) && abiObj.abi) {\n abiObj = abiObj.abi;\n }\n\n this.contractInterfaces[abiName] = new Interface(abiObj);\n } catch (e) {\n logger.error(`Unable to parse ABI: ${e.message}`);\n throw new Error('ABI is invalid');\n }\n }\n\n return this.contractInterfaces[abiName];\n }\n\n async parseLog<T extends EthereumResult = EthereumResult>(\n log: EthereumLog | LightEthereumLog,\n ds: SubqlRuntimeDatasource,\n ): Promise<\n EthereumLog | LightEthereumLog | EthereumLog<T> | LightEthereumLog<T>\n > {\n try {\n if (!ds?.options?.abi) {\n logger.warn('No ABI provided for datasource');\n return log;\n }\n const iface = this.buildInterface(ds.options.abi, await loadAssets(ds));\n return {\n ...log,\n args: iface?.parseLog(log).args as T,\n };\n } catch (e) {\n logger.warn(`Failed to parse log data: ${e.message}`);\n return log;\n }\n }\n\n async parseTransaction<T extends EthereumResult = EthereumResult>(\n transaction: EthereumTransaction,\n ds: SubqlRuntimeDatasource,\n ): Promise<EthereumTransaction<T> | EthereumTransaction> {\n try {\n if (!ds?.options?.abi) {\n logger.warn('No ABI provided for datasource');\n return transaction;\n }\n const assets = await loadAssets(ds);\n const iface = this.buildInterface(ds.options.abi, assets);\n const func = iface.getFunction(hexDataSlice(transaction.input, 0, 4));\n const args = iface.decodeFunctionData(func, transaction.input) as T;\n\n transaction.logs =\n transaction.logs &&\n ((await Promise.all(\n transaction.logs.map(async (log) => this.parseLog(log, ds)),\n )) as Array<EthereumLog | EthereumLog<T>>);\n\n return {\n ...transaction,\n args,\n };\n } catch (e) {\n logger.warn(`Failed to parse transaction data: ${e.message}`);\n return transaction;\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async connect(): Promise<void> {\n logger.error('Ethereum API connect is not implemented');\n throw new Error('Not implemented');\n }\n\n async disconnect(): Promise<void> {\n if (this.client instanceof WebSocketProvider) {\n await this.client.destroy();\n } else {\n logger.warn('Disconnect called on HTTP provider');\n }\n }\n\n handleError(e: Error): Error {\n if ((e as any)?.status === 429) {\n const { hostname } = new URL(this.endpoint);\n return new Error(`Rate Limited at endpoint: ${hostname}`);\n }\n\n return e;\n }\n}\n"]}
|
|
@@ -11,7 +11,8 @@ const types_ethereum_1 = require("@subql/types-ethereum");
|
|
|
11
11
|
const api_ethereum_1 = require("./api.ethereum");
|
|
12
12
|
const block_ethereum_1 = require("./block.ethereum");
|
|
13
13
|
// Add api key to work
|
|
14
|
-
const HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';
|
|
14
|
+
// const HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';
|
|
15
|
+
const HTTP_ENDPOINT = 'https://eth.llamarpc.com';
|
|
15
16
|
const BLOCK_CONFIRMATIONS = 20;
|
|
16
17
|
const ds = {
|
|
17
18
|
mapping: {
|
|
@@ -168,7 +169,7 @@ describe('Api.ethereum', () => {
|
|
|
168
169
|
await ethApi.init();
|
|
169
170
|
expect(ethApi.supportsFinalized).toBeFalsy();
|
|
170
171
|
// Polygon
|
|
171
|
-
ethApi = new api_ethereum_1.EthereumApi('https://polygon.
|
|
172
|
+
ethApi = new api_ethereum_1.EthereumApi('https://polygon.llamarpc.com', BLOCK_CONFIRMATIONS, eventEmitter);
|
|
172
173
|
await ethApi.init();
|
|
173
174
|
expect(ethApi.supportsFinalized).toBeFalsy();
|
|
174
175
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.ethereum.test.js","sourceRoot":"","sources":["../../src/ethereum/api.ethereum.test.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;AAEnC,gDAAwB;AACxB,yDAAsD;AACtD,0DAM+B;AAC/B,iDAA6C;AAC7C,qDAG0B;AAE1B,sBAAsB;AACtB,MAAM,aAAa,GAAG,sCAAsC,CAAC;AAC7D,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B,MAAM,EAAE,GAA2B;IACjC,OAAO,EAAE;QACP,IAAI,EAAE,EAAE;QACR,QAAQ,EAAE;YACR;gBACE,OAAO,EAAE,MAAM;gBACf,IAAI,EAAE,oCAAmB,CAAC,IAAI;gBAC9B,MAAM,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE;aACnC;SACF;KACF;IACD,IAAI,EAAE,uCAAsB,CAAC,OAAO;IACpC,UAAU,EAAE,QAAQ;IACpB,OAAO,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE;IAC1B,MAAM,EAAE;QACN,MAAM,EAAE,EAAE,IAAI,EAAE,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,wBAAwB,CAAC,EAAE;KACrB;CAC9C,CAAC;AAEF,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AACvB,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,IAAI,MAAmB,CAAC;IACxB,MAAM,YAAY,GAAG,IAAI,6BAAa,EAAE,CAAC;IACzC,IAAI,SAAwB,CAAC;IAE7B,MAAM,UAAU,GAAG,KAAK,EAAE,MAAc,EAAE,EAAE;QAC1C,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAE9C,OAAO,KAAsB,CAAC;IAChC,CAAC,CAAC;IAEF,UAAU,CAA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CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4CAA4C,EAAE,KAAK,IAAI,EAAE;QAC1D,WAAW;QACX,MAAM,CAAE,MAAc,CAAC,oBAAoB,CAAC,CAAC,UAAU,EAAE,CAAC;QAE1D,WAAW;QACX,MAAM,GAAG,IAAI,0BAAW,CACtB,kCAAkC,EAClC,mBAAmB,EACnB,YAAY,CACb,CAAC;QACF,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAEpB,MAAM,CAAE,MAAc,CAAC,oBAAoB,CAAC,CAAC,UAAU,EAAE,CAAC;QAE1D,MAAM;QACN,MAAM,GAAG,IAAI,0BAAW,CACtB,kCAAkC,EAClC,mBAAmB,EACnB,YAAY,CACb,CAAC;QACF,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAEpB,MAAM,CAAE,MAAc,CAAC,iBAAiB,CAAC,CAAC,SAAS,EAAE,CAAC;QAEtD,UAAU;QACV,MAAM,GAAG,IAAI,0BAAW,CACtB,0CAA0C,EAC1C,mBAAmB,EACnB,YAAY,CACb,CAAC;QACF,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAEpB,MAAM,CAAE,MAAc,CAAC,iBAAiB,CAAC,CAAC,SAAS,EAAE,CAAC;IACxD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport path from 'path';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n EthereumBlock,\n EthereumDatasourceKind,\n EthereumHandlerKind,\n EthereumLogFilter,\n SubqlRuntimeDatasource,\n} from '@subql/types-ethereum';\nimport { EthereumApi } from './api.ethereum';\nimport {\n filterLogsProcessor,\n filterTransactionsProcessor,\n} from './block.ethereum';\n\n// Add api key to work\nconst HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';\nconst BLOCK_CONFIRMATIONS = 20;\n\nconst ds: SubqlRuntimeDatasource = {\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'test',\n kind: EthereumHandlerKind.Call,\n filter: { function: '0x23b872dd' },\n },\n ],\n },\n kind: EthereumDatasourceKind.Runtime,\n startBlock: 16258633,\n options: { abi: 'erc721' },\n assets: {\n erc721: { file: path.join(__dirname, '../../test/erc721.json') },\n } as unknown as Map<string, { file: string }>,\n};\n\njest.setTimeout(90000);\ndescribe('Api.ethereum', () => {\n let ethApi: EthereumApi;\n const eventEmitter = new EventEmitter2();\n let blockData: EthereumBlock;\n\n const fetchBlock = async (height: number) => {\n const block = await ethApi.fetchBlock(height);\n\n return block as EthereumBlock;\n };\n\n beforeEach(async () => {\n ethApi = new EthereumApi(HTTP_ENDPOINT, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(16258633);\n });\n\n it('Should format transaction in logs, and the transaction gas should be bigInt type', () => {\n expect(typeof blockData.logs[0].transaction.gas).toBe('bigint');\n expect(typeof blockData.logs[0].transaction.blockNumber).toBe('number');\n expect(typeof blockData.logs[0].transaction.gasPrice).toBe('bigint');\n expect(typeof blockData.logs[0].transaction.maxPriorityFeePerGas).toBe(\n 'bigint',\n );\n expect(typeof blockData.logs[0].transaction.transactionIndex).toBe(\n 'bigint',\n );\n });\n\n it('Decode nested logs in transactions', async () => {\n // Erc721\n const tx = blockData.transactions.find(\n (e) =>\n e.hash ===\n '0x8e419d0e36d7f9c099a001fded516bd168edd9d27b4aec2bcd56ba3b3b955ccc',\n );\n const parsedTx = await ethApi.parseTransaction(tx, ds);\n expect(parsedTx.logs[0].args).toBeTruthy();\n });\n\n it('Should return raw logs, if decode fails', async () => {\n // not Erc721\n const tx = blockData.transactions.find(\n (e) =>\n e.hash ===\n '0xed62f7a7720fe6ae05dec45ad9dd4f53034a0aae2c140d229b1151504ee9a6c9',\n );\n const parsedLog = await ethApi.parseLog(tx.logs[0], ds);\n expect(parsedLog).not.toHaveProperty('args');\n expect(parsedLog).toBeTruthy();\n });\n it('Null filter support', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(2847447);\n const result = blockData.transactions.filter((tx) => {\n if (\n filterTransactionsProcessor(\n tx,\n { to: null },\n '0x72a33394f0652e2bf15d7901f3cd46863d968424',\n )\n ) {\n return tx.hash;\n }\n });\n expect(result[0].hash).toBe(\n '0x24bef923522a4d6a79f9ab9242a74fb987dce94002c0f107c2a7d0b7e24bcf05',\n );\n expect(result.length).toBe(1);\n });\n\n it('!null filter support for logs, expect to filter out', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n const filter_1: EthereumLogFilter = {\n topics: [\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n undefined,\n undefined,\n '!null',\n ],\n };\n\n const filter_2: EthereumLogFilter = {\n topics: [\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n ],\n };\n\n blockData = await fetchBlock(4015990);\n const transaction = blockData.transactions.find(\n (tx) =>\n tx.hash ===\n '0xeb2e443f2d4e784193fa13bbbae2b85e6ee459e7b7b53f8ca098ffae9b25b059',\n );\n\n const erc20Transfers = transaction.logs.filter((log) =>\n filterLogsProcessor(log, filter_2),\n );\n const erc721Transfers = transaction.logs.filter((log) =>\n filterLogsProcessor(log, filter_1),\n );\n\n expect(erc20Transfers.length).toBe(7);\n expect(erc721Transfers.length).toBe(2);\n });\n\n it('Null filter support, for undefined transaction.to', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(2847447);\n blockData.transactions[1].to = undefined;\n const result = blockData.transactions.filter((tx) => {\n if (\n filterTransactionsProcessor(\n tx,\n { to: null },\n '0x72a33394f0652e2bf15d7901f3cd46863d968424',\n )\n ) {\n return tx.hash;\n }\n });\n expect(result[0].hash).toBe(\n '0x24bef923522a4d6a79f9ab9242a74fb987dce94002c0f107c2a7d0b7e24bcf05',\n );\n expect(result.length).toBe(1);\n });\n\n it('Should return all tx if filter.to is not defined', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(2847447);\n const result = blockData.transactions.filter((tx) => {\n if (\n filterTransactionsProcessor(\n tx,\n undefined,\n '0x72a33394f0652e2bf15d7901f3cd46863d968424',\n )\n ) {\n return tx.hash;\n }\n });\n expect(result.length).toBe(2);\n });\n\n it('filter.to Should support only null not undefined', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(2847447);\n const result = blockData.transactions.filter((tx) => {\n if (\n filterTransactionsProcessor(\n tx,\n { to: undefined },\n '0x72a33394f0652e2bf15d7901f3cd46863d968424',\n )\n ) {\n return tx.hash;\n }\n });\n expect(result.length).toBe(0);\n });\n it('If transaction is undefined, with null filter, should be supported', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(2847447);\n const result = blockData.transactions.filter((tx) => {\n tx.to = undefined;\n if (\n filterTransactionsProcessor(\n tx,\n { to: null },\n '0x72a33394f0652e2bf15d7901f3cd46863d968424',\n )\n ) {\n return tx.hash;\n }\n });\n expect(result.length).toBe(2);\n });\n\n it('Resolves the correct tags for finalization', async () => {\n // Ethereum\n expect((ethApi as any).supportsFinalization).toBeTruthy();\n\n // Moonbeam\n ethApi = new EthereumApi(\n 'https://rpc.api.moonbeam.network',\n BLOCK_CONFIRMATIONS,\n eventEmitter,\n );\n await ethApi.init();\n\n expect((ethApi as any).supportsFinalization).toBeTruthy();\n\n // BSC\n ethApi = new EthereumApi(\n 'https://bsc-dataseed.binance.org',\n BLOCK_CONFIRMATIONS,\n eventEmitter,\n );\n await ethApi.init();\n\n expect((ethApi as any).supportsFinalized).toBeFalsy();\n\n // Polygon\n ethApi = new EthereumApi(\n 'https://polygon.api.onfinality.io/public',\n BLOCK_CONFIRMATIONS,\n eventEmitter,\n );\n await ethApi.init();\n\n expect((ethApi as any).supportsFinalized).toBeFalsy();\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"api.ethereum.test.js","sourceRoot":"","sources":["../../src/ethereum/api.ethereum.test.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;AAEnC,gDAAwB;AACxB,yDAAsD;AACtD,0DAM+B;AAC/B,iDAA6C;AAC7C,qDAG0B;AAE1B,sBAAsB;AACtB,gEAAgE;AAChE,MAAM,aAAa,GAAG,0BAA0B,CAAC;AACjD,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B,MAAM,EAAE,GAA2B;IACjC,OAAO,EAAE;QACP,IAAI,EAAE,EAAE;QACR,QAAQ,EAAE;YACR;gBACE,OAAO,EAAE,MAAM;gBACf,IAAI,EAAE,oCAAmB,CAAC,IAAI;gBAC9B,MAAM,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE;aACnC;SACF;KACF;IACD,IAAI,EAAE,uCAAsB,CAAC,OAAO;IACpC,UAAU,EAAE,QAAQ;IACpB,OAAO,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE;IAC1B,MAAM,EAAE;QACN,MAAM,EAAE,EAAE,IAAI,EAAE,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,wBAAwB,CAAC,EAAE;KACrB;CAC9C,CAAC;AAEF,IAAI,CA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AC,CAAC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport path from 'path';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n EthereumBlock,\n EthereumDatasourceKind,\n EthereumHandlerKind,\n EthereumLogFilter,\n SubqlRuntimeDatasource,\n} from '@subql/types-ethereum';\nimport { EthereumApi } from './api.ethereum';\nimport {\n filterLogsProcessor,\n filterTransactionsProcessor,\n} from './block.ethereum';\n\n// Add api key to work\n// const HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';\nconst HTTP_ENDPOINT = 'https://eth.llamarpc.com';\nconst BLOCK_CONFIRMATIONS = 20;\n\nconst ds: SubqlRuntimeDatasource = {\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'test',\n kind: EthereumHandlerKind.Call,\n filter: { function: '0x23b872dd' },\n },\n ],\n },\n kind: EthereumDatasourceKind.Runtime,\n startBlock: 16258633,\n options: { abi: 'erc721' },\n assets: {\n erc721: { file: path.join(__dirname, '../../test/erc721.json') },\n } as unknown as Map<string, { file: string }>,\n};\n\njest.setTimeout(90000);\ndescribe('Api.ethereum', () => {\n let ethApi: EthereumApi;\n const eventEmitter = new EventEmitter2();\n let blockData: EthereumBlock;\n\n const fetchBlock = async (height: number) => {\n const block = await ethApi.fetchBlock(height);\n\n return block as EthereumBlock;\n };\n\n beforeEach(async () => {\n ethApi = new EthereumApi(HTTP_ENDPOINT, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(16258633);\n });\n\n it('Should format transaction in logs, and the transaction gas should be bigInt type', () => {\n expect(typeof blockData.logs[0].transaction.gas).toBe('bigint');\n expect(typeof blockData.logs[0].transaction.blockNumber).toBe('number');\n expect(typeof blockData.logs[0].transaction.gasPrice).toBe('bigint');\n expect(typeof blockData.logs[0].transaction.maxPriorityFeePerGas).toBe(\n 'bigint',\n );\n expect(typeof blockData.logs[0].transaction.transactionIndex).toBe(\n 'bigint',\n );\n });\n\n it('Decode nested logs in transactions', async () => {\n // Erc721\n const tx = blockData.transactions.find(\n (e) =>\n e.hash ===\n '0x8e419d0e36d7f9c099a001fded516bd168edd9d27b4aec2bcd56ba3b3b955ccc',\n );\n const parsedTx = await ethApi.parseTransaction(tx, ds);\n expect(parsedTx.logs[0].args).toBeTruthy();\n });\n\n it('Should return raw logs, if decode fails', async () => {\n // not Erc721\n const tx = blockData.transactions.find(\n (e) =>\n e.hash ===\n '0xed62f7a7720fe6ae05dec45ad9dd4f53034a0aae2c140d229b1151504ee9a6c9',\n );\n const parsedLog = await ethApi.parseLog(tx.logs[0], ds);\n expect(parsedLog).not.toHaveProperty('args');\n expect(parsedLog).toBeTruthy();\n });\n it('Null filter support', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(2847447);\n const result = blockData.transactions.filter((tx) => {\n if (\n filterTransactionsProcessor(\n tx,\n { to: null },\n '0x72a33394f0652e2bf15d7901f3cd46863d968424',\n )\n ) {\n return tx.hash;\n }\n });\n expect(result[0].hash).toBe(\n '0x24bef923522a4d6a79f9ab9242a74fb987dce94002c0f107c2a7d0b7e24bcf05',\n );\n expect(result.length).toBe(1);\n });\n\n it('!null filter support for logs, expect to filter out', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n const filter_1: EthereumLogFilter = {\n topics: [\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n undefined,\n undefined,\n '!null',\n ],\n };\n\n const filter_2: EthereumLogFilter = {\n topics: [\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n ],\n };\n\n blockData = await fetchBlock(4015990);\n const transaction = blockData.transactions.find(\n (tx) =>\n tx.hash ===\n '0xeb2e443f2d4e784193fa13bbbae2b85e6ee459e7b7b53f8ca098ffae9b25b059',\n );\n\n const erc20Transfers = transaction.logs.filter((log) =>\n filterLogsProcessor(log, filter_2),\n );\n const erc721Transfers = transaction.logs.filter((log) =>\n filterLogsProcessor(log, filter_1),\n );\n\n expect(erc20Transfers.length).toBe(7);\n expect(erc721Transfers.length).toBe(2);\n });\n\n it('Null filter support, for undefined transaction.to', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(2847447);\n blockData.transactions[1].to = undefined;\n const result = blockData.transactions.filter((tx) => {\n if (\n filterTransactionsProcessor(\n tx,\n { to: null },\n '0x72a33394f0652e2bf15d7901f3cd46863d968424',\n )\n ) {\n return tx.hash;\n }\n });\n expect(result[0].hash).toBe(\n '0x24bef923522a4d6a79f9ab9242a74fb987dce94002c0f107c2a7d0b7e24bcf05',\n );\n expect(result.length).toBe(1);\n });\n\n it('Should return all tx if filter.to is not defined', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(2847447);\n const result = blockData.transactions.filter((tx) => {\n if (\n filterTransactionsProcessor(\n tx,\n undefined,\n '0x72a33394f0652e2bf15d7901f3cd46863d968424',\n )\n ) {\n return tx.hash;\n }\n });\n expect(result.length).toBe(2);\n });\n\n it('filter.to Should support only null not undefined', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(2847447);\n const result = blockData.transactions.filter((tx) => {\n if (\n filterTransactionsProcessor(\n tx,\n { to: undefined },\n '0x72a33394f0652e2bf15d7901f3cd46863d968424',\n )\n ) {\n return tx.hash;\n }\n });\n expect(result.length).toBe(0);\n });\n it('If transaction is undefined, with null filter, should be supported', async () => {\n const beamEndpoint = 'https://rpc.api.moonbeam.network';\n ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);\n await ethApi.init();\n blockData = await fetchBlock(2847447);\n const result = blockData.transactions.filter((tx) => {\n tx.to = undefined;\n if (\n filterTransactionsProcessor(\n tx,\n { to: null },\n '0x72a33394f0652e2bf15d7901f3cd46863d968424',\n )\n ) {\n return tx.hash;\n }\n });\n expect(result.length).toBe(2);\n });\n\n it('Resolves the correct tags for finalization', async () => {\n // Ethereum\n expect((ethApi as any).supportsFinalization).toBeTruthy();\n\n // Moonbeam\n ethApi = new EthereumApi(\n 'https://rpc.api.moonbeam.network',\n BLOCK_CONFIRMATIONS,\n eventEmitter,\n );\n await ethApi.init();\n\n expect((ethApi as any).supportsFinalization).toBeTruthy();\n\n // BSC\n ethApi = new EthereumApi(\n 'https://bsc-dataseed.binance.org',\n BLOCK_CONFIRMATIONS,\n eventEmitter,\n );\n await ethApi.init();\n\n expect((ethApi as any).supportsFinalized).toBeFalsy();\n\n // Polygon\n ethApi = new EthereumApi(\n 'https://polygon.llamarpc.com',\n BLOCK_CONFIRMATIONS,\n eventEmitter,\n );\n await ethApi.init();\n\n expect((ethApi as any).supportsFinalized).toBeFalsy();\n });\n});\n"]}
|
|
@@ -10,7 +10,8 @@ const lodash_1 = require("lodash");
|
|
|
10
10
|
const api_service_ethereum_1 = require("./api.service.ethereum");
|
|
11
11
|
// Add api key to work
|
|
12
12
|
const WS_ENDPOINT = 'wss://eth.api.onfinality.io/ws?apikey=';
|
|
13
|
-
const HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';
|
|
13
|
+
// const HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';
|
|
14
|
+
const HTTP_ENDPOINT = 'https://eth.llamarpc.com';
|
|
14
15
|
function testSubqueryProject(endpoint) {
|
|
15
16
|
return {
|
|
16
17
|
network: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.service.ethereum.test.js","sourceRoot":"","sources":["../../src/ethereum/api.service.ethereum.test.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAGnC,yDAA2D;AAC3D,6CAAuC;AACvC,gDAI0B;AAC1B,qCAAwC;AACxC,mCAA+B;AAE/B,iEAA4D;AAE5D,sBAAsB;AACtB,MAAM,WAAW,GAAG,wCAAwC,CAAC;AAC7D,MAAM,aAAa,GAAG,
|
|
1
|
+
{"version":3,"file":"api.service.ethereum.test.js","sourceRoot":"","sources":["../../src/ethereum/api.service.ethereum.test.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAGnC,yDAA2D;AAC3D,6CAAuC;AACvC,gDAI0B;AAC1B,qCAAwC;AACxC,mCAA+B;AAE/B,iEAA4D;AAE5D,sBAAsB;AACtB,MAAM,WAAW,GAAG,wCAAwC,CAAC;AAC7D,gEAAgE;AAChE,MAAM,aAAa,GAAG,0BAA0B,CAAC;AAEjD,SAAS,mBAAmB,CAAC,QAAgB;IAC3C,OAAO;QACL,OAAO,EAAE;YACP,QAAQ,EAAE,CAAC,QAAQ,CAAC;YACpB,OAAO,EAAE,GAAG;SACb;QACD,WAAW,EAAE,EAAE;QACf,EAAE,EAAE,MAAM;QACV,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,IAAI,uBAAa,CAAC,EAAE,CAAC;QAC7B,SAAS,EAAE,EAAE;KACP,CAAC;AACX,CAAC;AAED,MAAM,iBAAiB,GAAG,KAAK,EAC7B,WAAmB,aAAa,EACiB,EAAE;IACnD,MAAM,MAAM,GAAG,MAAM,cAAI,CAAC,mBAAmB,CAAC;QAC5C,SAAS,EAAE;YACT,iCAAqB;YACrB,sCAA0B;YAC1B;gBACE,OAAO,EAAE,sBAAU;gBACnB,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;aACvB;YACD;gBACE,OAAO,EAAE,kB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CAAC,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8BAA8B,EAAE,KAAK,IAAI,EAAE;QAC5C,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,GAAG,CAAC,uBAAuB,EAAE,CAAC;QAE9D,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;QACxC,MAAM,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,QAAU,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+CAA+C,EAAE,KAAK,IAAI,EAAE;QAC7D,MAAM,MAAM,CACV,UAAU;aACP,OAAO,CAAC,QAAQ,CAAC;aACjB,OAAO,CAAC,2CAA2C,CAAC,CACxD,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,sDAAsD,EAAE,KAAK,IAAI,EAAE;QACpE,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;QAC/D,MAAM,MAAM,CACV,UAAU;aACP,OAAO,CAAC,QAAQ,CAAC;aACjB,OAAO,CAAC,2CAA2C,CAAC,CACxD,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;QAErD,MAAM,CAAC,OAAO,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { INestApplication } from '@nestjs/common';\nimport { EventEmitterModule } from '@nestjs/event-emitter';\nimport { Test } from '@nestjs/testing';\nimport {\n ConnectionPoolService,\n ConnectionPoolStateManager,\n NodeConfig,\n} from '@subql/node-core';\nimport { GraphQLSchema } from 'graphql';\nimport { range } from 'lodash';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { EthereumApiService } from './api.service.ethereum';\n\n// Add api key to work\nconst WS_ENDPOINT = 'wss://eth.api.onfinality.io/ws?apikey=';\n// const HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';\nconst HTTP_ENDPOINT = 'https://eth.llamarpc.com';\n\nfunction testSubqueryProject(endpoint: string): SubqueryProject {\n return {\n network: {\n endpoint: [endpoint],\n chainId: '1',\n },\n dataSources: [],\n id: 'test',\n root: './',\n schema: new GraphQLSchema({}),\n templates: [],\n } as any;\n}\n\nconst prepareApiService = async (\n endpoint: string = HTTP_ENDPOINT,\n): Promise<[EthereumApiService, INestApplication]> => {\n const module = await Test.createTestingModule({\n providers: [\n ConnectionPoolService,\n ConnectionPoolStateManager,\n {\n provide: NodeConfig,\n useFactory: () => ({}),\n },\n {\n provide: 'ISubqueryProject',\n useFactory: () => testSubqueryProject(endpoint),\n },\n EthereumApiService,\n ],\n imports: [EventEmitterModule.forRoot()],\n }).compile();\n\n const app = module.createNestApplication();\n await app.init();\n const apiService = app.get(EthereumApiService);\n await apiService.init();\n return [apiService, app];\n};\n\njest.setTimeout(90000);\ndescribe('ApiService', () => {\n let apiService: EthereumApiService;\n let app: INestApplication;\n\n beforeEach(async () => {\n [apiService, app] = await prepareApiService();\n });\n\n afterEach(async () => {\n return app?.close();\n });\n\n it('can instantiate api', () => {\n expect(apiService.api.getChainId()).toEqual(1);\n });\n\n it('can fetch blocks', async () => {\n await expect(\n apiService.api.fetchBlocks(range(12369621, 12369625)),\n ).resolves.toHaveLength(4);\n });\n\n it('can get the finalized height', async () => {\n const height = await apiService.api.getFinalizedBlockHeight();\n\n console.log('Finalized height', height);\n expect(height).toBeGreaterThan(16_000_000);\n });\n\n it('ensure api errorCode is exposed when throwing', async () => {\n await expect(\n apiService\n .safeApi(17520376)\n .getCode('0x75F0398549C9fDEa03BbDde388361827cb376D5'),\n ).rejects.toHaveProperty('code', 'INVALID_ARGUMENT');\n });\n it('should not retry on any errors not in the retry list', async () => {\n const callSpy = jest.spyOn(apiService.unsafeApi, 'getSafeApi');\n await expect(\n apiService\n .safeApi(17520376)\n .getCode('0x75F0398549C9fDEa03BbDde388361827cb376D5'),\n ).rejects.toHaveProperty('code', 'INVALID_ARGUMENT');\n\n expect(callSpy).toHaveBeenCalledTimes(1);\n });\n});\n"]}
|
|
@@ -25,14 +25,9 @@ const node_core_1 = require("@subql/node-core");
|
|
|
25
25
|
const SubqueryProject_1 = require("../../configure/SubqueryProject");
|
|
26
26
|
const dynamic_ds_service_1 = require("../dynamic-ds.service");
|
|
27
27
|
const unfinalizedBlocks_service_1 = require("../unfinalizedBlocks.service");
|
|
28
|
-
async function createIndexerWorker(store, cache, dynamicDsService, unfinalizedBlocksService, connectionPoolState, root, startHeight) {
|
|
29
|
-
const indexerWorker = node_core_1.Worker.create(path_1.default.resolve(__dirname, '../../../dist/indexer/worker/worker.js'), [...node_core_1.baseWorkerFunctions, 'initWorker'], Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (0, node_core_1.cacheHostFunctions)(cache)), (0, node_core_1.storeHostFunctions)(store)), (0, node_core_1.dynamicDsHostFunctions)(dynamicDsService)), { unfinalizedBlocksProcess: unfinalizedBlocksService.processUnfinalizedBlockHeader.bind(unfinalizedBlocksService) }), (0, node_core_1.connectionPoolStateHostFunctions)(connectionPoolState)), root);
|
|
30
|
-
await indexerWorker.initWorker(startHeight);
|
|
31
|
-
return indexerWorker;
|
|
32
|
-
}
|
|
33
28
|
let WorkerBlockDispatcherService = class WorkerBlockDispatcherService extends node_core_1.WorkerBlockDispatcher {
|
|
34
29
|
constructor(nodeConfig, eventEmitter, projectService, projectUpgadeService, smartBatchService, cacheService, storeService, storeCacheService, poiService, poiSyncService, project, dynamicDsService, unfinalizedBlocksSevice, connectionPoolState) {
|
|
35
|
-
super(nodeConfig, eventEmitter, projectService, projectUpgadeService, smartBatchService, storeService, storeCacheService, poiService, poiSyncService, project, dynamicDsService, () => createIndexerWorker(storeService.getStore(), cacheService.getCache(), dynamicDsService, unfinalizedBlocksSevice, connectionPoolState, project.root, projectService.startHeight));
|
|
30
|
+
super(nodeConfig, eventEmitter, projectService, projectUpgadeService, smartBatchService, storeService, storeCacheService, poiService, poiSyncService, project, dynamicDsService, () => (0, node_core_1.createIndexerWorker)(path_1.default.resolve(__dirname, '../../../dist/indexer/worker/worker.js'), [], storeService.getStore(), cacheService.getCache(), dynamicDsService, unfinalizedBlocksSevice, connectionPoolState, project.root, projectService.startHeight));
|
|
36
31
|
}
|
|
37
32
|
async fetchBlock(worker, height) {
|
|
38
33
|
const start = new Date();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-block-dispatcher.service.js","sourceRoot":"","sources":["../../../src/indexer/blockDispatcher/worker-block-dispatcher.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;;;;AAEnC,gDAAwB;AACxB,2CAA2E;AAC3E,yDAAsD;AACtD,
|
|
1
|
+
{"version":3,"file":"worker-block-dispatcher.service.js","sourceRoot":"","sources":["../../../src/indexer/blockDispatcher/worker-block-dispatcher.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;;;;AAEnC,gDAAwB;AACxB,2CAA2E;AAC3E,yDAAsD;AACtD,gDAa0B;AAC1B,qEAGyC;AAEzC,8DAAyD;AAEzD,4EAAwE;AAQjE,IAAM,4BAA4B,GAAlC,MAAM,4BACX,SAAQ,iCAAuD;IAG/D,YACE,UAAsB,EACtB,YAA2B,EAE3B,cAAkD,EAElD,oBAA4C,EAC5C,iBAAoC,EACpC,YAAkC,EAClC,YAA0B,EAC1B,iBAAoC,EACpC,UAAsB,EACtB,cAA8B,EACF,OAAwB,EACpD,gBAAkC,EAClC,uBAAiD,EACjD,mBAAsE;QAEtE,KAAK,CACH,UAAU,EACV,YAAY,EACZ,cAAc,EACd,oBAAoB,EACpB,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,OAAO,EACP,gBAAgB,EAChB,GAAG,EAAE,CACH,IAAA,+BAAmB,EAMjB,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,wCAAwC,CAAC,EACjE,EAAE,EACF,YAAY,CAAC,QAAQ,EAAE,EACvB,YAAY,CAAC,QAAQ,EAAE,EACvB,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,OAAO,CAAC,IAAI,EACZ,cAAc,CAAC,WAAW,CAC3B,CACJ,CAAC;IACJ,CAAC;IAES,KAAK,CAAC,UAAU,CACxB,MAAqB,EACrB,MAAc;QAEd,MAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAC;QACzB,MAAM,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACtC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;QAEvB,oDAAoD;QACpD,yBAAyB;QACzB,iBAAiB;QACjB,yEAAyE;QACzE,OAAO;QACP,+BAA+B;QAC/B,iBAAiB;QACjB,4EAA4E;QAC5E,OAAO;QACP,IAAI;IACN,CAAC;CACF,CAAA;AAzEY,4BAA4B;IADxC,IAAA,mBAAU,GAAE;IAQR,WAAA,IAAA,eAAM,EAAC,iBAAiB,CAAC,CAAA;IAEzB,WAAA,IAAA,eAAM,EAAC,wBAAwB,CAAC,CAAA;IAQhC,YAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;qCAZf,sBAAU;QACR,6BAAa,kBAKR,6BAAiB;QACtB,gCAAoB;QACpB,wBAAY;QACP,6BAAiB;QACxB,sBAAU;QACN,0BAAc;QACO,iCAAe;QAClC,qCAAgB;QACT,oDAAwB;QAC5B,sCAA0B;GApBtC,4BAA4B,CAyExC;AAzEY,oEAA4B","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport path from 'path';\nimport { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n NodeConfig,\n SmartBatchService,\n StoreService,\n PoiService,\n StoreCacheService,\n IProjectService,\n WorkerBlockDispatcher,\n ConnectionPoolStateManager,\n IProjectUpgradeService,\n PoiSyncService,\n InMemoryCacheService,\n createIndexerWorker,\n} from '@subql/node-core';\nimport {\n EthereumProjectDs,\n SubqueryProject,\n} from '../../configure/SubqueryProject';\nimport { EthereumApiConnection } from '../../ethereum/api.connection';\nimport { DynamicDsService } from '../dynamic-ds.service';\nimport { BlockContent } from '../types';\nimport { UnfinalizedBlocksService } from '../unfinalizedBlocks.service';\nimport { IIndexerWorker } from '../worker/worker';\n\ntype IndexerWorker = IIndexerWorker & {\n terminate: () => Promise<number>;\n};\n\n@Injectable()\nexport class WorkerBlockDispatcherService\n extends WorkerBlockDispatcher<EthereumProjectDs, IndexerWorker>\n implements OnApplicationShutdown\n{\n constructor(\n nodeConfig: NodeConfig,\n eventEmitter: EventEmitter2,\n @Inject('IProjectService')\n projectService: IProjectService<EthereumProjectDs>,\n @Inject('IProjectUpgradeService')\n projectUpgadeService: IProjectUpgradeService,\n smartBatchService: SmartBatchService,\n cacheService: InMemoryCacheService,\n storeService: StoreService,\n storeCacheService: StoreCacheService,\n poiService: PoiService,\n poiSyncService: PoiSyncService,\n @Inject('ISubqueryProject') project: SubqueryProject,\n dynamicDsService: DynamicDsService,\n unfinalizedBlocksSevice: UnfinalizedBlocksService,\n connectionPoolState: ConnectionPoolStateManager<EthereumApiConnection>,\n ) {\n super(\n nodeConfig,\n eventEmitter,\n projectService,\n projectUpgadeService,\n smartBatchService,\n storeService,\n storeCacheService,\n poiService,\n poiSyncService,\n project,\n dynamicDsService,\n () =>\n createIndexerWorker<\n IIndexerWorker,\n EthereumApiConnection,\n BlockContent,\n EthereumProjectDs\n >(\n path.resolve(__dirname, '../../../dist/indexer/worker/worker.js'),\n [],\n storeService.getStore(),\n cacheService.getCache(),\n dynamicDsService,\n unfinalizedBlocksSevice,\n connectionPoolState,\n project.root,\n projectService.startHeight,\n ),\n );\n }\n\n protected async fetchBlock(\n worker: IndexerWorker,\n height: number,\n ): Promise<void> {\n const start = new Date();\n await worker.fetchBlock(height, null);\n const end = new Date();\n\n // const waitTime = end.getTime() - start.getTime();\n // if (waitTime > 1000) {\n // logger.info(\n // `Waiting to fetch block ${height}: ${chalk.red(`${waitTime}ms`)}`,\n // );\n // } else if (waitTime > 200) {\n // logger.info(\n // `Waiting to fetch block ${height}: ${chalk.yellow(`${waitTime}ms`)}`,\n // );\n // }\n }\n}\n"]}
|
|
@@ -5,7 +5,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
const types_ethereum_1 = require("@subql/types-ethereum");
|
|
6
6
|
const graphql_1 = require("graphql");
|
|
7
7
|
const fetch_service_1 = require("./fetch.service");
|
|
8
|
-
const HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';
|
|
8
|
+
// const HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';
|
|
9
|
+
const HTTP_ENDPOINT = 'https://eth.llamarpc.com';
|
|
9
10
|
const mockTempDs = [
|
|
10
11
|
{
|
|
11
12
|
name: 'ERC721',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.service.spec.js","sourceRoot":"","sources":["../../src/indexer/fetch.service.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,0DAI+B;AAC/B,qCAAwC;AAKxC,mDAA4E;AAE5E,MAAM,aAAa,GAAG,sCAAsC,CAAC;AAC7D,MAAM,UAAU,GAAgC;IAC9C;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,uCAAsB,CAAC,OAAO;QACpC,MAAM,EAAE,IAAI,GAAG,EAAE;QACjB,OAAO,EAAE;YACP,WAAW,EAAE,EAAE;YACf,IAAI,EAAE,EAAE;YACR,QAAQ,EAAE;gBACR;oBACE,OAAO,EAAE,cA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;4BACE,KAAK,EAAE,SAAS;4BAChB,KAAK,EACH,oEAAoE;4BACtE,OAAO,EAAE,SAAS;yBACnB;qBACF;iBACF;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport {\n EthereumDatasourceKind,\n EthereumHandlerKind,\n SubqlRuntimeDatasource,\n} from '@subql/types-ethereum';\nimport { GraphQLSchema } from 'graphql';\nimport {\n EthereumProjectDsTemplate,\n SubqueryProject,\n} from '../configure/SubqueryProject';\nimport { buildDictionaryQueryEntries, FetchService } from './fetch.service';\n\nconst HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';\nconst mockTempDs: EthereumProjectDsTemplate[] = [\n {\n name: 'ERC721',\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n mapping: {\n entryScript: '',\n file: '',\n handlers: [\n {\n handler: 'handleERC721',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: ['Transfer(address, address, uint256)'],\n },\n },\n ],\n },\n },\n {\n name: 'ERC1155',\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n mapping: {\n entryScript: '',\n file: '',\n handlers: [\n {\n handler: 'handleERC1155',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'TransferSingle(address, address, address, uint256, uint256)',\n ],\n },\n },\n ],\n },\n },\n];\n\nfunction testSubqueryProject(\n endpoint: string,\n ds: any,\n mockTempDs,\n): SubqueryProject {\n return {\n network: {\n endpoint,\n chainId: '1',\n },\n dataSources: ds as any,\n id: 'test',\n root: './',\n schema: new GraphQLSchema({}),\n templates: mockTempDs as any,\n } as any;\n}\n\ndescribe('Dictionary queries', () => {\n describe('Log filters', () => {\n it('Build filter for !null', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleLog',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'Transfer(address, address, uint256)',\n undefined,\n undefined,\n '!null',\n ],\n },\n },\n ],\n },\n };\n const result = buildDictionaryQueryEntries([ds]);\n\n expect(result).toEqual([\n {\n entity: 'evmLogs',\n conditions: [\n {\n field: 'address',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n {\n field: 'topics0',\n value:\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n matcher: 'equalTo',\n },\n {\n field: 'topics3',\n value: false,\n matcher: 'isNull',\n },\n ],\n },\n ]);\n });\n });\n\n describe('Transaction filters', () => {\n it('Build a filter for contract creation transactions', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransaction',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: null,\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryQueryEntries([ds]);\n\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [{ field: 'to', matcher: 'isNull', value: true }],\n },\n ]);\n });\n\n it('Build a filter with include ds option and contract address', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryQueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n\n it('If ds option and filter both provide contract address, it should use ds options one', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: '0xabcde',\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryQueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n\n it('If ds option provide contract address, it should use ds options \"address\"', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryQueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n\n it('If filter provide contract address, it should use filter \"to\"', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: '0xabcde',\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryQueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0xabcde',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n });\n describe('Correct dictionary query with dynamic ds', () => {\n it('Build correct erc1155 transfer single query', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleDyanmicDs',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'TransferSingle(address, address, address, uint256, uint256)',\n ],\n },\n },\n ],\n },\n };\n const result = buildDictionaryQueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmLogs',\n conditions: [\n {\n field: 'topics0',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n matcher: 'equalTo',\n },\n ],\n },\n ]);\n });\n\n it('Builds a groupded query for multiple dynamic ds', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleDyanmicDs',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'TransferSingle(address, address, address, uint256, uint256)',\n ],\n },\n },\n ],\n },\n };\n\n const duplicateDataSources = [\n { ...mockTempDs[0], options: { address: 'address1' } },\n { ...mockTempDs[0], options: { address: 'address2' } },\n { ...mockTempDs[1], options: { address: 'address3' } },\n ];\n\n const dataSources = [ds, ...duplicateDataSources];\n\n const project = testSubqueryProject(\n HTTP_ENDPOINT,\n dataSources,\n mockTempDs,\n );\n\n const fetchService = new FetchService(\n null,\n null,\n null,\n project,\n null,\n null,\n null,\n null,\n null,\n null,\n );\n\n const queryEntry = (fetchService as any).buildDictionaryQueryEntries(\n dataSources,\n );\n\n expect(queryEntry).toEqual([\n {\n entity: 'evmLogs',\n conditions: [\n {\n field: 'topics0',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n matcher: 'equalTo',\n },\n ],\n },\n {\n entity: 'evmLogs',\n conditions: [\n {\n field: 'address',\n // This is what we're looking to happen with multiple instances of template\n value: ['address1', 'address2'],\n matcher: 'in',\n },\n {\n field: 'topics0',\n value:\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n matcher: 'equalTo',\n },\n ],\n },\n {\n entity: 'evmLogs',\n conditions: [\n // This condition should not be grouped because there is a single instance of the tamplate\n {\n field: 'address',\n value: 'address3',\n matcher: 'equalTo',\n },\n {\n field: 'topics0',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n matcher: 'equalTo',\n },\n ],\n },\n ]);\n });\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"fetch.service.spec.js","sourceRoot":"","sources":["../../src/indexer/fetch.service.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,0DAI+B;AAC/B,qCAAwC;AAKxC,mDAA4E;AAE5E,gEAAgE;AAChE,MAAM,aAAa,GAAG,0BAA0B,CAAC;AACjD,MAAM,UAAU,GAAgC;IAC9C;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,uCAAsB,CAAC,OAAO;QACpC,MAAM,EAAE,IAAI,GAAG,EAAE;QACjB,OAAO,EAAE;YACP,WAAW,EAAE,EAAE;YACf,IAAI,EAAE,EAAE;YACR,QAAQ,EAAE;gBACR;oBACE,OAAO,EAA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wBACD;4BACE,KAAK,EAAE,SAAS;4BAChB,KAAK,EACH,oEAAoE;4BACtE,OAAO,EAAE,SAAS;yBACnB;qBACF;iBACF;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport {\n EthereumDatasourceKind,\n EthereumHandlerKind,\n SubqlRuntimeDatasource,\n} from '@subql/types-ethereum';\nimport { GraphQLSchema } from 'graphql';\nimport {\n EthereumProjectDsTemplate,\n SubqueryProject,\n} from '../configure/SubqueryProject';\nimport { buildDictionaryQueryEntries, FetchService } from './fetch.service';\n\n// const HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';\nconst HTTP_ENDPOINT = 'https://eth.llamarpc.com';\nconst mockTempDs: EthereumProjectDsTemplate[] = [\n {\n name: 'ERC721',\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n mapping: {\n entryScript: '',\n file: '',\n handlers: [\n {\n handler: 'handleERC721',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: ['Transfer(address, address, uint256)'],\n },\n },\n ],\n },\n },\n {\n name: 'ERC1155',\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n mapping: {\n entryScript: '',\n file: '',\n handlers: [\n {\n handler: 'handleERC1155',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'TransferSingle(address, address, address, uint256, uint256)',\n ],\n },\n },\n ],\n },\n },\n];\n\nfunction testSubqueryProject(\n endpoint: string,\n ds: any,\n mockTempDs,\n): SubqueryProject {\n return {\n network: {\n endpoint,\n chainId: '1',\n },\n dataSources: ds as any,\n id: 'test',\n root: './',\n schema: new GraphQLSchema({}),\n templates: mockTempDs as any,\n } as any;\n}\n\ndescribe('Dictionary queries', () => {\n describe('Log filters', () => {\n it('Build filter for !null', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleLog',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'Transfer(address, address, uint256)',\n undefined,\n undefined,\n '!null',\n ],\n },\n },\n ],\n },\n };\n const result = buildDictionaryQueryEntries([ds]);\n\n expect(result).toEqual([\n {\n entity: 'evmLogs',\n conditions: [\n {\n field: 'address',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n {\n field: 'topics0',\n value:\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n matcher: 'equalTo',\n },\n {\n field: 'topics3',\n value: false,\n matcher: 'isNull',\n },\n ],\n },\n ]);\n });\n });\n\n describe('Transaction filters', () => {\n it('Build a filter for contract creation transactions', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransaction',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: null,\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryQueryEntries([ds]);\n\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [{ field: 'to', matcher: 'isNull', value: true }],\n },\n ]);\n });\n\n it('Build a filter with include ds option and contract address', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryQueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n\n it('If ds option and filter both provide contract address, it should use ds options one', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: '0xabcde',\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryQueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n\n it('If ds option provide contract address, it should use ds options \"address\"', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryQueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n\n it('If filter provide contract address, it should use filter \"to\"', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: '0xabcde',\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryQueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0xabcde',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n });\n describe('Correct dictionary query with dynamic ds', () => {\n it('Build correct erc1155 transfer single query', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleDyanmicDs',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'TransferSingle(address, address, address, uint256, uint256)',\n ],\n },\n },\n ],\n },\n };\n const result = buildDictionaryQueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmLogs',\n conditions: [\n {\n field: 'topics0',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n matcher: 'equalTo',\n },\n ],\n },\n ]);\n });\n\n it('Builds a groupded query for multiple dynamic ds', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleDyanmicDs',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'TransferSingle(address, address, address, uint256, uint256)',\n ],\n },\n },\n ],\n },\n };\n\n const duplicateDataSources = [\n { ...mockTempDs[0], options: { address: 'address1' } },\n { ...mockTempDs[0], options: { address: 'address2' } },\n { ...mockTempDs[1], options: { address: 'address3' } },\n ];\n\n const dataSources = [ds, ...duplicateDataSources];\n\n const project = testSubqueryProject(\n HTTP_ENDPOINT,\n dataSources,\n mockTempDs,\n );\n\n const fetchService = new FetchService(\n null,\n null,\n null,\n project,\n null,\n null,\n null,\n null,\n null,\n null,\n );\n\n const queryEntry = (fetchService as any).buildDictionaryQueryEntries(\n dataSources,\n );\n\n expect(queryEntry).toEqual([\n {\n entity: 'evmLogs',\n conditions: [\n {\n field: 'topics0',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n matcher: 'equalTo',\n },\n ],\n },\n {\n entity: 'evmLogs',\n conditions: [\n {\n field: 'address',\n // This is what we're looking to happen with multiple instances of template\n value: ['address1', 'address2'],\n matcher: 'in',\n },\n {\n field: 'topics0',\n value:\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n matcher: 'equalTo',\n },\n ],\n },\n {\n entity: 'evmLogs',\n conditions: [\n // This condition should not be grouped because there is a single instance of the tamplate\n {\n field: 'address',\n value: 'address3',\n matcher: 'equalTo',\n },\n {\n field: 'topics0',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n matcher: 'equalTo',\n },\n ],\n },\n ]);\n });\n });\n});\n"]}
|
|
@@ -5,8 +5,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
const event_emitter_1 = require("@nestjs/event-emitter");
|
|
6
6
|
const ethereum_1 = require("../ethereum");
|
|
7
7
|
const project_service_1 = require("./project.service");
|
|
8
|
+
const HTTP_ENDPOINT = 'https://eth.llamarpc.com';
|
|
8
9
|
const mockApiService = () => {
|
|
9
|
-
const ethApi = new ethereum_1.EthereumApi(
|
|
10
|
+
const ethApi = new ethereum_1.EthereumApi(HTTP_ENDPOINT, 20, new event_emitter_1.EventEmitter2());
|
|
10
11
|
// await ethApi.init();
|
|
11
12
|
return {
|
|
12
13
|
unsafeApi: ethApi,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.service.test.js","sourceRoot":"","sources":["../../src/indexer/project.service.test.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,yDAAsD;AACtD,0CAA8D;AAC9D,uDAAmD;AAEnD,MAAM,cAAc,GAAG,GAAuB,EAAE;IAC9C,MAAM,MAAM,GAAG,IAAI,sBAAW,
|
|
1
|
+
{"version":3,"file":"project.service.test.js","sourceRoot":"","sources":["../../src/indexer/project.service.test.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,yDAAsD;AACtD,0CAA8D;AAC9D,uDAAmD;AAEnD,MAAM,aAAa,GAAG,0BAA0B,CAAC;AAEjD,MAAM,cAAc,GAAG,GAAuB,EAAE;IAC9C,MAAM,MAAM,GAAG,IAAI,sBAAW,CAAC,aAAa,EAAE,EAAE,EAAE,IAAI,6BAAa,EAAE,CAAC,CAAC;IAEvE,uBAAuB;IAEvB,OAAO;QACL,SAAS,EAAE,MAAM;KACX,CAAC;AACX,CAAC,CAAC;AAEF,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,IAAI,cAA8B,CAAC;IAEnC,UAAU,CAAC,GAAG,EAAE;QACd,MAAM,UAAU,GAAG,cAAc,EAAE,CAAC;QAEpC,cAAc,GAAG,IAAI,gCAAc,CACjC,IAAI,EACJ,UAAU,EACV,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,EAAS,EACT,IAAI,EACJ,IAAI,EACJ,IAAI,CACL,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;QAC1C,MAAM,SAAS,GAAG,MAAO,cAAsB,CAAC,iBAAiB,CAC/D,OAAS,CACV,CAAC;QAEF,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,0BAA0B,CAAC,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { EthereumApi, EthereumApiService } from '../ethereum';\nimport { ProjectService } from './project.service';\n\nconst HTTP_ENDPOINT = 'https://eth.llamarpc.com';\n\nconst mockApiService = (): EthereumApiService => {\n const ethApi = new EthereumApi(HTTP_ENDPOINT, 20, new EventEmitter2());\n\n // await ethApi.init();\n\n return {\n unsafeApi: ethApi,\n } as any;\n};\n\ndescribe('ProjectService', () => {\n let projectService: ProjectService;\n\n beforeEach(() => {\n const apiService = mockApiService();\n\n projectService = new ProjectService(\n null,\n apiService,\n null,\n null,\n null,\n null,\n null,\n null,\n {} as any,\n null,\n null,\n null,\n );\n });\n\n it('can get a block timestamps', async () => {\n const timestamp = await (projectService as any).getBlockTimestamp(\n 4_000_000,\n );\n\n expect(timestamp).toEqual(new Date('2017-07-09T20:52:47.000Z'));\n });\n});\n"]}
|
|
@@ -1,7 +1,2 @@
|
|
|
1
1
|
import { IBaseIndexerWorker } from '@subql/node-core';
|
|
2
|
-
declare function initWorker(startHeight: number): Promise<void>;
|
|
3
2
|
export type IIndexerWorker = IBaseIndexerWorker;
|
|
4
|
-
export type IInitIndexerWorker = IIndexerWorker & {
|
|
5
|
-
initWorker: typeof initWorker;
|
|
6
|
-
};
|
|
7
|
-
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../src/indexer/worker/worker.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,iEAAiE;AACjE,kDAAkD;AAClD,wCAAwC;AACxC,oDAAqD;AACrD,wCAAwC;AACxC,uCAA2C;AAE3C,MAAM,EAAE,IAAI,EAAE,GAAG,oBAAY,CAAC;AAE9B,IAAA,mB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AAA,mBAAU,EACR,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,SAA+B,EACpC,IAAI,CAAC,QAA8B,CACpC,CAAC;AAEF,6DAA+C;AAC/C,uCAA2C;AAC3C,gDAM0B;AAE1B,mDAA+C;AAC/C,qDAAiD;AAEjD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,WAAW,8BAAQ,EAAE,CAAC,CAAC;AAEhD,KAAK,UAAU,UAAU,CAAC,WAAmB;IAC3C,IAAI;QACF,MAAM,GAAG,GAAG,MAAM,kBAAW,CAAC,MAAM,CAAC,4BAAY,EAAE;YACjD,MAAM,EAAE,IAAI,sBAAU,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,0EAA0E;SACjH,CAAC,CAAC;QAEH,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QAEjB,MAAM,cAAc,GAAmB,GAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QAClE,uGAAuG;QACvG,MAAM,cAAc,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAEvC,MAAM,aAAa,GAAG,GAAG,CAAC,GAAG,CAAC,8BAAa,CAAC,CAAC;QAE7C,IAAA,8BAAkB,EAAC,GAAG,EAAE,aAAa,CAAC,CAAC;KACxC;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,CAAC,CAAC,CAAC;QACzC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,wBAAwB,CAAC,CAAC;QAC1C,MAAM,CAAC,CAAC;KACT;AACH,CAAC;AAIA,MAAc,CAAC,IAAI,GAAG,IAAA,4BAAgB,EAAC,EAAE,EAAE;IAC1C,UAAU;CACX,CAAC,CAAC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\n// initlogger and yargs must be imported before all other imports\n// making sure logger is defined before its called\n// eslint-disable-next-line import/order\nimport { initLogger } from '@subql/node-core/logger';\n// eslint-disable-next-line import/order\nimport { yargsOptions } from '../../yargs';\n\nconst { argv } = yargsOptions;\n\ninitLogger(\n argv.debug,\n argv.outputFmt as 'json' | 'colored',\n argv.logLevel as string | undefined,\n);\n\nimport { threadId } from 'node:worker_threads';\nimport { NestFactory } from '@nestjs/core';\nimport {\n getLogger,\n NestLogger,\n createWorkerHost,\n IBaseIndexerWorker,\n initWorkerServices,\n} from '@subql/node-core';\nimport { ProjectService } from '../project.service';\nimport { WorkerModule } from './worker.module';\nimport { WorkerService } from './worker.service';\n\nconst logger = getLogger(`worker #${threadId}`);\n\nasync function initWorker(startHeight: number): Promise<void> {\n try {\n const app = await NestFactory.create(WorkerModule, {\n logger: new NestLogger(!!argv.debug), // TIP: If the worker is crashing comment out this line for better logging\n });\n\n await app.init();\n\n const projectService: ProjectService = app.get('IProjectService');\n // Initialise async services, we do this here rather than in factories so we can capture one off events\n await projectService.init(startHeight);\n\n const workerService = app.get(WorkerService);\n\n initWorkerServices(app, workerService);\n } catch (e) {\n console.log('Failed to start worker', e);\n logger.error(e, 'Failed to start worker');\n throw e;\n }\n}\n\nexport type IIndexerWorker = IBaseIndexerWorker;\n\n(global as any).host = createWorkerHost([], {\n initWorker,\n});\n"]}
|
|
@@ -19,7 +19,6 @@ const indexer_manager_1 = require("./indexer.manager");
|
|
|
19
19
|
const project_service_1 = require("./project.service");
|
|
20
20
|
const sandbox_service_1 = require("./sandbox.service");
|
|
21
21
|
const unfinalizedBlocks_service_1 = require("./unfinalizedBlocks.service");
|
|
22
|
-
const worker_inMemoryCache_service_1 = require("./worker/worker.inMemoryCache.service");
|
|
23
22
|
const worker_service_1 = require("./worker/worker.service");
|
|
24
23
|
const worker_unfinalizedBlocks_service_1 = require("./worker/worker.unfinalizedBlocks.service");
|
|
25
24
|
let WorkerFetchModule = class WorkerFetchModule {
|
|
@@ -64,7 +63,7 @@ WorkerFetchModule = __decorate([
|
|
|
64
63
|
worker_service_1.WorkerService,
|
|
65
64
|
{
|
|
66
65
|
provide: node_core_1.InMemoryCacheService,
|
|
67
|
-
useFactory: () => new
|
|
66
|
+
useFactory: () => new node_core_1.WorkerInMemoryCacheService(global.host),
|
|
68
67
|
},
|
|
69
68
|
],
|
|
70
69
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-fetch.module.js","sourceRoot":"","sources":["../../src/indexer/worker-fetch.module.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;AAEnC,2CAAwC;AACxC,yDAAsD;AACtD,
|
|
1
|
+
{"version":3,"file":"worker-fetch.module.js","sourceRoot":"","sources":["../../src/indexer/worker-fetch.module.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;AAEnC,2CAAwC;AACxC,yDAAsD;AACtD,gDAS0B;AAE1B,0CAAiD;AAEjD,iEAA4D;AAC5D,6DAAwD;AACxD,uDAAmD;AACnD,uDAAmD;AACnD,uDAAmD;AACnD,2EAAuE;AACvE,4DAAwD;AACxD,gGAA2F;AAyDpF,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;CAAG,CAAA;AAApB,iBAAiB;IAvD7B,IAAA,eAAM,EAAC;QACN,SAAS,EAAE;YACT,gCAAc;YACd;gBACE,OAAO,EAAE,sCAA0B;gBACnC,UAAU,EAAE,GAAG,EAAE,CACf,IAAI,4CAAgC,CAAE,MAAc,CAAC,IAAI,CAAC;aAC7D;YACD,iCAAqB;YACrB;gBACE,OAAO,EAAE,sBAAU;gBACnB,UAAU,EAAE,KAAK,EACf,OAAwB,EACxB,qBAAmE,EACnE,YAA2B,EAC3B,UAAsB,EACtB,EAAE;oBACF,MAAM,UAAU,GAAG,IAAI,6BAAkB,CACvC,OAAO,EACP,qBAAqB,EACrB,YAAY,EACZ,UAAU,CACX,CAAC;oBACF,MAAM,UAAU,CAAC,IAAI,EAAE,CAAC;oBACxB,OAAO,UAAU,CAAC;gBACpB,CAAC;gBACD,MAAM,EAAE;oBACN,kBAAkB;oBAClB,iCAAqB;oBACrB,6BAAa;oBACb,sBAAU;iBACX;aACF;YACD,gCAAc;YACd,yCAAkB;YAClB;gBACE,OAAO,EAAE,qCAAgB;gBACzB,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI,kCAAsB,CAAE,MAAc,CAAC,IAAI,CAAC;aACnE;YACD;gBACE,OAAO,EAAE,iBAAiB;gBAC1B,QAAQ,EAAE,gCAAc;aACzB;YACD;gBACE,OAAO,EAAE,oDAAwB;gBACjC,UAAU,EAAE,GAAG,EAAE,CACf,IAAI,iEAA8B,CAAE,MAAc,CAAC,IAAI,CAAC;aAC3D;YACD,8BAAa;YACb;gBACE,OAAO,EAAE,gCAAoB;gBAC7B,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI,sCAA0B,CAAE,MAAc,CAAC,IAAI,CAAC;aACvE;SACF;KACF,CAAC;GACW,iBAAiB,CAAG;AAApB,8CAAiB","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Module } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n ApiService,\n ConnectionPoolService,\n WorkerDynamicDsService,\n WorkerConnectionPoolStateManager,\n ConnectionPoolStateManager,\n NodeConfig,\n InMemoryCacheService,\n WorkerInMemoryCacheService,\n} from '@subql/node-core';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { EthereumApiService } from '../ethereum';\nimport { EthereumApiConnection } from '../ethereum/api.connection';\nimport { DsProcessorService } from './ds-processor.service';\nimport { DynamicDsService } from './dynamic-ds.service';\nimport { IndexerManager } from './indexer.manager';\nimport { ProjectService } from './project.service';\nimport { SandboxService } from './sandbox.service';\nimport { UnfinalizedBlocksService } from './unfinalizedBlocks.service';\nimport { WorkerService } from './worker/worker.service';\nimport { WorkerUnfinalizedBlocksService } from './worker/worker.unfinalizedBlocks.service';\n\n@Module({\n providers: [\n IndexerManager,\n {\n provide: ConnectionPoolStateManager,\n useFactory: () =>\n new WorkerConnectionPoolStateManager((global as any).host),\n },\n ConnectionPoolService,\n {\n provide: ApiService,\n useFactory: async (\n project: SubqueryProject,\n connectionPoolService: ConnectionPoolService<EthereumApiConnection>,\n eventEmitter: EventEmitter2,\n nodeConfig: NodeConfig,\n ) => {\n const apiService = new EthereumApiService(\n project,\n connectionPoolService,\n eventEmitter,\n nodeConfig,\n );\n await apiService.init();\n return apiService;\n },\n inject: [\n 'ISubqueryProject',\n ConnectionPoolService,\n EventEmitter2,\n NodeConfig,\n ],\n },\n SandboxService,\n DsProcessorService,\n {\n provide: DynamicDsService,\n useFactory: () => new WorkerDynamicDsService((global as any).host),\n },\n {\n provide: 'IProjectService',\n useClass: ProjectService,\n },\n {\n provide: UnfinalizedBlocksService,\n useFactory: () =>\n new WorkerUnfinalizedBlocksService((global as any).host),\n },\n WorkerService,\n {\n provide: InMemoryCacheService,\n useFactory: () => new WorkerInMemoryCacheService((global as any).host),\n },\n ],\n})\nexport class WorkerFetchModule {}\n"]}
|
|
@@ -26,10 +26,12 @@ let TestingFeatureModule = class TestingFeatureModule {
|
|
|
26
26
|
TestingFeatureModule = __decorate([
|
|
27
27
|
(0, common_1.Module)({
|
|
28
28
|
providers: [
|
|
29
|
+
node_core_1.InMemoryCacheService,
|
|
29
30
|
node_core_1.StoreService,
|
|
30
31
|
node_core_1.StoreCacheService,
|
|
31
32
|
event_emitter_1.EventEmitter2,
|
|
32
33
|
node_core_1.PoiService,
|
|
34
|
+
node_core_1.PoiSyncService,
|
|
33
35
|
sandbox_service_1.SandboxService,
|
|
34
36
|
ds_processor_service_1.DsProcessorService,
|
|
35
37
|
dynamic_ds_service_1.DynamicDsService,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.module.js","sourceRoot":"","sources":["../../src/subcommands/testing.module.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;AAEnC,2CAAwC;AACxC,yDAA0E;AAC1E,+CAAqE;AACrE,
|
|
1
|
+
{"version":3,"file":"testing.module.js","sourceRoot":"","sources":["../../src/subcommands/testing.module.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;AAEnC,2CAAwC;AACxC,yDAA0E;AAC1E,+CAAqE;AACrE,gDAY0B;AAC1B,oEAAgE;AAEhE,0CAAiD;AAEjD,0EAAqE;AACrE,sEAAiE;AACjE,gEAA4D;AAC5D,gEAA4D;AAC5D,gEAA4D;AAC5D,oFAAgF;AA0DzE,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;CAAG,CAAA;AAAvB,oBAAoB;IAxDhC,IAAA,eAAM,EAAC;QACN,SAAS,EAAE;YACT,gCAAoB;YACpB,wBAAY;YACZ,6BAAiB;YACjB,6BAAa;YACb,sBAAU;YACV,0BAAc;YACd,gCAAc;YACd,yCAAkB;YAClB,qCAAgB;YAChB,oDAAwB;YACxB,sCAA0B;YAC1B,iCAAqB;YACrB;gBACE,OAAO,EAAE,iBAAiB;gBAC1B,QAAQ,EAAE,gCAAc;aACzB;YACD;gBACE,OAAO,EAAE,sBAAU;gBACnB,UAAU,EAAE,KAAK,EACf,OAAwB,EACxB,qBAAmE,EACnE,YAA2B,EAC3B,UAAsB,EACtB,EAAE;oBACF,MAAM,UAAU,GAAG,IAAI,6BAAkB,CACvC,OAAO,EACP,qBAAqB,EACrB,YAAY,EACZ,UAAU,CACX,CAAC;oBACF,MAAM,UAAU,CAAC,IAAI,EAAE,CAAC;oBACxB,OAAO,UAAU,CAAC;gBACpB,CAAC;gBACD,MAAM,EAAE;oBACN,kBAAkB;oBAClB,iCAAqB;oBACrB,6BAAa;oBACb,sBAAU;iBACX;aACF;YACD,4BAAiB;YACjB,sBAAU;YACV;gBACE,OAAO,EAAE,MAAM;gBACf,WAAW,EAAE,sBAAU;aACxB;YACD;gBACE,OAAO,EAAE,iBAAiB;gBAC1B,QAAQ,EAAE,gCAAc;aACzB;SACF;QACD,WAAW,EAAE,EAAE;QACf,OAAO,EAAE,CAAC,sBAAU,CAAC;KACtB,CAAC;GACW,oBAAoB,CAAG;AAAvB,oDAAoB;AAY1B,IAAM,aAAa,GAAnB,MAAM,aAAa;CAAG,CAAA;AAAhB,aAAa;IAVzB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,oBAAQ,CAAC,OAAO,EAAE;YAClB,kCAAe,CAAC,QAAQ,EAAE;YAC1B,kCAAkB,CAAC,OAAO,EAAE;YAC5B,yBAAc,CAAC,OAAO,EAAE;YACxB,oBAAoB;SACrB;QACD,WAAW,EAAE,EAAE;KAChB,CAAC;GACW,aAAa,CAAG;AAAhB,sCAAa","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Module } from '@nestjs/common';\nimport { EventEmitter2, EventEmitterModule } from '@nestjs/event-emitter';\nimport { ScheduleModule, SchedulerRegistry } from '@nestjs/schedule';\nimport {\n ApiService,\n ConnectionPoolService,\n ConnectionPoolStateManager,\n DbModule,\n InMemoryCacheService,\n NodeConfig,\n PoiService,\n PoiSyncService,\n StoreCacheService,\n StoreService,\n TestRunner,\n} from '@subql/node-core';\nimport { ConfigureModule } from '../configure/configure.module';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { EthereumApiService } from '../ethereum';\nimport { EthereumApiConnection } from '../ethereum/api.connection';\nimport { DsProcessorService } from '../indexer/ds-processor.service';\nimport { DynamicDsService } from '../indexer/dynamic-ds.service';\nimport { IndexerManager } from '../indexer/indexer.manager';\nimport { ProjectService } from '../indexer/project.service';\nimport { SandboxService } from '../indexer/sandbox.service';\nimport { UnfinalizedBlocksService } from '../indexer/unfinalizedBlocks.service';\n\n@Module({\n providers: [\n InMemoryCacheService,\n StoreService,\n StoreCacheService,\n EventEmitter2,\n PoiService,\n PoiSyncService,\n SandboxService,\n DsProcessorService,\n DynamicDsService,\n UnfinalizedBlocksService,\n ConnectionPoolStateManager,\n ConnectionPoolService,\n {\n provide: 'IProjectService',\n useClass: ProjectService,\n },\n {\n provide: ApiService,\n useFactory: async (\n project: SubqueryProject,\n connectionPoolService: ConnectionPoolService<EthereumApiConnection>,\n eventEmitter: EventEmitter2,\n nodeConfig: NodeConfig,\n ) => {\n const apiService = new EthereumApiService(\n project,\n connectionPoolService,\n eventEmitter,\n nodeConfig,\n );\n await apiService.init();\n return apiService;\n },\n inject: [\n 'ISubqueryProject',\n ConnectionPoolService,\n EventEmitter2,\n NodeConfig,\n ],\n },\n SchedulerRegistry,\n TestRunner,\n {\n provide: 'IApi',\n useExisting: ApiService,\n },\n {\n provide: 'IIndexerManager',\n useClass: IndexerManager,\n },\n ],\n controllers: [],\n exports: [TestRunner],\n})\nexport class TestingFeatureModule {}\n\n@Module({\n imports: [\n DbModule.forRoot(),\n ConfigureModule.register(),\n EventEmitterModule.forRoot(),\n ScheduleModule.forRoot(),\n TestingFeatureModule,\n ],\n controllers: [],\n})\nexport class TestingModule {}\n"]}
|
package/dist/yargs.js
CHANGED
|
@@ -76,7 +76,7 @@ exports.yargsOptions = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv)
|
|
|
76
76
|
},
|
|
77
77
|
debug: {
|
|
78
78
|
demandOption: false,
|
|
79
|
-
describe: `Enable debug logging for specific scopes, this will override log-level. "*" will enable debug everywhere, or comma separated strings for specific scopes. e.g. "SQL,dictionary"`,
|
|
79
|
+
describe: `Enable debug logging for specific scopes, this will override log-level. "*" will enable debug everywhere, or comma separated strings for specific scopes. e.g. "SQL,dictionary". To disable specific scopes you can prefix them with '-'. e.g. "*,-SQL"`,
|
|
80
80
|
type: 'string',
|
|
81
81
|
},
|
|
82
82
|
'dictionary-resolver': {
|