mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-02-09 11:32:49 +00:00
82 lines
2.2 KiB
Handlebars
82 lines
2.2 KiB
Handlebars
|
//
|
||
|
// Copyright 2022 Vulcanize, Inc.
|
||
|
//
|
||
|
|
||
|
{{#if (subgraphPath)}}
|
||
|
import path from 'path';
|
||
|
{{/if}}
|
||
|
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 '@vulcanize/util';
|
||
|
{{#if (subgraphPath)}}
|
||
|
import { GraphWatcher, Database as GraphDatabase } from '@vulcanize/graph-node';
|
||
|
{{/if}}
|
||
|
|
||
|
import { Database } from '../database';
|
||
|
import { Indexer } from '../indexer';
|
||
|
|
||
|
const log = debug('vulcanize:index-block');
|
||
|
|
||
|
const main = async (): Promise<void> => {
|
||
|
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();
|
||
|
{{#if (subgraphPath)}}
|
||
|
|
||
|
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
|
||
|
await graphDb.init();
|
||
|
|
||
|
const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);
|
||
|
{{/if}}
|
||
|
|
||
|
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{{#if (subgraphPath)}}, graphWatcher{{/if}});
|
||
|
await indexer.init();
|
||
|
{{#if (subgraphPath)}}
|
||
|
|
||
|
graphWatcher.setIndexer(indexer);
|
||
|
await graphWatcher.init();
|
||
|
{{/if}}
|
||
|
|
||
|
await indexBlock(indexer, jobQueueConfig.eventsInBatch, argv);
|
||
|
|
||
|
await db.close();
|
||
|
};
|
||
|
|
||
|
main().catch(err => {
|
||
|
log(err);
|
||
|
}).finally(() => {
|
||
|
process.exit(0);
|
||
|
});
|