// // Copyright 2022 Vulcanize, Inc. // import yargs from 'yargs'; import 'reflect-metadata'; import debug from 'debug'; import assert from 'assert'; import { Config, DEFAULT_CONFIG_PATH, getConfig, initClients, JobQueue, indexBlock } from '@cerc-io/util'; import { GraphWatcher, Database as GraphDatabase } from '@cerc-io/graph-node'; import { Database } from '../database'; import { Indexer } from '../indexer'; const log = debug('vulcanize:index-block'); const main = async (): Promise => { const argv = await yargs.parserConfiguration({ 'parse-numbers': false }).options({ configFile: { alias: 'f', type: 'string', require: true, demandOption: true, describe: 'Configuration file path (toml)', default: DEFAULT_CONFIG_PATH }, block: { type: 'number', require: true, demandOption: true, describe: 'Block number to index' } }).argv; const config: Config = await getConfig(argv.configFile); const { ethClient, ethProvider } = await initClients(config); const db = new Database(config.database); await db.init(); const graphDb = new GraphDatabase(config.server, db.baseDatabase); await graphDb.init(); const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server); const jobQueueConfig = config.jobQueue; assert(jobQueueConfig, 'Missing job queue config'); const { dbConnectionString, maxCompletionLagInSecs } = jobQueueConfig; assert(dbConnectionString, 'Missing job queue db connection string'); const jobQueue = new JobQueue({ dbConnectionString, maxCompletionLag: maxCompletionLagInSecs }); const indexer = new Indexer(config.server, db, ethClient, ethProvider, jobQueue, graphWatcher); await indexer.init(); graphWatcher.setIndexer(indexer); await graphWatcher.init(); await indexBlock(indexer, jobQueueConfig.eventsInBatch, argv); await db.close(); }; main().catch(err => { log(err); }).finally(() => { process.exit(0); });