mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-03-12 05:44:16 +00:00
* Move graph-database from graph-node to util * Refactor and remove graph-node dependency from cli package * Modify dependencies using depcheck * Implement CLI refactoring changes in other watchers * Review changes to remove eden comment and fix local import in util * Import GraphDatabase from util instead of graph-node * Move graph-node non assemblyscript code to util package * Implement CLI refactoring changes in codegen * Fix graph-node tests after refactoring * Move fromStateEntityValues to graph state utils
101 lines
2.1 KiB
TypeScript
101 lines
2.1 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
|
|
} 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 | undefined {
|
|
return this._baseCmd.config;
|
|
}
|
|
|
|
get clients (): Clients | undefined {
|
|
return this._baseCmd.clients;
|
|
}
|
|
|
|
get ethProvider (): JsonRpcProvider | undefined {
|
|
return this._baseCmd.ethProvider;
|
|
}
|
|
|
|
get database (): DatabaseInterface | undefined {
|
|
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 (
|
|
serverConfig: ServerConfig,
|
|
db: DatabaseInterface,
|
|
clients: Clients,
|
|
ethProvider: JsonRpcProvider,
|
|
jobQueue: JobQueue,
|
|
graphWatcher?: GraphWatcherInterface
|
|
) => IndexerInterface,
|
|
graphWatcher?: GraphWatcherInterface
|
|
) {
|
|
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');
|
|
}
|
|
}
|