@subql/node-ethereum 6.4.0 → 6.4.1-0
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.
|
@@ -17,7 +17,9 @@ export declare class EthereumApi implements ApiWrapper {
|
|
|
17
17
|
private chainId?;
|
|
18
18
|
private name?;
|
|
19
19
|
private _supportsFinalization;
|
|
20
|
+
private _supportsSafe;
|
|
20
21
|
get supportsFinalization(): boolean;
|
|
22
|
+
get supportsSafe(): boolean;
|
|
21
23
|
/**
|
|
22
24
|
* @param {string} endpoint - The endpoint of the RPC provider
|
|
23
25
|
* @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.
|
|
@@ -71,11 +71,16 @@ class EthereumApi {
|
|
|
71
71
|
contractInterfaces = {};
|
|
72
72
|
chainId;
|
|
73
73
|
name;
|
|
74
|
-
// Ethereum POS
|
|
74
|
+
// Ethereum POS tag support
|
|
75
75
|
_supportsFinalization = true;
|
|
76
|
+
_supportsSafe = true;
|
|
76
77
|
get supportsFinalization() {
|
|
77
78
|
return this._supportsFinalization;
|
|
78
79
|
}
|
|
80
|
+
get supportsSafe() {
|
|
81
|
+
// Cronos (chainId 25) "safe" tag is hard-blocked due to unreliable behavior.
|
|
82
|
+
return this._supportsSafe && this.chainId !== 25;
|
|
83
|
+
}
|
|
79
84
|
/**
|
|
80
85
|
* @param {string} endpoint - The endpoint of the RPC provider
|
|
81
86
|
* @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.
|
|
@@ -147,7 +152,8 @@ class EthereumApi {
|
|
|
147
152
|
this.getSupportsTag('safe'),
|
|
148
153
|
]);
|
|
149
154
|
this._genesisHash = genesisHash;
|
|
150
|
-
this._supportsFinalization = supportsFinalization
|
|
155
|
+
this._supportsFinalization = supportsFinalization;
|
|
156
|
+
this._supportsSafe = supportsSafe;
|
|
151
157
|
this.chainId = network.chainId;
|
|
152
158
|
this.name = network.name;
|
|
153
159
|
}
|
|
@@ -225,12 +231,7 @@ class EthereumApi {
|
|
|
225
231
|
return (await this.getFinalizedBlock()).number;
|
|
226
232
|
}
|
|
227
233
|
async getBestBlockHeight() {
|
|
228
|
-
|
|
229
|
-
const tag = !this.unfinalizedBlocks &&
|
|
230
|
-
this.supportsFinalization &&
|
|
231
|
-
this.chainId !== 25
|
|
232
|
-
? 'safe'
|
|
233
|
-
: 'latest';
|
|
234
|
+
const tag = !this.unfinalizedBlocks && this.supportsSafe ? 'safe' : 'latest';
|
|
234
235
|
return (await this.client.getBlock(tag)).number;
|
|
235
236
|
}
|
|
236
237
|
getRuntimeChain() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/api.ethereum.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAEnC,oDAA4B;AAC5B,4CAAoB;AACpB,gDAAwB;AACxB,kDAA0B;AAC1B,4CAA+C;AAM/C,wDAA2E;AAE3E,gDAA8D;AAY9D,wEAA+C;AAC/C,4CAA0D;AAC1D,8CAAkD;AAClD,+DAIqC;AACrC,8EAAwE;AACxE,kEAA6D;AAC7D,yDAA2D;AAC3D,iEAA8D;AAE9D,0DAAyC;AACzC,qDAO0B;AAE1B,8DAA8D;AAC9D,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAElE,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,cAAc,CAAC,CAAC;AAEzC,KAAK,UAAU,UAAU,CACvB,EAA0B;IAE1B,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC;QACf,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,MAAM,GAAG,GAA2B,EAAE,CAAC;IAEvC,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,OA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5D,CAAC;QAED,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AArcD,kCAqcC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport assert from 'assert';\nimport fs from 'fs';\nimport http from 'http';\nimport https from 'https';\nimport { Interface } from '@ethersproject/abi';\nimport {\n BlockTag,\n Block,\n TransactionReceipt,\n} from '@ethersproject/abstract-provider';\nimport { WebSocketProvider, BaseProvider } from '@ethersproject/providers';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { getLogger, IBlock, timeout } from '@subql/node-core';\nimport {\n ApiWrapper,\n EthereumBlock,\n EthereumTransaction,\n EthereumResult,\n EthereumLog,\n SubqlRuntimeDatasource,\n LightEthereumBlock,\n LightEthereumLog,\n IEthereumEndpointConfig,\n} from '@subql/types-ethereum';\nimport CacheableLookup from 'cacheable-lookup';\nimport { hexDataSlice, hexValue } from 'ethers/lib/utils';\nimport { retryOnFailEth } from '../utils/project';\nimport {\n CeloJsonRpcBatchProvider,\n CeloJsonRpcProvider,\n CeloWsProvider,\n} from './ethers/celo/celo-provider';\nimport { JsonRpcBatchProvider } from './ethers/json-rpc-batch-provider';\nimport { JsonRpcProvider } from './ethers/json-rpc-provider';\nimport { OPFormatterMixin } from './ethers/op/op-provider';\nimport { TRON_CHAIN_IDS } from './ethers/tron/tron-constants';\nimport { ConnectionInfo } from './ethers/web';\nimport SafeEthProvider from './safe-api';\nimport {\n formatBlock,\n formatBlockUtil,\n formatLog,\n formatReceipt,\n formatTransaction,\n handleNumber,\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 ds.assets.entries()) {\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 _genesisHash = '';\n private contractInterfaces: Record<string, Interface> = {};\n private chainId?: number;\n private name?: string;\n\n // Ethereum POS\n private _supportsFinalization = true;\n\n get supportsFinalization(): boolean {\n return this._supportsFinalization;\n }\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 private unfinalizedBlocks = false,\n private config?: IEthereumEndpointConfig,\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,\n headers: {\n 'User-Agent': `Subquery-Node ${packageVersion}`,\n ...config?.headers,\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 (OPFormatterMixin(JsonRpcBatchProvider))(connection);\n this.nonBatchClient = new (OPFormatterMixin(JsonRpcProvider))(connection);\n this.applyBatchSize(config?.batchSize);\n } else if (protocolStr === 'ws' || protocolStr === 'wss') {\n this.client = new (OPFormatterMixin(WebSocketProvider))(this.endpoint);\n } else {\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n }\n\n private applyBatchSize(batchSize?: number): void {\n if (batchSize === null || batchSize === undefined) return;\n\n if (batchSize <= 0 && !!this.nonBatchClient) {\n logger.info('Endpoint config batch size is 0, not using batch requests');\n this.client = this.nonBatchClient;\n return;\n }\n (this.client as JsonRpcBatchProvider).setBatchSize(batchSize);\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, network);\n } else {\n this.client = new CeloJsonRpcBatchProvider(\n this.client.connection,\n network,\n );\n this.nonBatchClient = new CeloJsonRpcProvider(\n this.client.connection,\n network,\n );\n this.applyBatchSize(this.config?.batchSize);\n }\n }\n\n try {\n const [genesisHash, supportsFinalization, supportsSafe] =\n await Promise.all([\n this.fetchGenesisHash(network.chainId),\n this.getSupportsTag('finalized'),\n this.getSupportsTag('safe'),\n ]);\n\n this._genesisHash = genesisHash;\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 if (!this.nonBatchClient) {\n throw new Error('No suitable client found');\n }\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 there is a bug in ethers where it will never resolve\n // It was happening with arbitrum on a syncing node\n 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: (method: string, args: any[]) => {\n this.eventEmitter.emit('rpcCall');\n return orig(method, args);\n },\n });\n }\n\n private async fetchGenesisHash(chainId: number): Promise<string> {\n const tag = () => {\n switch (chainId) {\n // BEVM Canary\n case 1501:\n return 4157986;\n // Polkadot Hub mainnet - block 0x0 is not available via EVM RPC\n case 420420419:\n return 11405259;\n // Polkadot Hub testnet - block 0x0 is not available via EVM RPC\n case 420420417:\n return 4367914;\n default:\n return 'earliest';\n }\n };\n\n const block = await this.client.getBlock(tag());\n if (block === null) {\n logger.warn(\n `Unable to fetch genesis block for chainId ${chainId}. ` +\n `Using chainId as network identifier.`,\n );\n return '';\n }\n return block.hash;\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.unfinalizedBlocks &&\n this.supportsFinalization &&\n this.chainId !== 25\n ? 'safe'\n : 'latest';\n return (await this.client.getBlock(tag)).number;\n }\n\n getRuntimeChain(): string {\n assert(this.name, 'Api has not been initialised');\n return this.name;\n }\n\n getChainId(): number {\n assert(this.chainId, 'Api has not been initialised');\n return this.chainId;\n }\n\n getGenesisHash(): string {\n // Genesis hash is optional for EVM chains - chainId is the primary network identifier\n return this._genesisHash;\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 // Tron sometimes returns '0x' as stateRoot, which fails the formatter\n // We only want to apply this fix for Tron networks\n // Mainnet: 728126428, Shasta: 2494104990, Nile: 3448148188\n if (\n this.chainId &&\n TRON_CHAIN_IDS.includes(this.chainId) &&\n block.stateRoot === '0x'\n ) {\n block.stateRoot =\n '0x0000000000000000000000000000000000000000000000000000000000000000';\n } else {\n block.stateRoot = this.client.formatter.hash(block.stateRoot);\n }\n\n return block;\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<IBlock<EthereumBlock>> {\n try {\n const block = await this.getBlockPromise(blockNumber, true);\n const logsRaw = await this.client.getLogs({\n blockHash: block.hash,\n });\n\n // Certain RPC may not accommodate for blockHash, and would return wrong logs\n if (logsRaw.length) {\n logsRaw.forEach((l) => {\n if (l.blockHash.toLowerCase() !== block.hash.toLowerCase()) {\n throw new Error(\n `Log BlockHash does not match block: ${blockNumber}, blockHash ${\n block.hash\n }. Log ${handleNumber(\n l.logIndex,\n ).toNumber()} got block ${handleNumber(\n l.blockNumber,\n ).toNumber()} blockHash ${\n l.blockHash\n }. Please check with rpc provider`,\n );\n }\n });\n }\n\n block.logs = logsRaw.map((l) => formatLog(l, block));\n block.transactions = block.transactions.map((tx) => ({\n ...formatTransaction(tx, block),\n receipt: () =>\n this.getTransactionReceipt(tx.hash).then((r) => formatReceipt(r)),\n logs: block.logs.filter((l) => l.transactionHash === tx.hash),\n }));\n\n this.eventEmitter.emit('fetchBlock');\n return formatBlockUtil(block);\n } catch (e: any) {\n throw this.handleError(e);\n }\n }\n\n private async fetchLightBlock(\n blockNumber: number,\n ): Promise<IBlock<LightEthereumBlock>> {\n const block = await this.getBlockPromise(blockNumber, false);\n const logs = await this.client.getLogs({ blockHash: block.hash });\n\n const lightBlock: LightEthereumBlock = {\n ...block,\n logs: logs.map((l) => formatLog(l, block)),\n };\n return formatBlockUtil<LightEthereumBlock>(lightBlock);\n }\n\n async fetchBlocks(bufferBlocks: number[]): Promise<IBlock<EthereumBlock>[]> {\n return Promise.all(bufferBlocks.map(async (num) => this.fetchBlock(num)));\n }\n\n async fetchBlocksLight(\n bufferBlocks: number[],\n ): Promise<IBlock<LightEthereumBlock>[]> {\n return Promise.all(\n bufferBlocks.map(async (num) => this.fetchLightBlock(num)),\n );\n }\n\n get api(): BaseProvider {\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 assert(client, 'Unable to find client to make SafeApi');\n\n return new SafeEthProvider(client, blockHeight);\n }\n\n private buildInterface(\n abiName: string,\n assets: Record<string, string>,\n ): Interface {\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: any) {\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\n log.args = iface?.parseLog(log).args as T;\n\n return log;\n } catch (e: any) {\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 if (transaction.input !== '0x') {\n logger.warn('No ABI provided for datasource');\n }\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 transaction.args = args;\n return transaction;\n } catch (e: any) {\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":";AAA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AAC,IAAI,GAAG,IAAI,CAAC;YACxB,OAAO,WAAW,CAAC;QACrB,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,MAAM,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YAC9D,OAAO,WAAW,CAAC;QACrB,CAAC;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,CAAC;YAC7C,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAC9B,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;IAED,WAAW,CAAC,CAAQ;QAClB,IAAK,CAAS,EAAE,MAAM,KAAK,GAAG,EAAE,CAAC;YAC/B,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5C,OAAO,IAAI,KAAK,CAAC,6BAA6B,QAAQ,EAAE,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AAvcD,kCAucC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport assert from 'assert';\nimport fs from 'fs';\nimport http from 'http';\nimport https from 'https';\nimport { Interface } from '@ethersproject/abi';\nimport {\n BlockTag,\n Block,\n TransactionReceipt,\n} from '@ethersproject/abstract-provider';\nimport { WebSocketProvider, BaseProvider } from '@ethersproject/providers';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { getLogger, IBlock, timeout } from '@subql/node-core';\nimport {\n ApiWrapper,\n EthereumBlock,\n EthereumTransaction,\n EthereumResult,\n EthereumLog,\n SubqlRuntimeDatasource,\n LightEthereumBlock,\n LightEthereumLog,\n IEthereumEndpointConfig,\n} from '@subql/types-ethereum';\nimport CacheableLookup from 'cacheable-lookup';\nimport { hexDataSlice, hexValue } from 'ethers/lib/utils';\nimport { retryOnFailEth } from '../utils/project';\nimport {\n CeloJsonRpcBatchProvider,\n CeloJsonRpcProvider,\n CeloWsProvider,\n} from './ethers/celo/celo-provider';\nimport { JsonRpcBatchProvider } from './ethers/json-rpc-batch-provider';\nimport { JsonRpcProvider } from './ethers/json-rpc-provider';\nimport { OPFormatterMixin } from './ethers/op/op-provider';\nimport { TRON_CHAIN_IDS } from './ethers/tron/tron-constants';\nimport { ConnectionInfo } from './ethers/web';\nimport SafeEthProvider from './safe-api';\nimport {\n formatBlock,\n formatBlockUtil,\n formatLog,\n formatReceipt,\n formatTransaction,\n handleNumber,\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 ds.assets.entries()) {\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 _genesisHash = '';\n private contractInterfaces: Record<string, Interface> = {};\n private chainId?: number;\n private name?: string;\n\n // Ethereum POS tag support\n private _supportsFinalization = true;\n private _supportsSafe = true;\n\n get supportsFinalization(): boolean {\n return this._supportsFinalization;\n }\n\n get supportsSafe(): boolean {\n // Cronos (chainId 25) \"safe\" tag is hard-blocked due to unreliable behavior.\n return this._supportsSafe && this.chainId !== 25;\n }\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 private unfinalizedBlocks = false,\n private config?: IEthereumEndpointConfig,\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,\n headers: {\n 'User-Agent': `Subquery-Node ${packageVersion}`,\n ...config?.headers,\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 (OPFormatterMixin(JsonRpcBatchProvider))(connection);\n this.nonBatchClient = new (OPFormatterMixin(JsonRpcProvider))(connection);\n this.applyBatchSize(config?.batchSize);\n } else if (protocolStr === 'ws' || protocolStr === 'wss') {\n this.client = new (OPFormatterMixin(WebSocketProvider))(this.endpoint);\n } else {\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n }\n\n private applyBatchSize(batchSize?: number): void {\n if (batchSize === null || batchSize === undefined) return;\n\n if (batchSize <= 0 && !!this.nonBatchClient) {\n logger.info('Endpoint config batch size is 0, not using batch requests');\n this.client = this.nonBatchClient;\n return;\n }\n (this.client as JsonRpcBatchProvider).setBatchSize(batchSize);\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, network);\n } else {\n this.client = new CeloJsonRpcBatchProvider(\n this.client.connection,\n network,\n );\n this.nonBatchClient = new CeloJsonRpcProvider(\n this.client.connection,\n network,\n );\n this.applyBatchSize(this.config?.batchSize);\n }\n }\n\n try {\n const [genesisHash, supportsFinalization, supportsSafe] =\n await Promise.all([\n this.fetchGenesisHash(network.chainId),\n this.getSupportsTag('finalized'),\n this.getSupportsTag('safe'),\n ]);\n\n this._genesisHash = genesisHash;\n this._supportsFinalization = supportsFinalization;\n this._supportsSafe = supportsSafe;\n this.chainId = network.chainId;\n this.name = network.name;\n } catch (e) {\n if ((e as Error).message.startsWith('Invalid response')) {\n if (!this.nonBatchClient) {\n throw new Error('No suitable client found');\n }\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 there is a bug in ethers where it will never resolve\n // It was happening with arbitrum on a syncing node\n 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: (method: string, args: any[]) => {\n this.eventEmitter.emit('rpcCall');\n return orig(method, args);\n },\n });\n }\n\n private async fetchGenesisHash(chainId: number): Promise<string> {\n const tag = () => {\n switch (chainId) {\n // BEVM Canary\n case 1501:\n return 4157986;\n // Polkadot Hub mainnet - block 0x0 is not available via EVM RPC\n case 420420419:\n return 11405259;\n // Polkadot Hub testnet - block 0x0 is not available via EVM RPC\n case 420420417:\n return 4367914;\n default:\n return 'earliest';\n }\n };\n\n const block = await this.client.getBlock(tag());\n if (block === null) {\n logger.warn(\n `Unable to fetch genesis block for chainId ${chainId}. ` +\n `Using chainId as network identifier.`,\n );\n return '';\n }\n return block.hash;\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 =\n !this.unfinalizedBlocks && this.supportsSafe ? 'safe' : 'latest';\n return (await this.client.getBlock(tag)).number;\n }\n\n getRuntimeChain(): string {\n assert(this.name, 'Api has not been initialised');\n return this.name;\n }\n\n getChainId(): number {\n assert(this.chainId, 'Api has not been initialised');\n return this.chainId;\n }\n\n getGenesisHash(): string {\n // Genesis hash is optional for EVM chains - chainId is the primary network identifier\n return this._genesisHash;\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 // Tron sometimes returns '0x' as stateRoot, which fails the formatter\n // We only want to apply this fix for Tron networks\n // Mainnet: 728126428, Shasta: 2494104990, Nile: 3448148188\n if (\n this.chainId &&\n TRON_CHAIN_IDS.includes(this.chainId) &&\n block.stateRoot === '0x'\n ) {\n block.stateRoot =\n '0x0000000000000000000000000000000000000000000000000000000000000000';\n } else {\n block.stateRoot = this.client.formatter.hash(block.stateRoot);\n }\n\n return block;\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<IBlock<EthereumBlock>> {\n try {\n const block = await this.getBlockPromise(blockNumber, true);\n const logsRaw = await this.client.getLogs({\n blockHash: block.hash,\n });\n\n // Certain RPC may not accommodate for blockHash, and would return wrong logs\n if (logsRaw.length) {\n logsRaw.forEach((l) => {\n if (l.blockHash.toLowerCase() !== block.hash.toLowerCase()) {\n throw new Error(\n `Log BlockHash does not match block: ${blockNumber}, blockHash ${\n block.hash\n }. Log ${handleNumber(\n l.logIndex,\n ).toNumber()} got block ${handleNumber(\n l.blockNumber,\n ).toNumber()} blockHash ${\n l.blockHash\n }. Please check with rpc provider`,\n );\n }\n });\n }\n\n block.logs = logsRaw.map((l) => formatLog(l, block));\n block.transactions = block.transactions.map((tx) => ({\n ...formatTransaction(tx, block),\n receipt: () =>\n this.getTransactionReceipt(tx.hash).then((r) => formatReceipt(r)),\n logs: block.logs.filter((l) => l.transactionHash === tx.hash),\n }));\n\n this.eventEmitter.emit('fetchBlock');\n return formatBlockUtil(block);\n } catch (e: any) {\n throw this.handleError(e);\n }\n }\n\n private async fetchLightBlock(\n blockNumber: number,\n ): Promise<IBlock<LightEthereumBlock>> {\n const block = await this.getBlockPromise(blockNumber, false);\n const logs = await this.client.getLogs({ blockHash: block.hash });\n\n const lightBlock: LightEthereumBlock = {\n ...block,\n logs: logs.map((l) => formatLog(l, block)),\n };\n return formatBlockUtil<LightEthereumBlock>(lightBlock);\n }\n\n async fetchBlocks(bufferBlocks: number[]): Promise<IBlock<EthereumBlock>[]> {\n return Promise.all(bufferBlocks.map(async (num) => this.fetchBlock(num)));\n }\n\n async fetchBlocksLight(\n bufferBlocks: number[],\n ): Promise<IBlock<LightEthereumBlock>[]> {\n return Promise.all(\n bufferBlocks.map(async (num) => this.fetchLightBlock(num)),\n );\n }\n\n get api(): BaseProvider {\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 assert(client, 'Unable to find client to make SafeApi');\n\n return new SafeEthProvider(client, blockHeight);\n }\n\n private buildInterface(\n abiName: string,\n assets: Record<string, string>,\n ): Interface {\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: any) {\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\n log.args = iface?.parseLog(log).args as T;\n\n return log;\n } catch (e: any) {\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 if (transaction.input !== '0x') {\n logger.warn('No ABI provided for datasource');\n }\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 transaction.args = args;\n return transaction;\n } catch (e: any) {\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"]}
|