mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-01-15 00:48:20 +00:00
* 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
105 lines
2.2 KiB
TypeScript
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');
|
|
}
|
|
}
|