watcher-ts/packages/cli/src/reset/watcher.ts
Nabarun Gogoi 8547876764
Add isFEVM flag in config to avoid filtering event logs by topics (#454)
* Pass upstream config to indexer instance

* Add isFEVM flag and refactor watcher config fields

* Codegen changes for indexer

* Add missing getter in dummy indexer for graph-node tests
2023-11-07 12:07:49 +05:30

105 lines
2.2 KiB
TypeScript

//
// Copyright 2022 Vulcanize, Inc.
//
import debug from 'debug';
import 'reflect-metadata';
import assert from 'assert';
import { ConnectionOptions } from 'typeorm';
import { JsonRpcProvider } from '@ethersproject/providers';
import {
JobQueue,
DatabaseInterface,
IndexerInterface,
ServerConfig,
Clients,
GraphWatcherInterface,
Config,
UpstreamConfig
} from '@cerc-io/util';
import { BaseCmd } from '../base';
const log = debug('vulcanize:reset-watcher');
interface Arguments {
configFile: string;
blockNumber: number;
}
export class ResetWatcherCmd {
_argv?: Arguments;
_baseCmd: BaseCmd;
constructor () {
this._baseCmd = new BaseCmd();
}
get config (): Config {
return this._baseCmd.config;
}
get clients (): Clients {
return this._baseCmd.clients;
}
get ethProvider (): JsonRpcProvider {
return this._baseCmd.ethProvider;
}
get database (): DatabaseInterface {
return this._baseCmd.database;
}
async initConfig<ConfigType> (configFile: string): Promise<ConfigType> {
return this._baseCmd.initConfig(configFile);
}
async init (
argv: any,
Database: new (
config: ConnectionOptions,
serverConfig?: ServerConfig
) => DatabaseInterface,
clients: { [key: string]: any } = {}
): Promise<void> {
this._argv = argv;
await this.initConfig(argv.configFile);
await this._baseCmd.init(Database, clients);
}
async initIndexer (
Indexer: new (
config: {
server: ServerConfig;
upstream: UpstreamConfig;
},
db: DatabaseInterface,
clients: Clients,
ethProvider: JsonRpcProvider,
jobQueue: JobQueue,
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
graphWatcher?: GraphWatcherInterface
): Promise<void> {
return this._baseCmd.initIndexer(Indexer, graphWatcher);
}
async exec (): Promise<void> {
assert(this._argv);
const database = this._baseCmd.database;
const indexer = this._baseCmd.indexer;
assert(database);
assert(indexer);
await indexer.resetWatcherToBlock(this._argv.blockNumber);
await database.close();
log('Reset watcher successfully');
}
}