@subql/node-ethereum 6.3.4-1 → 6.4.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.
- package/CHANGELOG.md +9 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/ethereum/api.ethereum.js +2 -14
- package/dist/ethereum/api.ethereum.js.map +1 -1
- package/dist/ethereum/ethers/tron/tron-constants.d.ts +1 -0
- package/dist/ethereum/ethers/tron/tron-constants.js +8 -0
- package/dist/ethereum/ethers/tron/tron-constants.js.map +1 -0
- package/dist/indexer/unfinalizedBlocks.service.d.ts +4 -5
- package/dist/indexer/unfinalizedBlocks.service.js +6 -13
- package/dist/indexer/unfinalizedBlocks.service.js.map +1 -1
- package/package.json +4 -4
- package/dist/ethereum/ethers/tron/tron-provider.d.ts +0 -29
- package/dist/ethereum/ethers/tron/tron-provider.js +0 -55
- package/dist/ethereum/ethers/tron/tron-provider.js.map +0 -1
- package/dist/ethereum/ethers/tron/tron-utils.d.ts +0 -10
- package/dist/ethereum/ethers/tron/tron-utils.js +0 -38
- package/dist/ethereum/ethers/tron/tron-utils.js.map +0 -1
|
@@ -20,8 +20,7 @@ const celo_provider_1 = require("./ethers/celo/celo-provider");
|
|
|
20
20
|
const json_rpc_batch_provider_1 = require("./ethers/json-rpc-batch-provider");
|
|
21
21
|
const json_rpc_provider_1 = require("./ethers/json-rpc-provider");
|
|
22
22
|
const op_provider_1 = require("./ethers/op/op-provider");
|
|
23
|
-
const
|
|
24
|
-
const tron_utils_1 = require("./ethers/tron/tron-utils");
|
|
23
|
+
const tron_constants_1 = require("./ethers/tron/tron-constants");
|
|
25
24
|
const safe_api_1 = __importDefault(require("./safe-api"));
|
|
26
25
|
const utils_ethereum_1 = require("./utils.ethereum");
|
|
27
26
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
@@ -141,17 +140,6 @@ class EthereumApi {
|
|
|
141
140
|
this.applyBatchSize(this.config?.batchSize);
|
|
142
141
|
}
|
|
143
142
|
}
|
|
144
|
-
//tron
|
|
145
|
-
if (tron_utils_1.TRON_CHAIN_IDS.includes(network.chainId)) {
|
|
146
|
-
if (this.client instanceof providers_1.WebSocketProvider) {
|
|
147
|
-
this.client = new tron_provider_1.TronWsProvider(this.client.connection.url, network);
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
this.client = new tron_provider_1.TronJsonRpcBatchProvider(this.client.connection, network);
|
|
151
|
-
this.nonBatchClient = new tron_provider_1.TronJsonRpcProvider(this.client.connection, network);
|
|
152
|
-
this.applyBatchSize(this.config?.batchSize);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
143
|
try {
|
|
156
144
|
const [genesisHash, supportsFinalization, supportsSafe] = await Promise.all([
|
|
157
145
|
this.fetchGenesisHash(network.chainId),
|
|
@@ -279,7 +267,7 @@ class EthereumApi {
|
|
|
279
267
|
// We only want to apply this fix for Tron networks
|
|
280
268
|
// Mainnet: 728126428, Shasta: 2494104990, Nile: 3448148188
|
|
281
269
|
if (this.chainId &&
|
|
282
|
-
|
|
270
|
+
tron_constants_1.TRON_CHAIN_IDS.includes(this.chainId) &&
|
|
283
271
|
block.stateRoot === '0x') {
|
|
284
272
|
block.stateRoot =
|
|
285
273
|
'0x0000000000000000000000000000000000000000000000000000000000000000';
|
|
@@ -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,+DAIqC;AACrC,yDAA0D;AAE1D,0DAAyC;AACzC,qDAO0B;AAE1B,8DAA8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AC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAC5D,CAAyC,CAAC;YAE7C,WAAW,CAAC,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;AAtdD,kCAsdC","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 {\n TronJsonRpcBatchProvider,\n TronJsonRpcProvider,\n TronWsProvider,\n} from './ethers/tron/tron-provider';\nimport { TRON_CHAIN_IDS } from './ethers/tron/tron-utils';\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 //tron\n if (TRON_CHAIN_IDS.includes(network.chainId)) {\n if (this.client instanceof WebSocketProvider) {\n this.client = new TronWsProvider(this.client.connection.url, network);\n } else {\n this.client = new TronJsonRpcBatchProvider(\n this.client.connection,\n network,\n );\n this.nonBatchClient = new TronJsonRpcProvider(\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":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C;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;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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const TRON_CHAIN_IDS: number[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors
|
|
3
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.TRON_CHAIN_IDS = void 0;
|
|
6
|
+
// Tron chain IDs: Mainnet, Shasta testnet, Nile testnet
|
|
7
|
+
exports.TRON_CHAIN_IDS = [728126428, 2494104990, 3448148188];
|
|
8
|
+
//# sourceMappingURL=tron-constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tron-constants.js","sourceRoot":"","sources":["../../../../src/ethereum/ethers/tron/tron-constants.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,wDAAwD;AAC3C,QAAA,cAAc,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\n// Tron chain IDs: Mainnet, Shasta testnet, Nile testnet\nexport const TRON_CHAIN_IDS = [728126428, 2494104990, 3448148188];\n"]}
|
|
@@ -2,17 +2,16 @@ import { UnfinalizedBlocksService as BaseUnfinalizedBlocksService, Header, NodeC
|
|
|
2
2
|
import { BlockchainService } from '../blockchain.service';
|
|
3
3
|
import { BlockContent } from './types';
|
|
4
4
|
export declare class UnfinalizedBlocksService extends BaseUnfinalizedBlocksService<BlockContent> {
|
|
5
|
-
private supportsFinalization?;
|
|
6
5
|
private startupCheck;
|
|
7
6
|
constructor(nodeConfig: NodeConfig, storeModelProvider: IStoreModelProvider, blockchainService: BlockchainService);
|
|
8
7
|
/**
|
|
9
8
|
* @param reindex - the function to reindex back before a fork
|
|
10
|
-
* @param supportsFinalization - If the chain supports the 'finalized' block tag this should be true.
|
|
11
9
|
* */
|
|
12
|
-
init(reindex: (targetHeight: Header) => Promise<void
|
|
10
|
+
init(reindex: (targetHeight: Header) => Promise<void>): Promise<Header | undefined>;
|
|
13
11
|
/**
|
|
14
|
-
* Checks if a fork has happened
|
|
15
|
-
*
|
|
12
|
+
* Checks if a fork has happened during startup by verifying the last unfinalized block hash.
|
|
13
|
+
* Runtime fork detection is handled by node-core's registerUnfinalizedBlock which validates parentHash chain.
|
|
14
|
+
* @returns (Header | undefined) - The header if fork is detected at startup
|
|
16
15
|
* */
|
|
17
16
|
protected hasForked(): Promise<Header | undefined>;
|
|
18
17
|
/**
|
|
@@ -22,7 +22,6 @@ const blockchain_service_1 = require("../blockchain.service");
|
|
|
22
22
|
const NodeConfig_1 = require("../configure/NodeConfig");
|
|
23
23
|
const logger = (0, node_core_1.getLogger)('UnfinalizedBlocksService');
|
|
24
24
|
let UnfinalizedBlocksService = class UnfinalizedBlocksService extends node_core_1.UnfinalizedBlocksService {
|
|
25
|
-
supportsFinalization;
|
|
26
25
|
startupCheck = true;
|
|
27
26
|
constructor(nodeConfig, storeModelProvider, blockchainService) {
|
|
28
27
|
// blockchain service cast is due to unsolvable typescript generic error, it wokrs on the main sdk but not here
|
|
@@ -30,22 +29,18 @@ let UnfinalizedBlocksService = class UnfinalizedBlocksService extends node_core_
|
|
|
30
29
|
}
|
|
31
30
|
/**
|
|
32
31
|
* @param reindex - the function to reindex back before a fork
|
|
33
|
-
* @param supportsFinalization - If the chain supports the 'finalized' block tag this should be true.
|
|
34
32
|
* */
|
|
35
33
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
36
|
-
async init(reindex
|
|
37
|
-
this.supportsFinalization = supportsFinalisation;
|
|
34
|
+
async init(reindex) {
|
|
38
35
|
return super.init(reindex);
|
|
39
36
|
}
|
|
40
37
|
/**
|
|
41
|
-
* Checks if a fork has happened
|
|
42
|
-
*
|
|
38
|
+
* Checks if a fork has happened during startup by verifying the last unfinalized block hash.
|
|
39
|
+
* Runtime fork detection is handled by node-core's registerUnfinalizedBlock which validates parentHash chain.
|
|
40
|
+
* @returns (Header | undefined) - The header if fork is detected at startup
|
|
43
41
|
* */
|
|
44
42
|
async hasForked() {
|
|
45
|
-
|
|
46
|
-
return super.hasForked();
|
|
47
|
-
}
|
|
48
|
-
// Startup check helps speed up finding a fork by checking the hash of the last unfinalized block
|
|
43
|
+
// Startup check verifies the last unfinalized block hash against the chain
|
|
49
44
|
if (this.startupCheck) {
|
|
50
45
|
this.startupCheck = false;
|
|
51
46
|
const lastUnfinalized = (0, lodash_1.last)(this.unfinalizedBlocks);
|
|
@@ -62,6 +57,7 @@ let UnfinalizedBlocksService = class UnfinalizedBlocksService extends node_core_
|
|
|
62
57
|
const i = this.unfinalizedBlocks.length - 1;
|
|
63
58
|
const current = this.unfinalizedBlocks[i];
|
|
64
59
|
const parent = this.unfinalizedBlocks[i - 1];
|
|
60
|
+
// this now won't find fork as such cases has been covered when registerUnfinalizedBlock() is called
|
|
65
61
|
if (current.parentHash !== parent.blockHash) {
|
|
66
62
|
// We've found a fork now we need to find where the fork happened
|
|
67
63
|
logger.warn(`Block fork detected at ${current.blockHeight}. Parent hash ${current.parentHash} doesn't match indexed parent ${parent.blockHash}.`);
|
|
@@ -74,9 +70,6 @@ let UnfinalizedBlocksService = class UnfinalizedBlocksService extends node_core_
|
|
|
74
70
|
* @return (number | undefined) - The block height to rewind to to remove forked data
|
|
75
71
|
**/
|
|
76
72
|
async getLastCorrectFinalizedBlock(forkedHeader) {
|
|
77
|
-
if (this.supportsFinalization) {
|
|
78
|
-
return super.getLastCorrectFinalizedBlock(forkedHeader);
|
|
79
|
-
}
|
|
80
73
|
const bestVerifiableBlocks = this.unfinalizedBlocks.filter(({ blockHeight }) => blockHeight < forkedHeader.blockHeight);
|
|
81
74
|
let checkingHeader = forkedHeader;
|
|
82
75
|
// Work backwards through the blocks until we find a matching hash
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unfinalizedBlocks.service.js","sourceRoot":"","sources":["../../src/indexer/unfinalizedBlocks.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,2CAAoD;AACpD,gDAS0B;AAC1B,mCAA8B;AAC9B,8DAA0D;AAC1D,wDAA6D;AAG7D,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,0BAA0B,CAAC,CAAC;AAG9C,IAAM,wBAAwB,GAA9B,MAAM,wBAAyB,SAAQ,oCAA0C;IAC9E,
|
|
1
|
+
{"version":3,"file":"unfinalizedBlocks.service.js","sourceRoot":"","sources":["../../src/indexer/unfinalizedBlocks.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,2CAAoD;AACpD,gDAS0B;AAC1B,mCAA8B;AAC9B,8DAA0D;AAC1D,wDAA6D;AA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BAAiB,CAAC,kBAAkB,CAC9D,YAAY,CACb,CAAC;YACJ,CAAC;QACH,CAAC;QAED,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,cAAc,CAAC,CAAC;YACnE,OAAO,SAAS,CAAC;QACnB,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,IAAI,CAAC,CAAC,OAAO,KAAK,yCAA6B,EAAE,CAAC;gBAChD,OAAO,IAAI,CAAC,iBAAiB,CAAC,kBAAkB,CAC9C,IAAI,CAAC,GAAG,CACN,CAAC,EACD,YAAY,CAAC,WAAW;oBACrB,IAAI,CAAC,UAAiC,CAAC,gBAAgB,CAC3D,CACF,CAAC;YACJ,CAAC;YACD,gCAAgC;YAChC,MAAM,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;YACjD,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;CACF,CAAA;AAlIY,4DAAwB;AAgCnB;IADf,IAAA,oBAAQ,GAAE;;;;yDAqCV;mCApEU,wBAAwB;IADpC,IAAA,mBAAU,GAAE;IAMR,WAAA,IAAA,eAAM,EAAC,qBAAqB,CAAC,CAAA;IAC7B,WAAA,IAAA,eAAM,EAAC,oBAAoB,CAAC,CAAA;qCAFjB,sBAAU,UAE2B,sCAAiB;GANzD,wBAAwB,CAkIpC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport {\n UnfinalizedBlocksService as BaseUnfinalizedBlocksService,\n Header,\n NodeConfig,\n getLogger,\n profiler,\n POI_NOT_ENABLED_ERROR_MESSAGE,\n IStoreModelProvider,\n IBlockchainService,\n} from '@subql/node-core';\nimport { last } from 'lodash';\nimport { BlockchainService } from '../blockchain.service';\nimport { EthereumNodeConfig } from '../configure/NodeConfig';\nimport { BlockContent } from './types';\n\nconst logger = getLogger('UnfinalizedBlocksService');\n\n@Injectable()\nexport class UnfinalizedBlocksService extends BaseUnfinalizedBlocksService<BlockContent> {\n private startupCheck = true;\n\n constructor(\n nodeConfig: NodeConfig,\n @Inject('IStoreModelProvider') storeModelProvider: IStoreModelProvider,\n @Inject('IBlockchainService') blockchainService: BlockchainService,\n ) {\n // blockchain service cast is due to unsolvable typescript generic error, it wokrs on the main sdk but not here\n super(\n new EthereumNodeConfig(nodeConfig),\n storeModelProvider,\n blockchainService as IBlockchainService,\n );\n }\n\n /**\n * @param reindex - the function to reindex back before a fork\n * */\n // eslint-disable-next-line @typescript-eslint/require-await\n async init(\n reindex: (targetHeight: Header) => Promise<void>,\n ): Promise<Header | undefined> {\n return super.init(reindex);\n }\n\n /**\n * Checks if a fork has happened during startup by verifying the last unfinalized block hash.\n * Runtime fork detection is handled by node-core's registerUnfinalizedBlock which validates parentHash chain.\n * @returns (Header | undefined) - The header if fork is detected at startup\n * */\n @profiler()\n protected async hasForked(): Promise<Header | undefined> {\n // Startup check verifies the last unfinalized block hash against the chain\n if (this.startupCheck) {\n this.startupCheck = false;\n const lastUnfinalized = last(this.unfinalizedBlocks);\n if (lastUnfinalized) {\n const checkUnfinalized =\n await this.blockchainService.getHeaderForHeight(\n lastUnfinalized.blockHeight,\n );\n\n if (lastUnfinalized.blockHash !== checkUnfinalized.blockHash) {\n return checkUnfinalized;\n }\n }\n }\n\n if (this.unfinalizedBlocks.length <= 2) {\n return;\n }\n\n const i = this.unfinalizedBlocks.length - 1;\n const current = this.unfinalizedBlocks[i];\n const parent = this.unfinalizedBlocks[i - 1];\n\n // this now won't find fork as such cases has been covered when registerUnfinalizedBlock() is called\n if (current.parentHash !== parent.blockHash) {\n // We've found a fork now we need to find where the fork happened\n logger.warn(\n `Block fork detected at ${current.blockHeight}. Parent hash ${current.parentHash} doesn't match indexed parent ${parent.blockHash}.`,\n );\n\n return current;\n }\n\n return;\n }\n\n /**\n * Finds the height before the fork occurred based on the result of hasForked\n * @return (number | undefined) - The block height to rewind to to remove forked data\n **/\n protected async getLastCorrectFinalizedBlock(\n forkedHeader: Header,\n ): Promise<Header | undefined> {\n const bestVerifiableBlocks = this.unfinalizedBlocks.filter(\n ({ blockHeight }) => blockHeight < forkedHeader.blockHeight,\n );\n\n let checkingHeader = forkedHeader;\n\n // Work backwards through the blocks until we find a matching hash\n for (const header of bestVerifiableBlocks.reverse()) {\n if (\n header.blockHash === checkingHeader.blockHash ||\n header.blockHash === checkingHeader.parentHash\n ) {\n return header;\n }\n\n // Get the new parent\n if (!checkingHeader.parentHash) {\n throw new Error('Unable to get parent hash for header');\n }\n const parentHeight = checkingHeader.blockHeight - 1;\n try {\n checkingHeader = await this.blockchainService.getHeaderForHash(\n checkingHeader.parentHash,\n );\n } catch {\n // Parent block not found on chain (orphaned), fall back to height-based check\n logger.warn(\n `Failed to get block by hash, falling back to height-based check at height ${parentHeight}`,\n );\n checkingHeader = await this.blockchainService.getHeaderForHeight(\n parentHeight,\n );\n }\n }\n\n try {\n const poiHeader = await this.findFinalizedUsingPOI(checkingHeader);\n return poiHeader;\n } catch (e: any) {\n if (e.message === POI_NOT_ENABLED_ERROR_MESSAGE) {\n return this.blockchainService.getHeaderForHeight(\n Math.max(\n 0,\n forkedHeader.blockHeight -\n (this.nodeConfig as EthereumNodeConfig).blockForkReindex,\n ),\n );\n }\n // TODO rewind back 1000+ blocks\n logger.info('Failed to use POI to rewind block');\n throw e;\n }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@subql/node-ethereum",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Ian He",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
"@nestjs/schedule": "^5.0.1",
|
|
27
27
|
"@subql/common": "^5.8.2",
|
|
28
28
|
"@subql/common-ethereum": "4.10.1",
|
|
29
|
-
"@subql/node-core": "^19.
|
|
29
|
+
"@subql/node-core": "^19.2.0",
|
|
30
30
|
"@subql/testing": "^2.2.1",
|
|
31
31
|
"@subql/types-ethereum": "4.2.3",
|
|
32
32
|
"cacheable-lookup": "6",
|
|
33
33
|
"ethers": "^5.7.0",
|
|
34
34
|
"eventemitter2": "^6.4.5",
|
|
35
35
|
"json5": "^2.2.3",
|
|
36
|
-
"lodash": "^4.17.
|
|
36
|
+
"lodash": "^4.17.23",
|
|
37
37
|
"reflect-metadata": "^0.1.13",
|
|
38
38
|
"rimraf": "^3.0.2",
|
|
39
39
|
"yargs": "^16.2.0"
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"CHANGELOG.md",
|
|
71
71
|
"LICENSE"
|
|
72
72
|
],
|
|
73
|
-
"stableVersion": "6.
|
|
73
|
+
"stableVersion": "6.4.0"
|
|
74
74
|
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Networkish } from '@ethersproject/networks';
|
|
2
|
-
import { WebSocketProvider } from '@ethersproject/providers';
|
|
3
|
-
import { JsonRpcBatchProvider } from '../json-rpc-batch-provider';
|
|
4
|
-
import { JsonRpcProvider } from '../json-rpc-provider';
|
|
5
|
-
import { ConnectionInfo } from '../web';
|
|
6
|
-
/**
|
|
7
|
-
* Tron-specific JsonRpcProvider that applies parameter transformations
|
|
8
|
-
* to handle Tron RPC limitations.
|
|
9
|
-
*/
|
|
10
|
-
export declare class TronJsonRpcProvider extends JsonRpcProvider {
|
|
11
|
-
constructor(url: string | ConnectionInfo, network?: Networkish);
|
|
12
|
-
send(method: string, params: Array<any>): Promise<any>;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Tron-specific JsonRpcBatchProvider that applies parameter transformations
|
|
16
|
-
* to handle Tron RPC limitations.
|
|
17
|
-
*/
|
|
18
|
-
export declare class TronJsonRpcBatchProvider extends JsonRpcBatchProvider {
|
|
19
|
-
constructor(url: string | ConnectionInfo, network?: Networkish);
|
|
20
|
-
send(method: string, params: Array<any>): Promise<any>;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Tron-specific WebSocketProvider that applies parameter transformations
|
|
24
|
-
* to handle Tron RPC limitations.
|
|
25
|
-
*/
|
|
26
|
-
export declare class TronWsProvider extends WebSocketProvider {
|
|
27
|
-
constructor(url: string, network?: Networkish);
|
|
28
|
-
send(method: string, params: Array<any>): Promise<any>;
|
|
29
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors
|
|
3
|
-
// SPDX-License-Identifier: GPL-3.0
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.TronWsProvider = exports.TronJsonRpcBatchProvider = exports.TronJsonRpcProvider = void 0;
|
|
6
|
-
const providers_1 = require("@ethersproject/providers");
|
|
7
|
-
const json_rpc_batch_provider_1 = require("../json-rpc-batch-provider");
|
|
8
|
-
const json_rpc_provider_1 = require("../json-rpc-provider");
|
|
9
|
-
const tron_utils_1 = require("./tron-utils");
|
|
10
|
-
/**
|
|
11
|
-
* Tron-specific JsonRpcProvider that applies parameter transformations
|
|
12
|
-
* to handle Tron RPC limitations.
|
|
13
|
-
*/
|
|
14
|
-
class TronJsonRpcProvider extends json_rpc_provider_1.JsonRpcProvider {
|
|
15
|
-
constructor(url, network) {
|
|
16
|
-
super(url, network);
|
|
17
|
-
}
|
|
18
|
-
async send(method, params) {
|
|
19
|
-
const chainId = this.network?.chainId ?? 0;
|
|
20
|
-
const cleanedParams = (0, tron_utils_1.applyTronParamTransforms)(method, params, chainId);
|
|
21
|
-
return super.send(method, cleanedParams);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.TronJsonRpcProvider = TronJsonRpcProvider;
|
|
25
|
-
/**
|
|
26
|
-
* Tron-specific JsonRpcBatchProvider that applies parameter transformations
|
|
27
|
-
* to handle Tron RPC limitations.
|
|
28
|
-
*/
|
|
29
|
-
class TronJsonRpcBatchProvider extends json_rpc_batch_provider_1.JsonRpcBatchProvider {
|
|
30
|
-
constructor(url, network) {
|
|
31
|
-
super(url, network);
|
|
32
|
-
}
|
|
33
|
-
async send(method, params) {
|
|
34
|
-
const chainId = this.network?.chainId ?? 0;
|
|
35
|
-
const cleanedParams = (0, tron_utils_1.applyTronParamTransforms)(method, params, chainId);
|
|
36
|
-
return super.send(method, cleanedParams);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.TronJsonRpcBatchProvider = TronJsonRpcBatchProvider;
|
|
40
|
-
/**
|
|
41
|
-
* Tron-specific WebSocketProvider that applies parameter transformations
|
|
42
|
-
* to handle Tron RPC limitations.
|
|
43
|
-
*/
|
|
44
|
-
class TronWsProvider extends providers_1.WebSocketProvider {
|
|
45
|
-
constructor(url, network) {
|
|
46
|
-
super(url, network);
|
|
47
|
-
}
|
|
48
|
-
async send(method, params) {
|
|
49
|
-
const chainId = this.network?.chainId ?? 0;
|
|
50
|
-
const cleanedParams = (0, tron_utils_1.applyTronParamTransforms)(method, params, chainId);
|
|
51
|
-
return super.send(method, cleanedParams);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
exports.TronWsProvider = TronWsProvider;
|
|
55
|
-
//# sourceMappingURL=tron-provider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tron-provider.js","sourceRoot":"","sources":["../../../../src/ethereum/ethers/tron/tron-provider.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAGnC,wDAA6D;AAC7D,wEAAkE;AAClE,4DAAuD;AAEvD,6CAAwD;AAExD;;;GAGG;AACH,MAAa,mBAAoB,SAAQ,mCAAe;IACtD,YAAY,GAA4B,EAAE,OAAoB;QAC5D,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAAc,EAAE,MAAkB;QAC3C,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,OAAO,IAAI,CAAC,CAAC;QAC3C,MAAM,aAAa,GAAG,IAAA,qCAAwB,EAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACxE,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC3C,CAAC;CACF;AAVD,kDAUC;AAED;;;GAGG;AACH,MAAa,wBAAyB,SAAQ,8CAAoB;IAChE,YAAY,GAA4B,EAAE,OAAoB;QAC5D,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAAc,EAAE,MAAkB;QAC3C,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,OAAO,IAAI,CAAC,CAAC;QAC3C,MAAM,aAAa,GAAG,IAAA,qCAAwB,EAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACxE,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC3C,CAAC;CACF;AAVD,4DAUC;AAED;;;GAGG;AACH,MAAa,cAAe,SAAQ,6BAAiB;IACnD,YAAY,GAAW,EAAE,OAAoB;QAC3C,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAAc,EAAE,MAAkB;QAC3C,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,OAAO,IAAI,CAAC,CAAC;QAC3C,MAAM,aAAa,GAAG,IAAA,qCAAwB,EAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACxE,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC3C,CAAC;CACF;AAVD,wCAUC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Networkish } from '@ethersproject/networks';\nimport { WebSocketProvider } from '@ethersproject/providers';\nimport { JsonRpcBatchProvider } from '../json-rpc-batch-provider';\nimport { JsonRpcProvider } from '../json-rpc-provider';\nimport { ConnectionInfo } from '../web';\nimport { applyTronParamTransforms } from './tron-utils';\n\n/**\n * Tron-specific JsonRpcProvider that applies parameter transformations\n * to handle Tron RPC limitations.\n */\nexport class TronJsonRpcProvider extends JsonRpcProvider {\n constructor(url: string | ConnectionInfo, network?: Networkish) {\n super(url, network);\n }\n\n async send(method: string, params: Array<any>): Promise<any> {\n const chainId = this.network?.chainId ?? 0;\n const cleanedParams = applyTronParamTransforms(method, params, chainId);\n return super.send(method, cleanedParams);\n }\n}\n\n/**\n * Tron-specific JsonRpcBatchProvider that applies parameter transformations\n * to handle Tron RPC limitations.\n */\nexport class TronJsonRpcBatchProvider extends JsonRpcBatchProvider {\n constructor(url: string | ConnectionInfo, network?: Networkish) {\n super(url, network);\n }\n\n async send(method: string, params: Array<any>): Promise<any> {\n const chainId = this.network?.chainId ?? 0;\n const cleanedParams = applyTronParamTransforms(method, params, chainId);\n return super.send(method, cleanedParams);\n }\n}\n\n/**\n * Tron-specific WebSocketProvider that applies parameter transformations\n * to handle Tron RPC limitations.\n */\nexport class TronWsProvider extends WebSocketProvider {\n constructor(url: string, network?: Networkish) {\n super(url, network);\n }\n\n async send(method: string, params: Array<any>): Promise<any> {\n const chainId = this.network?.chainId ?? 0;\n const cleanedParams = applyTronParamTransforms(method, params, chainId);\n return super.send(method, cleanedParams);\n }\n}\n"]}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare const TRON_CHAIN_IDS: number[];
|
|
2
|
-
export declare const TRON_TRANSACTION_METHODS: string[];
|
|
3
|
-
/**
|
|
4
|
-
* Remove type and accessList from transaction objects in params for Tron chains
|
|
5
|
-
*/
|
|
6
|
-
export declare function cleanParamsForTron(params: Array<any>, chainId: number): Array<any>;
|
|
7
|
-
/**
|
|
8
|
-
* Apply all Tron-specific parameter transformations for the given method.
|
|
9
|
-
*/
|
|
10
|
-
export declare function applyTronParamTransforms(method: string, params: Array<any>, chainId: number): Array<any>;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors
|
|
3
|
-
// SPDX-License-Identifier: GPL-3.0
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.TRON_TRANSACTION_METHODS = exports.TRON_CHAIN_IDS = void 0;
|
|
6
|
-
exports.cleanParamsForTron = cleanParamsForTron;
|
|
7
|
-
exports.applyTronParamTransforms = applyTronParamTransforms;
|
|
8
|
-
// Tron chain IDs: Mainnet, Shasta testnet, Nile testnet
|
|
9
|
-
exports.TRON_CHAIN_IDS = [728126428, 2494104990, 3448148188];
|
|
10
|
-
// Methods that accept transaction objects as parameters
|
|
11
|
-
exports.TRON_TRANSACTION_METHODS = ['eth_call'];
|
|
12
|
-
/**
|
|
13
|
-
* Remove type and accessList from transaction objects in params for Tron chains
|
|
14
|
-
*/
|
|
15
|
-
function cleanParamsForTron(params, chainId) {
|
|
16
|
-
if (!exports.TRON_CHAIN_IDS.includes(chainId)) {
|
|
17
|
-
return params;
|
|
18
|
-
}
|
|
19
|
-
return params.map((param) => {
|
|
20
|
-
if (param && typeof param === 'object' && !Array.isArray(param)) {
|
|
21
|
-
const cleaned = { ...param };
|
|
22
|
-
delete cleaned.type;
|
|
23
|
-
delete cleaned.accessList;
|
|
24
|
-
return cleaned;
|
|
25
|
-
}
|
|
26
|
-
return param;
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Apply all Tron-specific parameter transformations for the given method.
|
|
31
|
-
*/
|
|
32
|
-
function applyTronParamTransforms(method, params, chainId) {
|
|
33
|
-
if (exports.TRON_TRANSACTION_METHODS.includes(method)) {
|
|
34
|
-
return cleanParamsForTron(params, chainId);
|
|
35
|
-
}
|
|
36
|
-
return params;
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=tron-utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tron-utils.js","sourceRoot":"","sources":["../../../../src/ethereum/ethers/tron/tron-utils.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAWnC,gDAiBC;AAKD,4DASC;AAxCD,wDAAwD;AAC3C,QAAA,cAAc,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;AAElE,wDAAwD;AAC3C,QAAA,wBAAwB,GAAG,CAAC,UAAU,CAAC,CAAC;AAErD;;GAEG;AACH,SAAgB,kBAAkB,CAChC,MAAkB,EAClB,OAAe;IAEf,IAAI,CAAC,sBAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QACtC,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAC1B,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAChE,MAAM,OAAO,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;YAC7B,OAAO,OAAO,CAAC,IAAI,CAAC;YACpB,OAAO,OAAO,CAAC,UAAU,CAAC;YAC1B,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,SAAgB,wBAAwB,CACtC,MAAc,EACd,MAAkB,EAClB,OAAe;IAEf,IAAI,gCAAwB,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9C,OAAO,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\n// Tron chain IDs: Mainnet, Shasta testnet, Nile testnet\nexport const TRON_CHAIN_IDS = [728126428, 2494104990, 3448148188];\n\n// Methods that accept transaction objects as parameters\nexport const TRON_TRANSACTION_METHODS = ['eth_call'];\n\n/**\n * Remove type and accessList from transaction objects in params for Tron chains\n */\nexport function cleanParamsForTron(\n params: Array<any>,\n chainId: number,\n): Array<any> {\n if (!TRON_CHAIN_IDS.includes(chainId)) {\n return params;\n }\n\n return params.map((param) => {\n if (param && typeof param === 'object' && !Array.isArray(param)) {\n const cleaned = { ...param };\n delete cleaned.type;\n delete cleaned.accessList;\n return cleaned;\n }\n return param;\n });\n}\n\n/**\n * Apply all Tron-specific parameter transformations for the given method.\n */\nexport function applyTronParamTransforms(\n method: string,\n params: Array<any>,\n chainId: number,\n): Array<any> {\n if (TRON_TRANSACTION_METHODS.includes(method)) {\n return cleanParamsForTron(params, chainId);\n }\n return params;\n}\n"]}
|