mirror of
https://github.com/cerc-io/watcher-ts
synced 2024-11-19 20:36:19 +00:00
Refactor create checkpoint CLI to cli package (#247)
* Refactor create checkpoint CLI to cli package * Update mock indexer
This commit is contained in:
parent
06e5c62fa8
commit
03050e5323
76
packages/cli/src/checkpoint/create.ts
Normal file
76
packages/cli/src/checkpoint/create.ts
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
//
|
||||||
|
// 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 { GraphWatcher } from '@cerc-io/graph-node';
|
||||||
|
import {
|
||||||
|
JobQueue,
|
||||||
|
DatabaseInterface,
|
||||||
|
IndexerInterface,
|
||||||
|
ServerConfig,
|
||||||
|
Clients
|
||||||
|
} from '@cerc-io/util';
|
||||||
|
|
||||||
|
import { BaseCmd } from '../base';
|
||||||
|
|
||||||
|
const log = debug('vulcanize:checkpoint-create');
|
||||||
|
|
||||||
|
interface Arguments {
|
||||||
|
configFile: string;
|
||||||
|
address: string;
|
||||||
|
blockHash: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CreateCheckpointCmd {
|
||||||
|
_argv?: Arguments
|
||||||
|
_baseCmd: BaseCmd
|
||||||
|
_database?: DatabaseInterface
|
||||||
|
_indexer?: IndexerInterface
|
||||||
|
|
||||||
|
constructor () {
|
||||||
|
this._baseCmd = new BaseCmd();
|
||||||
|
}
|
||||||
|
|
||||||
|
async initConfig<ConfigType> (configFile: string): Promise<ConfigType> {
|
||||||
|
return this._baseCmd.initConfig(configFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
async init (
|
||||||
|
argv: any,
|
||||||
|
Database: new (
|
||||||
|
config: ConnectionOptions,
|
||||||
|
serverConfig?: ServerConfig
|
||||||
|
) => DatabaseInterface,
|
||||||
|
Indexer: new (
|
||||||
|
serverConfig: ServerConfig,
|
||||||
|
db: DatabaseInterface,
|
||||||
|
clients: Clients,
|
||||||
|
ethProvider: JsonRpcProvider,
|
||||||
|
jobQueue: JobQueue,
|
||||||
|
graphWatcher?: GraphWatcher
|
||||||
|
) => IndexerInterface,
|
||||||
|
clients: { [key: string]: any } = {}
|
||||||
|
): Promise<void> {
|
||||||
|
this._argv = argv;
|
||||||
|
await this.initConfig(argv.configFile);
|
||||||
|
|
||||||
|
({ database: this._database, indexer: this._indexer } = await this._baseCmd.init(Database, Indexer, clients));
|
||||||
|
}
|
||||||
|
|
||||||
|
async exec (): Promise<void> {
|
||||||
|
assert(this._argv);
|
||||||
|
assert(this._database);
|
||||||
|
assert(this._indexer);
|
||||||
|
|
||||||
|
const blockHash = await this._indexer.processCLICheckpoint(this._argv.address, this._argv.blockHash);
|
||||||
|
|
||||||
|
await this._database.close();
|
||||||
|
log(`Created a checkpoint for contract ${this._argv.address} at block-hash ${blockHash}`);
|
||||||
|
}
|
||||||
|
}
|
@ -5,3 +5,4 @@
|
|||||||
export * from './watch-contract';
|
export * from './watch-contract';
|
||||||
export * from './reset/watcher';
|
export * from './reset/watcher';
|
||||||
export * from './reset/state';
|
export * from './reset/state';
|
||||||
|
export * from './checkpoint/create';
|
||||||
|
@ -64,9 +64,12 @@ export class ResetWatcherCmd {
|
|||||||
|
|
||||||
async exec (): Promise<void> {
|
async exec (): Promise<void> {
|
||||||
assert(this._argv);
|
assert(this._argv);
|
||||||
|
assert(this._database);
|
||||||
assert(this._indexer);
|
assert(this._indexer);
|
||||||
|
|
||||||
await this._indexer.resetWatcherToBlock(this._argv.blockNumber);
|
await this._indexer.resetWatcherToBlock(this._argv.blockNumber);
|
||||||
|
|
||||||
|
await this._database.close();
|
||||||
log('Reset watcher successfully');
|
log('Reset watcher successfully');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,11 @@
|
|||||||
// Copyright 2022 Vulcanize, Inc.
|
// Copyright 2022 Vulcanize, Inc.
|
||||||
//
|
//
|
||||||
|
|
||||||
import debug from 'debug';
|
import { CreateCheckpointCmd } from '@cerc-io/cli';
|
||||||
import assert from 'assert';
|
|
||||||
|
|
||||||
import { getConfig, initClients, JobQueue, Config } from '@cerc-io/util';
|
import { Database } from '../../database';
|
||||||
import { GraphWatcher, Database as GraphDatabase } from '@cerc-io/graph-node';
|
|
||||||
|
|
||||||
import { Database, ENTITY_TO_LATEST_ENTITY_MAP } from '../../database';
|
|
||||||
import { Indexer } from '../../indexer';
|
import { Indexer } from '../../indexer';
|
||||||
|
|
||||||
const log = debug('vulcanize:checkpoint-create');
|
|
||||||
|
|
||||||
export const command = 'create';
|
export const command = 'create';
|
||||||
|
|
||||||
export const desc = 'Create checkpoint';
|
export const desc = 'Create checkpoint';
|
||||||
@ -31,35 +25,8 @@ export const builder = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const handler = async (argv: any): Promise<void> => {
|
export const handler = async (argv: any): Promise<void> => {
|
||||||
const config: Config = await getConfig(argv.configFile);
|
const createCheckpointCmd = new CreateCheckpointCmd();
|
||||||
const { ethClient, ethProvider } = await initClients(config);
|
await createCheckpointCmd.init(argv, Database, Indexer);
|
||||||
|
|
||||||
const db = new Database(config.database);
|
await createCheckpointCmd.exec();
|
||||||
await db.init();
|
|
||||||
|
|
||||||
const graphDb = new GraphDatabase(config.server, db.baseDatabase, ENTITY_TO_LATEST_ENTITY_MAP);
|
|
||||||
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 });
|
|
||||||
await jobQueue.start();
|
|
||||||
|
|
||||||
const indexer = new Indexer(config.server, db, { ethClient }, ethProvider, jobQueue, graphWatcher);
|
|
||||||
await indexer.init();
|
|
||||||
|
|
||||||
graphWatcher.setIndexer(indexer);
|
|
||||||
await graphWatcher.init();
|
|
||||||
|
|
||||||
const blockHash = await indexer.processCLICheckpoint(argv.address, argv.blockHash);
|
|
||||||
|
|
||||||
log(`Created a checkpoint for contract ${argv.address} at block-hash ${blockHash}`);
|
|
||||||
|
|
||||||
await db.close();
|
|
||||||
};
|
};
|
||||||
|
@ -263,6 +263,11 @@ export class Indexer implements IndexerInterface {
|
|||||||
// TODO Implement
|
// TODO Implement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async processCLICheckpoint (contractAddress: string, blockHash?: string): Promise<string | undefined> {
|
||||||
|
// TODO Implement
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
getStateData (state: State): any {
|
getStateData (state: State): any {
|
||||||
return this._baseIndexer.getStateData(state);
|
return this._baseIndexer.getStateData(state);
|
||||||
}
|
}
|
||||||
|
@ -2,16 +2,11 @@
|
|||||||
// Copyright 2022 Vulcanize, Inc.
|
// Copyright 2022 Vulcanize, Inc.
|
||||||
//
|
//
|
||||||
|
|
||||||
import debug from 'debug';
|
import { CreateCheckpointCmd } from '@cerc-io/cli';
|
||||||
import assert from 'assert';
|
|
||||||
|
|
||||||
import { getConfig, initClients, JobQueue, Config } from '@cerc-io/util';
|
|
||||||
|
|
||||||
import { Database } from '../../database';
|
import { Database } from '../../database';
|
||||||
import { Indexer } from '../../indexer';
|
import { Indexer } from '../../indexer';
|
||||||
|
|
||||||
const log = debug('vulcanize:checkpoint-create');
|
|
||||||
|
|
||||||
export const command = 'create';
|
export const command = 'create';
|
||||||
|
|
||||||
export const desc = 'Create checkpoint';
|
export const desc = 'Create checkpoint';
|
||||||
@ -30,27 +25,8 @@ export const builder = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const handler = async (argv: any): Promise<void> => {
|
export const handler = async (argv: any): Promise<void> => {
|
||||||
const config: Config = await getConfig(argv.configFile);
|
const createCheckpointCmd = new CreateCheckpointCmd();
|
||||||
const { ethClient, ethProvider } = await initClients(config);
|
await createCheckpointCmd.init(argv, Database, Indexer);
|
||||||
|
|
||||||
const db = new Database(config.database);
|
await createCheckpointCmd.exec();
|
||||||
await db.init();
|
|
||||||
|
|
||||||
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 });
|
|
||||||
await jobQueue.start();
|
|
||||||
|
|
||||||
const indexer = new Indexer(config.server, db, { ethClient }, ethProvider, jobQueue);
|
|
||||||
await indexer.init();
|
|
||||||
|
|
||||||
const blockHash = await indexer.processCLICheckpoint(argv.address, argv.blockHash);
|
|
||||||
|
|
||||||
log(`Created a checkpoint for contract ${argv.address} at block-hash ${blockHash}`);
|
|
||||||
|
|
||||||
await db.close();
|
|
||||||
};
|
};
|
||||||
|
@ -200,6 +200,10 @@ export class Indexer implements IndexerInterface {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async processCLICheckpoint (contractAddress: string, blockHash?: string): Promise<string | undefined> {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
getStateData (state: StateInterface): any {
|
getStateData (state: StateInterface): any {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,11 @@
|
|||||||
// Copyright 2022 Vulcanize, Inc.
|
// Copyright 2022 Vulcanize, Inc.
|
||||||
//
|
//
|
||||||
|
|
||||||
import debug from 'debug';
|
import { CreateCheckpointCmd } from '@cerc-io/cli';
|
||||||
import assert from 'assert';
|
|
||||||
|
|
||||||
import { getConfig, initClients, JobQueue, Config } from '@cerc-io/util';
|
|
||||||
import { GraphWatcher, Database as GraphDatabase } from '@cerc-io/graph-node';
|
|
||||||
|
|
||||||
import { Database } from '../../database';
|
import { Database } from '../../database';
|
||||||
import { Indexer } from '../../indexer';
|
import { Indexer } from '../../indexer';
|
||||||
|
|
||||||
const log = debug('vulcanize:checkpoint-create');
|
|
||||||
|
|
||||||
export const command = 'create';
|
export const command = 'create';
|
||||||
|
|
||||||
export const desc = 'Create checkpoint';
|
export const desc = 'Create checkpoint';
|
||||||
@ -31,35 +25,8 @@ export const builder = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const handler = async (argv: any): Promise<void> => {
|
export const handler = async (argv: any): Promise<void> => {
|
||||||
const config: Config = await getConfig(argv.configFile);
|
const createCheckpointCmd = new CreateCheckpointCmd();
|
||||||
const { ethClient, ethProvider } = await initClients(config);
|
await createCheckpointCmd.init(argv, Database, Indexer);
|
||||||
|
|
||||||
const db = new Database(config.database);
|
await createCheckpointCmd.exec();
|
||||||
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 });
|
|
||||||
await jobQueue.start();
|
|
||||||
|
|
||||||
const indexer = new Indexer(config.server, db, { ethClient }, ethProvider, jobQueue, graphWatcher);
|
|
||||||
await indexer.init();
|
|
||||||
|
|
||||||
graphWatcher.setIndexer(indexer);
|
|
||||||
await graphWatcher.init();
|
|
||||||
|
|
||||||
const blockHash = await indexer.processCLICheckpoint(argv.address, argv.blockHash);
|
|
||||||
|
|
||||||
log(`Created a checkpoint for contract ${argv.address} at block-hash ${blockHash}`);
|
|
||||||
|
|
||||||
await db.close();
|
|
||||||
};
|
};
|
||||||
|
@ -2,16 +2,11 @@
|
|||||||
// Copyright 2022 Vulcanize, Inc.
|
// Copyright 2022 Vulcanize, Inc.
|
||||||
//
|
//
|
||||||
|
|
||||||
import debug from 'debug';
|
import { CreateCheckpointCmd } from '@cerc-io/cli';
|
||||||
import assert from 'assert';
|
|
||||||
|
|
||||||
import { getConfig, initClients, JobQueue, Config } from '@cerc-io/util';
|
|
||||||
|
|
||||||
import { Database } from '../../database';
|
import { Database } from '../../database';
|
||||||
import { Indexer } from '../../indexer';
|
import { Indexer } from '../../indexer';
|
||||||
|
|
||||||
const log = debug('vulcanize:checkpoint-create');
|
|
||||||
|
|
||||||
export const command = 'create';
|
export const command = 'create';
|
||||||
|
|
||||||
export const desc = 'Create checkpoint';
|
export const desc = 'Create checkpoint';
|
||||||
@ -30,27 +25,8 @@ export const builder = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const handler = async (argv: any): Promise<void> => {
|
export const handler = async (argv: any): Promise<void> => {
|
||||||
const config: Config = await getConfig(argv.configFile);
|
const createCheckpointCmd = new CreateCheckpointCmd();
|
||||||
const { ethClient, ethProvider } = await initClients(config);
|
await createCheckpointCmd.init(argv, Database, Indexer);
|
||||||
|
|
||||||
const db = new Database(config.database);
|
await createCheckpointCmd.exec();
|
||||||
await db.init();
|
|
||||||
|
|
||||||
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 });
|
|
||||||
await jobQueue.start();
|
|
||||||
|
|
||||||
const indexer = new Indexer(config.server, db, { ethClient }, ethProvider, jobQueue);
|
|
||||||
await indexer.init();
|
|
||||||
|
|
||||||
const blockHash = await indexer.processCLICheckpoint(argv.address, argv.blockHash);
|
|
||||||
|
|
||||||
log(`Created a checkpoint for contract ${argv.address} at block-hash ${blockHash}`);
|
|
||||||
|
|
||||||
await db.close();
|
|
||||||
};
|
};
|
||||||
|
@ -119,6 +119,7 @@ export interface IndexerInterface {
|
|||||||
processBlockAfterEvents?: (blockHash: string, blockNumber: number) => Promise<void>
|
processBlockAfterEvents?: (blockHash: string, blockNumber: number) => Promise<void>
|
||||||
processCanonicalBlock (blockHash: string, blockNumber: number): Promise<void>
|
processCanonicalBlock (blockHash: string, blockNumber: number): Promise<void>
|
||||||
processCheckpoint (blockHash: string): Promise<void>
|
processCheckpoint (blockHash: string): Promise<void>
|
||||||
|
processCLICheckpoint (contractAddress: string, blockHash?: string): Promise<string | undefined>
|
||||||
getStorageValue (storageLayout: StorageLayout, blockHash: string, contractAddress: string, variable: string, ...mappingKeys: MappingKey[]): Promise<ValueResult>
|
getStorageValue (storageLayout: StorageLayout, blockHash: string, contractAddress: string, variable: string, ...mappingKeys: MappingKey[]): Promise<ValueResult>
|
||||||
updateSubgraphState?: (contractAddress: string, data: any) => void
|
updateSubgraphState?: (contractAddress: string, data: any) => void
|
||||||
updateStateStatusMap (address: string, stateStatus: StateStatus): void
|
updateStateStatusMap (address: string, stateStatus: StateStatus): void
|
||||||
|
Loading…
Reference in New Issue
Block a user