@subql/node-ethereum 2.2.3-2 → 2.5.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.
@@ -54,18 +54,19 @@ let ConfigureModule = ConfigureModule_1 = class ConfigureModule {
54
54
  let config;
55
55
  let rawManifest;
56
56
  let reader;
57
+ const isTest = argv._[0] === 'test';
57
58
  // Override order : Sub-command/Args/Flags > Manifest Runner options > Default configs
58
59
  // Therefore, we should rebase the manifest runner options with args first but not the config in the end
59
60
  if (argv.config) {
60
61
  // get manifest options
61
- config = node_core_1.NodeConfig.fromFile(argv.config, yargsToIConfig(argv));
62
+ config = node_core_1.NodeConfig.fromFile(argv.config, yargsToIConfig(argv), isTest);
62
63
  reader = await common_2.ReaderFactory.create(config.subquery, {
63
64
  ipfs: config.ipfs,
64
65
  });
65
66
  rawManifest = await reader.getProjectSchema();
66
67
  (0, node_core_1.rebaseArgsWithManifest)(argv, rawManifest);
67
68
  // use rebased argv generate config to override current config
68
- config = node_core_1.NodeConfig.rebaseWithArgs(config, yargsToIConfig(argv));
69
+ config = node_core_1.NodeConfig.rebaseWithArgs(config, yargsToIConfig(argv), isTest);
69
70
  }
70
71
  else {
71
72
  if (!argv.subquery) {
@@ -81,7 +82,7 @@ let ConfigureModule = ConfigureModule_1 = class ConfigureModule {
81
82
  rawManifest = await reader.getProjectSchema();
82
83
  (0, node_core_1.rebaseArgsWithManifest)(argv, rawManifest);
83
84
  // Create new nodeConfig with rebased argv
84
- config = new node_core_1.NodeConfig((0, node_core_1.defaultSubqueryName)(yargsToIConfig(argv)));
85
+ config = new node_core_1.NodeConfig((0, node_core_1.defaultSubqueryName)(yargsToIConfig(argv)), isTest);
85
86
  }
86
87
  if (!(0, node_core_1.validDbSchemaName)(config.dbSchema)) {
87
88
  process.exit(1);
@@ -1 +1 @@
1
- {"version":3,"file":"configure.module.js","sourceRoot":"","sources":["../../src/configure/configure.module.ts"],"names":[],"mappings":";AAAA,gEAAgE;A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eAAe,CAmF3B;AAnFY,0CAAe","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport assert from 'assert';\nimport { DynamicModule, Global, Module } from '@nestjs/common';\nimport {\n handleCreateSubqueryProjectError,\n Reader,\n ReaderFactory,\n} from '@subql/common';\nimport { EthereumProjectNetworkConfig } from '@subql/common-ethereum';\nimport {\n IConfig,\n NodeConfig,\n getLogger,\n setLevel,\n rebaseArgsWithManifest,\n defaultSubqueryName,\n validDbSchemaName,\n} from '@subql/node-core';\nimport { camelCase, omitBy, isNil } from 'lodash';\nimport { yargsOptions } from '../yargs';\nimport { SubqueryProject } from './SubqueryProject';\n\nconst logger = getLogger('configure');\n\nconst YargsNameMapping: Record<string, string> = {};\n\ntype Args = typeof yargsOptions.argv['argv'];\n\nfunction yargsToIConfig(yargs: Args): Partial<IConfig> {\n return Object.entries(yargs).reduce((acc, [key, value]) => {\n if (['_', '$0'].includes(key)) return acc;\n\n if (key === 'network-registry') {\n try {\n value = JSON.parse(value as string);\n } catch (e) {\n throw new Error('Argument `network-registry` is not valid JSON');\n }\n }\n acc[YargsNameMapping[key] ?? camelCase(key)] = value;\n return acc;\n }, {} as any);\n}\n\nfunction warnDeprecations() {\n const { argv } = yargsOptions;\n if (argv['subquery-name']) {\n logger.warn(\n 'Note that argument --subquery-name has been deprecated in favour of --db-schema',\n );\n }\n if (argv.local) {\n logger.warn('Note that argument --local has been deprecated');\n }\n}\n\n@Global()\n@Module({})\nexport class ConfigureModule {\n static async register(): Promise<DynamicModule> {\n const { argv } = yargsOptions;\n let config: NodeConfig;\n let rawManifest: unknown;\n let reader: Reader;\n\n // Override order : Sub-command/Args/Flags > Manifest Runner options > Default configs\n // Therefore, we should rebase the manifest runner options with args first but not the config in the end\n if (argv.config) {\n // get manifest options\n config = NodeConfig.fromFile(argv.config, yargsToIConfig(argv));\n reader = await ReaderFactory.create(config.subquery, {\n ipfs: config.ipfs,\n });\n rawManifest = await reader.getProjectSchema();\n rebaseArgsWithManifest(argv, rawManifest);\n // use rebased argv generate config to override current config\n config = NodeConfig.rebaseWithArgs(config, yargsToIConfig(argv));\n } else {\n if (!argv.subquery) {\n logger.error(\n 'Subquery path is missing neither in cli options nor in config file',\n );\n yargsOptions.showHelp();\n process.exit(1);\n }\n\n warnDeprecations();\n assert(argv.subquery, 'subquery path is missing');\n reader = await ReaderFactory.create(argv.subquery, {\n ipfs: argv.ipfs,\n });\n rawManifest = await reader.getProjectSchema();\n rebaseArgsWithManifest(argv, rawManifest);\n // Create new nodeConfig with rebased argv\n config = new NodeConfig(defaultSubqueryName(yargsToIConfig(argv)));\n }\n\n if (!validDbSchemaName(config.dbSchema)) {\n process.exit(1);\n }\n\n if (config.debug) {\n setLevel('debug');\n }\n\n const project = async () => {\n const p = await SubqueryProject.create(\n argv.subquery,\n rawManifest,\n reader,\n omitBy<EthereumProjectNetworkConfig>(\n {\n endpoint: config.networkEndpoints,\n dictionary: config.networkDictionary,\n },\n isNil,\n ),\n config.root,\n ).catch((err) => {\n const pjson = require('../../package.json');\n handleCreateSubqueryProjectError(err, pjson, rawManifest, logger);\n process.exit(1);\n });\n return p;\n };\n\n return {\n module: ConfigureModule,\n providers: [\n {\n provide: NodeConfig,\n useValue: config,\n },\n {\n provide: 'ISubqueryProject',\n useFactory: project,\n },\n ],\n exports: [NodeConfig, 'ISubqueryProject'],\n };\n }\n}\n"]}
1
+ {"version":3,"file":"configure.module.js","sourceRoot":"","sources":["../../src/configure/configure.module.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;;;;;;;;AAEtC,oDAA4B;AAC5B,2CAA+D;AAC/D,0CAIuB;AAEvB,gDAQ0B;AAC1B,mCAAkD;AAClD,oCAAwC;AACxC,uDAAoD;AAEpD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,WAAW,CAAC,CAAC;AAEtC,MAAM,gBAAgB,GAA2B,EAAE,CAAC;AAIpD,SAAS,cAAc,CAA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AAE;YACvC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;QAED,IAAI,MAAM,CAAC,KAAK,EAAE;YAChB,IAAA,oBAAQ,EAAC,OAAO,CAAC,CAAC;SACnB;QAED,MAAM,OAAO,GAAG,KAAK,IAAI,EAAE;YACzB,MAAM,CAAC,GAAG,MAAM,iCAAe,CAAC,MAAM,CACpC,IAAI,CAAC,QAAQ,EACb,WAAW,EACX,MAAM,EACN,IAAA,eAAM,EACJ;gBACE,QAAQ,EAAE,MAAM,CAAC,gBAAgB;gBACjC,UAAU,EAAE,MAAM,CAAC,iBAAiB;aACrC,EACD,cAAK,CACN,EACD,MAAM,CAAC,IAAI,CACZ,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBACd,MAAM,KAAK,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;gBAC5C,IAAA,yCAAgC,EAAC,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;gBAClE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC,CAAC,CAAC;YACH,OAAO,CAAC,CAAC;QACX,CAAC,CAAC;QAEF,OAAO;YACL,MAAM,EAAE,iBAAe;YACvB,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,sBAAU;oBACnB,QAAQ,EAAE,MAAM;iBACjB;gBACD;oBACE,OAAO,EAAE,kBAAkB;oBAC3B,UAAU,EAAE,OAAO;iBACpB;aACF;YACD,OAAO,EAAE,CAAC,sBAAU,EAAE,kBAAkB,CAAC;SAC1C,CAAC;IACJ,CAAC;CACF,CAAA;AAxFY,eAAe;IAF3B,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,eAAe,CAwF3B;AAxFY,0CAAe","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport assert from 'assert';\nimport { DynamicModule, Global, Module } from '@nestjs/common';\nimport {\n handleCreateSubqueryProjectError,\n Reader,\n ReaderFactory,\n} from '@subql/common';\nimport { EthereumProjectNetworkConfig } from '@subql/common-ethereum';\nimport {\n IConfig,\n NodeConfig,\n getLogger,\n setLevel,\n rebaseArgsWithManifest,\n defaultSubqueryName,\n validDbSchemaName,\n} from '@subql/node-core';\nimport { camelCase, omitBy, isNil } from 'lodash';\nimport { yargsOptions } from '../yargs';\nimport { SubqueryProject } from './SubqueryProject';\n\nconst logger = getLogger('configure');\n\nconst YargsNameMapping: Record<string, string> = {};\n\ntype Args = typeof yargsOptions.argv['argv'];\n\nfunction yargsToIConfig(yargs: Args): Partial<IConfig> {\n return Object.entries(yargs).reduce((acc, [key, value]) => {\n if (['_', '$0'].includes(key)) return acc;\n\n if (key === 'network-registry') {\n try {\n value = JSON.parse(value as string);\n } catch (e) {\n throw new Error('Argument `network-registry` is not valid JSON');\n }\n }\n acc[YargsNameMapping[key] ?? camelCase(key)] = value;\n return acc;\n }, {} as any);\n}\n\nfunction warnDeprecations() {\n const { argv } = yargsOptions;\n if (argv['subquery-name']) {\n logger.warn(\n 'Note that argument --subquery-name has been deprecated in favour of --db-schema',\n );\n }\n if (argv.local) {\n logger.warn('Note that argument --local has been deprecated');\n }\n}\n\n@Global()\n@Module({})\nexport class ConfigureModule {\n static async register(): Promise<DynamicModule> {\n const { argv } = yargsOptions;\n let config: NodeConfig;\n let rawManifest: unknown;\n let reader: Reader;\n\n const isTest = argv._[0] === 'test';\n\n // Override order : Sub-command/Args/Flags > Manifest Runner options > Default configs\n // Therefore, we should rebase the manifest runner options with args first but not the config in the end\n if (argv.config) {\n // get manifest options\n config = NodeConfig.fromFile(argv.config, yargsToIConfig(argv), isTest);\n reader = await ReaderFactory.create(config.subquery, {\n ipfs: config.ipfs,\n });\n rawManifest = await reader.getProjectSchema();\n rebaseArgsWithManifest(argv, rawManifest);\n // use rebased argv generate config to override current config\n config = NodeConfig.rebaseWithArgs(config, yargsToIConfig(argv), isTest);\n } else {\n if (!argv.subquery) {\n logger.error(\n 'Subquery path is missing neither in cli options nor in config file',\n );\n yargsOptions.showHelp();\n process.exit(1);\n }\n\n warnDeprecations();\n assert(argv.subquery, 'subquery path is missing');\n reader = await ReaderFactory.create(argv.subquery, {\n ipfs: argv.ipfs,\n });\n rawManifest = await reader.getProjectSchema();\n rebaseArgsWithManifest(argv, rawManifest);\n // Create new nodeConfig with rebased argv\n config = new NodeConfig(\n defaultSubqueryName(yargsToIConfig(argv)),\n isTest,\n );\n }\n\n if (!validDbSchemaName(config.dbSchema)) {\n process.exit(1);\n }\n\n if (config.debug) {\n setLevel('debug');\n }\n\n const project = async () => {\n const p = await SubqueryProject.create(\n argv.subquery,\n rawManifest,\n reader,\n omitBy<EthereumProjectNetworkConfig>(\n {\n endpoint: config.networkEndpoints,\n dictionary: config.networkDictionary,\n },\n isNil,\n ),\n config.root,\n ).catch((err) => {\n const pjson = require('../../package.json');\n handleCreateSubqueryProjectError(err, pjson, rawManifest, logger);\n process.exit(1);\n });\n return p;\n };\n\n return {\n module: ConfigureModule,\n providers: [\n {\n provide: NodeConfig,\n useValue: config,\n },\n {\n provide: 'ISubqueryProject',\n useFactory: project,\n },\n ],\n exports: [NodeConfig, 'ISubqueryProject'],\n };\n }\n}\n"]}
@@ -255,6 +255,9 @@ class EthereumApi {
255
255
  const iface = this.buildInterface(ds.options.abi, assets);
256
256
  const func = iface.getFunction((0, utils_1.hexDataSlice)(transaction.input, 0, 4));
257
257
  const args = iface.decodeFunctionData(func, transaction.input);
258
+ transaction.logs =
259
+ transaction.logs &&
260
+ (await Promise.all(transaction.logs.map(async (log) => this.parseLog(log, ds))));
258
261
  return Object.assign(Object.assign({}, transaction), { args });
259
262
  }
260
263
  catch (e) {
@@ -1 +1 @@
1
- {"version":3,"file":"api.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/api.ethereum.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;AAEtC,4CAAoB;AACpB,gDAAwB;AACxB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CAAC,MAAM,YAAY,6BAAiB,EAAE;YAC5C,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;SAC7B;aAAM;YACL,MAAM,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;SACnD;IACH,CAAC;IAED,WAAW,CAAC,CAAQ;QAClB,IAAI,CAAC,CAAS,aAAT,CAAC,uBAAD,CAAC,CAAU,MAAM,MAAK,GAAG,EAAE;YAC9B,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5C,OAAO,IAAI,KAAK,CAAC,6BAA6B,QAAQ,EAAE,CAAC,CAAC;SAC3D;QAED,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AArSD,kCAqSC","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport fs from 'fs';\nimport http from 'http';\nimport https from 'https';\nimport { Interface } from '@ethersproject/abi';\nimport {\n Provider,\n Block,\n TransactionReceipt,\n} from '@ethersproject/abstract-provider';\nimport { WebSocketProvider } from '@ethersproject/providers';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { getLogger, timeout } from '@subql/node-core';\nimport {\n ApiWrapper,\n EthereumBlockWrapper,\n EthereumTransaction,\n EthereumResult,\n EthereumLog,\n SubqlRuntimeDatasource,\n} from '@subql/types-ethereum';\nimport CacheableLookup from 'cacheable-lookup';\nimport { hexDataSlice, hexValue } from 'ethers/lib/utils';\nimport { retryOnFailEth } from '../utils/project';\nimport { yargsOptions } from '../yargs';\nimport { EthereumBlockWrapped } from './block.ethereum';\nimport { JsonRpcBatchProvider } from './ethers/json-rpc-batch-provider';\nimport { JsonRpcProvider } from './ethers/json-rpc-provider';\nimport { ConnectionInfo } from './ethers/web';\nimport SafeEthProvider from './safe-api';\nimport {\n formatBlock,\n formatLog,\n formatReceipt,\n formatTransaction,\n} from './utils.ethereum';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../../package.json');\n\nconst logger = getLogger('api.ethereum');\n\nasync function loadAssets(\n ds: SubqlRuntimeDatasource,\n): Promise<Record<string, string>> {\n if (!ds.assets) {\n return {};\n }\n const res: Record<string, string> = {};\n\n for (const [name, { file }] of Object.entries(ds.assets)) {\n try {\n res[name] = await fs.promises.readFile(file, { encoding: 'utf8' });\n } catch (e) {\n throw new Error(`Failed to load datasource asset ${file}`);\n }\n }\n\n return res;\n}\n\nfunction getHttpAgents() {\n // By default Nodejs doesn't cache DNS lookups\n // https://httptoolkit.com/blog/configuring-nodejs-dns/\n const lookup = new CacheableLookup();\n\n const options: http.AgentOptions = {\n keepAlive: true,\n /*, maxSockets: 100*/\n };\n\n const httpAgent = new http.Agent(options);\n const httpsAgent = new https.Agent(options);\n\n lookup.install(httpAgent);\n lookup.install(httpsAgent);\n\n return {\n http: httpAgent,\n https: httpsAgent,\n };\n}\n\nexport class EthereumApi implements ApiWrapper<EthereumBlockWrapper> {\n private client: JsonRpcProvider;\n\n // This is used within the sandbox when HTTP is used\n private nonBatchClient?: JsonRpcProvider;\n private genesisBlock: Record<string, any>;\n private contractInterfaces: Record<string, Interface> = {};\n private chainId: number;\n private name: string;\n\n // Ethereum POS\n private supportsFinalization = true;\n private blockConfirmations = yargsOptions.argv['block-confirmations'];\n\n constructor(private endpoint: string, private eventEmitter: EventEmitter2) {\n const { hostname, protocol, searchParams } = new URL(endpoint);\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(`Api host: ${hostname}, method: ${protocolStr}`);\n if (protocolStr === 'https' || protocolStr === 'http') {\n const connection: ConnectionInfo = {\n url: this.endpoint.split('?')[0],\n headers: {\n 'User-Agent': `Subquery-Node ${packageVersion}`,\n },\n allowGzip: true,\n throttleLimit: 5,\n throttleSlotInterval: 1,\n agents: getHttpAgents(),\n };\n searchParams.forEach((value, name, searchParams) => {\n (connection.headers as any)[name] = value;\n });\n this.client = new JsonRpcBatchProvider(connection);\n this.nonBatchClient = new JsonRpcProvider(connection);\n } else if (protocolStr === 'ws' || protocolStr === 'wss') {\n this.client = new WebSocketProvider(this.endpoint);\n } else {\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n }\n\n async init(): Promise<void> {\n this.injectClient();\n const [genesisBlock, network, supportsFinalization] = await Promise.all([\n this.client.getBlock('earliest'),\n this.client.getNetwork(),\n this.getSupportsFinalization(),\n ]);\n this.genesisBlock = genesisBlock;\n this.supportsFinalization = supportsFinalization;\n this.chainId = network.chainId;\n this.name = network.name;\n }\n\n private async getSupportsFinalization(): Promise<boolean> {\n try {\n // We set the timeout here because theres a bug in ethers where it will never resolve\n // It was happening with arbitrum on a syncing node\n await timeout(this.client.getBlock('finalized'), 2);\n return true;\n } catch (e) {\n logger.info('Chain doesnt support finalized tag');\n return false;\n }\n }\n\n private injectClient(): void {\n const orig = this.client.send.bind(this.client);\n Object.defineProperty(this.client, 'send', {\n value: (...args) => {\n this.eventEmitter.emit('rpcCall');\n return orig(...args);\n },\n });\n }\n\n async getFinalizedBlock(): Promise<Block> {\n const height = this.supportsFinalization\n ? 'finalized'\n : (await this.getBestBlockHeight()) - this.blockConfirmations;\n return this.client.getBlock(height);\n }\n\n async getFinalizedBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlock()).number;\n }\n\n async getBestBlockHeight(): Promise<number> {\n const tag = this.supportsFinalization ? 'safe' : 'latest';\n return (await this.client.getBlock(tag)).number;\n }\n\n getRuntimeChain(): string {\n return this.name;\n }\n\n getChainId(): number {\n return this.chainId;\n }\n\n getGenesisHash(): string {\n return this.genesisBlock.hash;\n }\n\n getSpecName(): string {\n return 'ethereum';\n }\n\n async getBlockByHeightOrHash(heightOrHash: number | string): Promise<Block> {\n if (typeof heightOrHash === 'number') {\n heightOrHash = hexValue(heightOrHash);\n }\n return this.client.getBlock(heightOrHash);\n }\n\n private async getBlockPromise(num: number, includeTx = true): Promise<any> {\n const rawBlock = await this.client.send('eth_getBlockByNumber', [\n hexValue(num),\n includeTx,\n ]);\n\n if (!rawBlock) {\n throw new Error(`Failed to fetch block ${num}`);\n }\n\n const block = formatBlock(rawBlock);\n\n block.stateRoot = this.client.formatter.hash(block.stateRoot);\n\n return block;\n }\n\n async getTransactionReceipt(\n transactionHash: string | Promise<string>,\n ): Promise<TransactionReceipt> {\n return retryOnFailEth<TransactionReceipt>(\n this.client.getTransactionReceipt.bind(this.client, transactionHash),\n );\n }\n\n async fetchBlock(\n blockNumber: number,\n includeTx?: boolean,\n ): Promise<EthereumBlockWrapped> {\n try {\n const [block, logs] = await Promise.all([\n this.getBlockPromise(blockNumber, includeTx),\n this.client.getLogs({\n fromBlock: hexValue(blockNumber),\n toBlock: hexValue(blockNumber),\n }),\n ]);\n\n const ret = new EthereumBlockWrapped(\n block,\n includeTx\n ? block.transactions.map((tx) => ({\n ...formatTransaction(tx, block),\n // TODO memoise\n receipt: () =>\n this.getTransactionReceipt(tx.hash).then((r) =>\n formatReceipt(r, block),\n ),\n }))\n : [],\n logs.map((l) => formatLog(l, block)),\n );\n this.eventEmitter.emit('fetchBlock');\n return ret;\n } catch (e) {\n throw this.handleError(e);\n }\n }\n\n async fetchBlocks(bufferBlocks: number[]): Promise<EthereumBlockWrapper[]> {\n return Promise.all(\n bufferBlocks.map(async (num) => this.fetchBlock(num, true)),\n );\n }\n\n get api(): Provider {\n return this.client;\n }\n\n getSafeApi(blockHeight: number): SafeEthProvider {\n // We cannot use a batch http client because OnF don't support routing historical queries in batches to an archive nodes\n const client =\n this.client instanceof WebSocketProvider\n ? this.client\n : this.nonBatchClient;\n\n return new SafeEthProvider(client, blockHeight);\n }\n\n private buildInterface(\n abiName: string,\n assets: Record<string, string>,\n ): Interface | undefined {\n if (!assets[abiName]) {\n throw new Error(`ABI named \"${abiName}\" not referenced in assets`);\n }\n\n // This assumes that all datasources have a different abi name or they are the same abi\n if (!this.contractInterfaces[abiName]) {\n // Constructing the interface validates the ABI\n try {\n let abiObj = JSON.parse(assets[abiName]);\n\n /*\n * Allows parsing JSON artifacts as well as ABIs\n * https://trufflesuite.github.io/artifact-updates/background.html#what-are-artifacts\n */\n if (!Array.isArray(abiObj) && abiObj.abi) {\n abiObj = abiObj.abi;\n }\n\n this.contractInterfaces[abiName] = new Interface(abiObj);\n } catch (e) {\n logger.error(`Unable to parse ABI: ${e.message}`);\n throw new Error('ABI is invalid');\n }\n }\n\n return this.contractInterfaces[abiName];\n }\n\n async parseLog<T extends EthereumResult = EthereumResult>(\n log: EthereumLog,\n ds: SubqlRuntimeDatasource,\n ): Promise<EthereumLog<T> | EthereumLog> {\n try {\n if (!ds?.options?.abi) {\n logger.warn('No ABI provided for datasource');\n return log;\n }\n const iface = this.buildInterface(ds.options.abi, await loadAssets(ds));\n return {\n ...log,\n args: iface?.parseLog(log).args as T,\n };\n } catch (e) {\n logger.warn(`Failed to parse log data: ${e.message}`);\n return log;\n }\n }\n\n async parseTransaction<T extends EthereumResult = EthereumResult>(\n transaction: EthereumTransaction,\n ds: SubqlRuntimeDatasource,\n ): Promise<EthereumTransaction<T> | EthereumTransaction> {\n try {\n if (!ds?.options?.abi) {\n logger.warn('No ABI provided for datasource');\n return transaction;\n }\n const assets = await loadAssets(ds);\n const iface = this.buildInterface(ds.options.abi, assets);\n const func = iface.getFunction(hexDataSlice(transaction.input, 0, 4));\n const args = iface.decodeFunctionData(func, transaction.input) as T;\n return {\n ...transaction,\n args,\n };\n } catch (e) {\n logger.warn(`Failed to parse transaction data: ${e.message}`);\n return transaction;\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async connect(): Promise<void> {\n logger.error('Ethereum API connect is not implemented');\n throw new Error('Not implemented');\n }\n\n async disconnect(): Promise<void> {\n if (this.client instanceof WebSocketProvider) {\n await this.client.destroy();\n } else {\n logger.warn('Disconnect called on HTTP provider');\n }\n }\n\n handleError(e: Error): Error {\n if ((e as any)?.status === 429) {\n const { hostname } = new URL(this.endpoint);\n return new Error(`Rate Limited at endpoint: ${hostname}`);\n }\n\n return e;\n }\n}\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,CAAC,CAC5D,CAAC,CAAC;YAEL,uCACK,WAAW,KACd,IAAI,IACJ;SACH;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YAC9D,OAAO,WAAW,CAAC;SACpB;IACH,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,OAAO;QACX,MAAM,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;QACxD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,UAAU;QACd,IAAI,IAAI,CAAC,MAAM,YAAY,6BAAiB,EAAE;YAC5C,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;SAC7B;aAAM;YACL,MAAM,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;SACnD;IACH,CAAC;IAED,WAAW,CAAC,CAAQ;QAClB,IAAI,CAAC,CAAS,aAAT,CAAC,uBAAD,CAAC,CAAU,MAAM,MAAK,GAAG,EAAE;YAC9B,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5C,OAAO,IAAI,KAAK,CAAC,6BAA6B,QAAQ,EAAE,CAAC,CAAC;SAC3D;QAED,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AA5SD,kCA4SC","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport fs from 'fs';\nimport http from 'http';\nimport https from 'https';\nimport { Interface } from '@ethersproject/abi';\nimport {\n Provider,\n Block,\n TransactionReceipt,\n} from '@ethersproject/abstract-provider';\nimport { WebSocketProvider } from '@ethersproject/providers';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { getLogger, timeout } from '@subql/node-core';\nimport {\n ApiWrapper,\n EthereumBlockWrapper,\n EthereumTransaction,\n EthereumResult,\n EthereumLog,\n SubqlRuntimeDatasource,\n} from '@subql/types-ethereum';\nimport CacheableLookup from 'cacheable-lookup';\nimport { hexDataSlice, hexValue } from 'ethers/lib/utils';\nimport { retryOnFailEth } from '../utils/project';\nimport { yargsOptions } from '../yargs';\nimport { EthereumBlockWrapped } from './block.ethereum';\nimport { JsonRpcBatchProvider } from './ethers/json-rpc-batch-provider';\nimport { JsonRpcProvider } from './ethers/json-rpc-provider';\nimport { ConnectionInfo } from './ethers/web';\nimport SafeEthProvider from './safe-api';\nimport {\n formatBlock,\n formatLog,\n formatReceipt,\n formatTransaction,\n} from './utils.ethereum';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../../package.json');\n\nconst logger = getLogger('api.ethereum');\n\nasync function loadAssets(\n ds: SubqlRuntimeDatasource,\n): Promise<Record<string, string>> {\n if (!ds.assets) {\n return {};\n }\n const res: Record<string, string> = {};\n\n for (const [name, { file }] of Object.entries(ds.assets)) {\n try {\n res[name] = await fs.promises.readFile(file, { encoding: 'utf8' });\n } catch (e) {\n throw new Error(`Failed to load datasource asset ${file}`);\n }\n }\n\n return res;\n}\n\nfunction getHttpAgents() {\n // By default Nodejs doesn't cache DNS lookups\n // https://httptoolkit.com/blog/configuring-nodejs-dns/\n const lookup = new CacheableLookup();\n\n const options: http.AgentOptions = {\n keepAlive: true,\n /*, maxSockets: 100*/\n };\n\n const httpAgent = new http.Agent(options);\n const httpsAgent = new https.Agent(options);\n\n lookup.install(httpAgent);\n lookup.install(httpsAgent);\n\n return {\n http: httpAgent,\n https: httpsAgent,\n };\n}\n\nexport class EthereumApi implements ApiWrapper<EthereumBlockWrapper> {\n private client: JsonRpcProvider;\n\n // This is used within the sandbox when HTTP is used\n private nonBatchClient?: JsonRpcProvider;\n private genesisBlock: Record<string, any>;\n private contractInterfaces: Record<string, Interface> = {};\n private chainId: number;\n private name: string;\n\n // Ethereum POS\n private supportsFinalization = true;\n private blockConfirmations = yargsOptions.argv['block-confirmations'];\n\n constructor(private endpoint: string, private eventEmitter: EventEmitter2) {\n const { hostname, protocol, searchParams } = new URL(endpoint);\n\n const protocolStr = protocol.replace(':', '');\n\n logger.info(`Api host: ${hostname}, method: ${protocolStr}`);\n if (protocolStr === 'https' || protocolStr === 'http') {\n const connection: ConnectionInfo = {\n url: this.endpoint.split('?')[0],\n headers: {\n 'User-Agent': `Subquery-Node ${packageVersion}`,\n },\n allowGzip: true,\n throttleLimit: 5,\n throttleSlotInterval: 1,\n agents: getHttpAgents(),\n };\n searchParams.forEach((value, name, searchParams) => {\n (connection.headers as any)[name] = value;\n });\n this.client = new JsonRpcBatchProvider(connection);\n this.nonBatchClient = new JsonRpcProvider(connection);\n } else if (protocolStr === 'ws' || protocolStr === 'wss') {\n this.client = new WebSocketProvider(this.endpoint);\n } else {\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n }\n\n async init(): Promise<void> {\n this.injectClient();\n const [genesisBlock, network, supportsFinalization] = await Promise.all([\n this.client.getBlock('earliest'),\n this.client.getNetwork(),\n this.getSupportsFinalization(),\n ]);\n this.genesisBlock = genesisBlock;\n this.supportsFinalization = supportsFinalization;\n this.chainId = network.chainId;\n this.name = network.name;\n }\n\n private async getSupportsFinalization(): Promise<boolean> {\n try {\n // We set the timeout here because theres a bug in ethers where it will never resolve\n // It was happening with arbitrum on a syncing node\n await timeout(this.client.getBlock('finalized'), 2);\n return true;\n } catch (e) {\n logger.info('Chain doesnt support finalized tag');\n return false;\n }\n }\n\n private injectClient(): void {\n const orig = this.client.send.bind(this.client);\n Object.defineProperty(this.client, 'send', {\n value: (...args) => {\n this.eventEmitter.emit('rpcCall');\n return orig(...args);\n },\n });\n }\n\n async getFinalizedBlock(): Promise<Block> {\n const height = this.supportsFinalization\n ? 'finalized'\n : (await this.getBestBlockHeight()) - this.blockConfirmations;\n return this.client.getBlock(height);\n }\n\n async getFinalizedBlockHeight(): Promise<number> {\n return (await this.getFinalizedBlock()).number;\n }\n\n async getBestBlockHeight(): Promise<number> {\n const tag = this.supportsFinalization ? 'safe' : 'latest';\n return (await this.client.getBlock(tag)).number;\n }\n\n getRuntimeChain(): string {\n return this.name;\n }\n\n getChainId(): number {\n return this.chainId;\n }\n\n getGenesisHash(): string {\n return this.genesisBlock.hash;\n }\n\n getSpecName(): string {\n return 'ethereum';\n }\n\n async getBlockByHeightOrHash(heightOrHash: number | string): Promise<Block> {\n if (typeof heightOrHash === 'number') {\n heightOrHash = hexValue(heightOrHash);\n }\n return this.client.getBlock(heightOrHash);\n }\n\n private async getBlockPromise(num: number, includeTx = true): Promise<any> {\n const rawBlock = await this.client.send('eth_getBlockByNumber', [\n hexValue(num),\n includeTx,\n ]);\n\n if (!rawBlock) {\n throw new Error(`Failed to fetch block ${num}`);\n }\n\n const block = formatBlock(rawBlock);\n\n block.stateRoot = this.client.formatter.hash(block.stateRoot);\n\n return block;\n }\n\n async getTransactionReceipt(\n transactionHash: string | Promise<string>,\n ): Promise<TransactionReceipt> {\n return retryOnFailEth<TransactionReceipt>(\n this.client.getTransactionReceipt.bind(this.client, transactionHash),\n );\n }\n\n async fetchBlock(\n blockNumber: number,\n includeTx?: boolean,\n ): Promise<EthereumBlockWrapped> {\n try {\n const [block, logs] = await Promise.all([\n this.getBlockPromise(blockNumber, includeTx),\n this.client.getLogs({\n fromBlock: hexValue(blockNumber),\n toBlock: hexValue(blockNumber),\n }),\n ]);\n\n const ret = new EthereumBlockWrapped(\n block,\n includeTx\n ? block.transactions.map((tx) => ({\n ...formatTransaction(tx, block),\n // TODO memoise\n receipt: () =>\n this.getTransactionReceipt(tx.hash).then((r) =>\n formatReceipt(r, block),\n ),\n }))\n : [],\n logs.map((l) => formatLog(l, block)),\n );\n this.eventEmitter.emit('fetchBlock');\n return ret;\n } catch (e) {\n throw this.handleError(e);\n }\n }\n\n async fetchBlocks(bufferBlocks: number[]): Promise<EthereumBlockWrapper[]> {\n return Promise.all(\n bufferBlocks.map(async (num) => this.fetchBlock(num, true)),\n );\n }\n\n get api(): Provider {\n return this.client;\n }\n\n getSafeApi(blockHeight: number): SafeEthProvider {\n // We cannot use a batch http client because OnF don't support routing historical queries in batches to an archive nodes\n const client =\n this.client instanceof WebSocketProvider\n ? this.client\n : this.nonBatchClient;\n\n return new SafeEthProvider(client, blockHeight);\n }\n\n private buildInterface(\n abiName: string,\n assets: Record<string, string>,\n ): Interface | undefined {\n if (!assets[abiName]) {\n throw new Error(`ABI named \"${abiName}\" not referenced in assets`);\n }\n\n // This assumes that all datasources have a different abi name or they are the same abi\n if (!this.contractInterfaces[abiName]) {\n // Constructing the interface validates the ABI\n try {\n let abiObj = JSON.parse(assets[abiName]);\n\n /*\n * Allows parsing JSON artifacts as well as ABIs\n * https://trufflesuite.github.io/artifact-updates/background.html#what-are-artifacts\n */\n if (!Array.isArray(abiObj) && abiObj.abi) {\n abiObj = abiObj.abi;\n }\n\n this.contractInterfaces[abiName] = new Interface(abiObj);\n } catch (e) {\n logger.error(`Unable to parse ABI: ${e.message}`);\n throw new Error('ABI is invalid');\n }\n }\n\n return this.contractInterfaces[abiName];\n }\n\n async parseLog<T extends EthereumResult = EthereumResult>(\n log: EthereumLog,\n ds: SubqlRuntimeDatasource,\n ): Promise<EthereumLog<T> | EthereumLog> {\n try {\n if (!ds?.options?.abi) {\n logger.warn('No ABI provided for datasource');\n return log;\n }\n const iface = this.buildInterface(ds.options.abi, await loadAssets(ds));\n return {\n ...log,\n args: iface?.parseLog(log).args as T,\n };\n } catch (e) {\n logger.warn(`Failed to parse log data: ${e.message}`);\n return log;\n }\n }\n\n async parseTransaction<T extends EthereumResult = EthereumResult>(\n transaction: EthereumTransaction,\n ds: SubqlRuntimeDatasource,\n ): Promise<EthereumTransaction<T> | EthereumTransaction> {\n try {\n if (!ds?.options?.abi) {\n logger.warn('No ABI provided for datasource');\n return transaction;\n }\n const assets = await loadAssets(ds);\n const iface = this.buildInterface(ds.options.abi, assets);\n const func = iface.getFunction(hexDataSlice(transaction.input, 0, 4));\n const args = iface.decodeFunctionData(func, transaction.input) as T;\n\n transaction.logs =\n transaction.logs &&\n (await Promise.all(\n transaction.logs.map(async (log) => this.parseLog(log, ds)),\n ));\n\n return {\n ...transaction,\n args,\n };\n } catch (e) {\n logger.warn(`Failed to parse transaction data: ${e.message}`);\n return transaction;\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async connect(): Promise<void> {\n logger.error('Ethereum API connect is not implemented');\n throw new Error('Not implemented');\n }\n\n async disconnect(): Promise<void> {\n if (this.client instanceof WebSocketProvider) {\n await this.client.destroy();\n } else {\n logger.warn('Disconnect called on HTTP provider');\n }\n }\n\n handleError(e: Error): Error {\n if ((e as any)?.status === 429) {\n const { hostname } = new URL(this.endpoint);\n return new Error(`Rate Limited at endpoint: ${hostname}`);\n }\n\n return e;\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ // Copyright 2020-2022 OnFinality Limited authors & contributors
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ const path_1 = __importDefault(require("path"));
9
+ const event_emitter_1 = require("@nestjs/event-emitter");
10
+ const types_ethereum_1 = require("@subql/types-ethereum");
11
+ const api_ethereum_1 = require("./api.ethereum");
12
+ // Add api key to work
13
+ const HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';
14
+ const ds = {
15
+ mapping: {
16
+ file: '',
17
+ handlers: [
18
+ {
19
+ handler: 'test',
20
+ kind: types_ethereum_1.EthereumHandlerKind.Call,
21
+ filter: { function: '0x23b872dd' },
22
+ },
23
+ ],
24
+ },
25
+ kind: types_ethereum_1.EthereumDatasourceKind.Runtime,
26
+ startBlock: 16258633,
27
+ options: { abi: 'erc721' },
28
+ assets: {
29
+ erc721: { file: path_1.default.join(__dirname, '../../test/erc721.json') },
30
+ },
31
+ };
32
+ jest.setTimeout(90000);
33
+ describe('Api.ethereum', () => {
34
+ let ethApi;
35
+ const eventEmitter = new event_emitter_1.EventEmitter2();
36
+ let blockData;
37
+ beforeAll(async () => {
38
+ ethApi = new api_ethereum_1.EthereumApi(HTTP_ENDPOINT, eventEmitter);
39
+ await ethApi.init();
40
+ blockData = await ethApi.fetchBlock(16258633, true);
41
+ });
42
+ it('Decode nested logs in transactions', async () => {
43
+ // Erc721
44
+ const tx = blockData.transactions.find((e) => e.hash ===
45
+ '0x8e419d0e36d7f9c099a001fded516bd168edd9d27b4aec2bcd56ba3b3b955ccc');
46
+ const parsedTx = await ethApi.parseTransaction(tx, ds);
47
+ expect(parsedTx.logs[0].args).toBeTruthy();
48
+ });
49
+ it('Should return raw logs, if decode fails', async () => {
50
+ // not Erc721
51
+ const tx = blockData.transactions.find((e) => e.hash ===
52
+ '0xed62f7a7720fe6ae05dec45ad9dd4f53034a0aae2c140d229b1151504ee9a6c9');
53
+ const parsedLog = await ethApi.parseLog(tx.logs[0], ds);
54
+ expect(parsedLog).not.toHaveProperty('args');
55
+ expect(parsedLog).toBeTruthy();
56
+ });
57
+ });
58
+ //# sourceMappingURL=api.ethereum.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.ethereum.test.js","sourceRoot":"","sources":["../../src/ethereum/api.ethereum.test.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;AAEtC,gDAAwB;AACxB,yDAAsD;AACtD,0DAI+B;AAC/B,iDAA6C;AAG7C,sBAAsB;AACtB,MAAM,aAAa,GAAG,sCAAsC,CAAC;AAE7D,MAAM,EAAE,GAA2B;IACjC,OAAO,EAAE;QACP,IAAI,EAAE,EAAE;QACR,QAAQ,EAAE;YACR;gBACE,OAAO,EAAE,MAAM;gBACf,IAAI,EAAE,oCAAmB,CAAC,IAAI;gBAC9B,MAAM,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE;aACnC;SACF;KACF;IACD,IAAI,EAAE,uCAAsB,CAAC,OAAO;IAC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ACvE,CAAC;QACF,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACxD,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAC7C,MAAM,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport path from 'path';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n EthereumDatasourceKind,\n EthereumHandlerKind,\n SubqlRuntimeDatasource,\n} from '@subql/types-ethereum';\nimport { EthereumApi } from './api.ethereum';\nimport { EthereumBlockWrapped } from './block.ethereum';\n\n// Add api key to work\nconst HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';\n\nconst ds: SubqlRuntimeDatasource = {\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'test',\n kind: EthereumHandlerKind.Call,\n filter: { function: '0x23b872dd' },\n },\n ],\n },\n kind: EthereumDatasourceKind.Runtime,\n startBlock: 16258633,\n options: { abi: 'erc721' },\n assets: {\n erc721: { file: path.join(__dirname, '../../test/erc721.json') },\n } as unknown as Map<string, { file: string }>,\n};\n\njest.setTimeout(90000);\ndescribe('Api.ethereum', () => {\n let ethApi: EthereumApi;\n const eventEmitter = new EventEmitter2();\n let blockData: EthereumBlockWrapped;\n beforeAll(async () => {\n ethApi = new EthereumApi(HTTP_ENDPOINT, eventEmitter);\n await ethApi.init();\n blockData = await ethApi.fetchBlock(16258633, true);\n });\n\n it('Decode nested logs in transactions', async () => {\n // Erc721\n const tx = blockData.transactions.find(\n (e) =>\n e.hash ===\n '0x8e419d0e36d7f9c099a001fded516bd168edd9d27b4aec2bcd56ba3b3b955ccc',\n );\n const parsedTx = await ethApi.parseTransaction(tx, ds);\n expect(parsedTx.logs[0].args).toBeTruthy();\n });\n\n it('Should return raw logs, if decode fails', async () => {\n // not Erc721\n const tx = blockData.transactions.find(\n (e) =>\n e.hash ===\n '0xed62f7a7720fe6ae05dec45ad9dd4f53034a0aae2c140d229b1151504ee9a6c9',\n );\n const parsedLog = await ethApi.parseLog(tx.logs[0], ds);\n expect(parsedLog).not.toHaveProperty('args');\n expect(parsedLog).toBeTruthy();\n });\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@subql/node-ethereum",
3
- "version": "2.2.3-2",
3
+ "version": "2.5.1-0",
4
4
  "description": "",
5
5
  "author": "Ian He",
6
6
  "license": "Apache-2.0",
@@ -25,11 +25,11 @@
25
25
  "@nestjs/platform-express": "^8.2.6",
26
26
  "@nestjs/schedule": "^1.0.2",
27
27
  "@subql/common": "^2.2.0",
28
- "@subql/common-ethereum": "2.1.1-1",
29
- "@subql/node-core": "^2.4.1",
28
+ "@subql/common-ethereum": "2.1.1",
29
+ "@subql/node-core": "^2.4.2",
30
30
  "@subql/testing": "^2.0.0",
31
31
  "@subql/types": "^2.1.2",
32
- "@subql/types-ethereum": "2.2.2-0",
32
+ "@subql/types-ethereum": "2.2.2",
33
33
  "@willsoto/nestjs-prometheus": "^4.4.0",
34
34
  "cacheable-lookup": "6",
35
35
  "cron-converter": "^1.0.2",
@@ -68,5 +68,5 @@
68
68
  "/dist",
69
69
  "/bin"
70
70
  ],
71
- "stableVersion": "2.2.3-1"
71
+ "stableVersion": "2.5.0"
72
72
  }