Refactor graph-node database and move to util (#259)

* 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
This commit is contained in:
2022-11-25 15:54:35 +05:30
committed by GitHub
parent 63a2c5804e
commit b66dcb4af9
105 changed files with 1120 additions and 428 deletions
+32 -42
View File
@@ -8,7 +8,6 @@ import { ConnectionOptions } from 'typeorm';
import { PubSub } from 'graphql-subscriptions';
import { JsonRpcProvider } from '@ethersproject/providers';
import { GraphWatcher, Database as GraphDatabase } from '@cerc-io/graph-node';
import {
Config,
getConfig,
@@ -17,9 +16,9 @@ import {
DatabaseInterface,
IndexerInterface,
ServerConfig,
Database as BaseDatabase,
Clients,
EventWatcherInterface
EventWatcherInterface,
GraphWatcherInterface
} from '@cerc-io/util';
import { EthClient } from '@cerc-io/ipld-eth-client';
@@ -30,13 +29,20 @@ export class BaseCmd {
_jobQueue?: JobQueue
_database?: DatabaseInterface;
_indexer?: IndexerInterface;
_graphDb?: GraphDatabase;
_eventWatcher?: EventWatcherInterface;
get config (): Config | undefined {
return this._config;
}
get clients (): Clients | undefined {
return this._clients;
}
get ethProvider (): JsonRpcProvider | undefined {
return this._ethProvider;
}
get jobQueue (): JobQueue | undefined {
return this._jobQueue;
}
@@ -45,10 +51,6 @@ export class BaseCmd {
return this._database;
}
get graphDb (): GraphDatabase | undefined {
return this._graphDb;
}
get indexer (): IndexerInterface | undefined {
return this._indexer;
}
@@ -70,17 +72,7 @@ export class BaseCmd {
config: ConnectionOptions,
serverConfig?: ServerConfig
) => DatabaseInterface,
Indexer: new (
serverConfig: ServerConfig,
db: DatabaseInterface,
clients: Clients,
ethProvider: JsonRpcProvider,
jobQueue: JobQueue,
graphWatcher?: GraphWatcher
) => IndexerInterface,
clients: { [key: string]: any } = {},
entityQueryTypeMap?: Map<any, any>,
entityToLatestEntityMap?: Map<any, any>
clients: { [key: string]: any } = {}
): Promise<void> {
assert(this._config);
@@ -99,18 +91,31 @@ export class BaseCmd {
const { ethClient, ethProvider } = await initClients(this._config);
this._ethProvider = ethProvider;
this._clients = { ethClient, ...clients };
}
// Check if subgraph watcher.
if (this._config.server.subgraphPath) {
const graphWatcher = await this._getGraphWatcher(this._database.baseDatabase, entityQueryTypeMap, entityToLatestEntityMap);
this._indexer = new Indexer(this._config.server, this._database, this._clients, ethProvider, this._jobQueue, graphWatcher);
await this._indexer.init();
async initIndexer (
Indexer: new (
serverConfig: ServerConfig,
db: DatabaseInterface,
clients: Clients,
ethProvider: JsonRpcProvider,
jobQueue: JobQueue,
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
graphWatcher?: GraphWatcherInterface
) {
assert(this._config);
assert(this._database);
assert(this._clients);
assert(this._ethProvider);
assert(this._jobQueue);
this._indexer = new Indexer(this._config.server, this._database, this._clients, this._ethProvider, this._jobQueue, graphWatcher);
await this._indexer.init();
if (graphWatcher) {
graphWatcher.setIndexer(this._indexer);
await graphWatcher.init();
} else {
this._indexer = new Indexer(this._config.server, this._database, this._clients, ethProvider, this._jobQueue);
await this._indexer.init();
}
}
@@ -131,19 +136,4 @@ export class BaseCmd {
const pubsub = new PubSub();
this._eventWatcher = new EventWatcher(this._clients.ethClient, this._indexer, pubsub, this._jobQueue);
}
async _getGraphWatcher (
baseDatabase: BaseDatabase,
entityQueryTypeMap?: Map<any, any>,
entityToLatestEntityMap?: Map<any, any>
): Promise<GraphWatcher> {
assert(this._config);
assert(this._clients?.ethClient);
assert(this._ethProvider);
this._graphDb = new GraphDatabase(this._config.server, baseDatabase, entityQueryTypeMap, entityToLatestEntityMap);
await this._graphDb.init();
return new GraphWatcher(this._graphDb, this._clients.ethClient, this._ethProvider, this._config.server);
}
}
+32 -9
View File
@@ -8,13 +8,14 @@ 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
Clients,
GraphWatcherInterface,
Config
} from '@cerc-io/util';
import { BaseCmd } from '../base';
@@ -35,6 +36,22 @@ export class CreateCheckpointCmd {
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);
}
@@ -45,20 +62,26 @@ export class CreateCheckpointCmd {
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?: GraphWatcher
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
clients: { [key: string]: any } = {}
): Promise<void> {
this._argv = argv;
await this.initConfig(argv.configFile);
await this._baseCmd.init(Database, Indexer, clients);
graphWatcher?: GraphWatcherInterface
) {
return this._baseCmd.initIndexer(Indexer, graphWatcher);
}
async exec (): Promise<void> {
+34 -13
View File
@@ -8,14 +8,16 @@ import assert from 'assert';
import { ConnectionOptions } from 'typeorm';
import { JsonRpcProvider } from '@ethersproject/providers';
import { GraphWatcher, Database as GraphDatabase } from '@cerc-io/graph-node';
import {
JobQueue,
DatabaseInterface,
IndexerInterface,
ServerConfig,
Clients,
verifyCheckpointData
verifyCheckpointData,
GraphDatabase,
GraphWatcherInterface,
Config
} from '@cerc-io/util';
import { BaseCmd } from '../base';
@@ -35,6 +37,22 @@ export class VerifyCheckpointCmd {
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);
}
@@ -45,23 +63,29 @@ export class VerifyCheckpointCmd {
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?: GraphWatcher
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
clients: { [key: string]: any } = {}
): Promise<void> {
this._argv = argv;
await this.initConfig(argv.configFile);
await this._baseCmd.init(Database, Indexer, clients);
graphWatcher?: GraphWatcherInterface
) {
return this._baseCmd.initIndexer(Indexer, graphWatcher);
}
async exec (): Promise<void> {
async exec (graphDb: GraphDatabase): Promise<void> {
assert(this._argv);
const database = this._baseCmd.database;
@@ -70,9 +94,6 @@ export class VerifyCheckpointCmd {
assert(database);
assert(indexer);
const graphDb: GraphDatabase | undefined = this._baseCmd.graphDb || database.graphDatabase;
assert(graphDb);
const state = await indexer.getStateByCID(this._argv.cid);
assert(state, 'State for the provided CID doesn\'t exist.');
const data = indexer.getStateData(state);
+31 -8
View File
@@ -11,7 +11,6 @@ import debug from 'debug';
import { ConnectionOptions } from 'typeorm';
import { JsonRpcProvider } from '@ethersproject/providers';
import { GraphWatcher } from '@cerc-io/graph-node';
import {
DEFAULT_CONFIG_PATH,
JobQueue,
@@ -19,7 +18,9 @@ import {
IndexerInterface,
ServerConfig,
StateKind,
Clients
Clients,
GraphWatcherInterface,
Config
} from '@cerc-io/util';
import * as codec from '@ipld/dag-cbor';
@@ -41,6 +42,22 @@ export class ExportStateCmd {
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> (): Promise<ConfigType> {
this._argv = this._getArgv();
assert(this._argv);
@@ -53,19 +70,25 @@ export class ExportStateCmd {
config: ConnectionOptions,
serverConfig?: ServerConfig
) => DatabaseInterface,
clients: { [key: string]: any } = {}
): Promise<void> {
await this.initConfig();
await this._baseCmd.init(Database, clients);
}
async initIndexer (
Indexer: new (
serverConfig: ServerConfig,
db: DatabaseInterface,
clients: Clients,
ethProvider: JsonRpcProvider,
jobQueue: JobQueue,
graphWatcher?: GraphWatcher
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
clients: { [key: string]: any } = {}
): Promise<void> {
await this.initConfig();
await this._baseCmd.init(Database, Indexer, clients);
graphWatcher?: GraphWatcherInterface
) {
return this._baseCmd.initIndexer(Indexer, graphWatcher);
}
async exec (): Promise<void> {
+33 -11
View File
@@ -11,9 +11,8 @@ import { ConnectionOptions } from 'typeorm';
import { PubSub } from 'graphql-subscriptions';
import { JsonRpcProvider } from '@ethersproject/providers';
import { GraphWatcher, fillState } from '@cerc-io/graph-node';
import { EthClient } from '@cerc-io/ipld-eth-client';
import {
fillState,
DEFAULT_CONFIG_PATH,
JobQueue,
DatabaseInterface,
@@ -21,8 +20,11 @@ import {
ServerConfig,
Clients,
EventWatcherInterface,
fillBlocks
fillBlocks,
GraphWatcherInterface,
Config
} from '@cerc-io/util';
import { EthClient } from '@cerc-io/ipld-eth-client';
import { BaseCmd } from './base';
@@ -45,6 +47,22 @@ export class FillCmd {
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;
}
get indexer (): IndexerInterface | undefined {
return this._baseCmd.indexer;
}
@@ -61,13 +79,21 @@ export class FillCmd {
config: ConnectionOptions,
serverConfig?: ServerConfig
) => DatabaseInterface,
clients: { [key: string]: any } = {}
): Promise<void> {
await this.initConfig();
await this._baseCmd.init(Database, clients);
}
async initIndexer (
Indexer: new (
serverConfig: ServerConfig,
db: DatabaseInterface,
clients: Clients,
ethProvider: JsonRpcProvider,
jobQueue: JobQueue,
graphWatcher?: GraphWatcher
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
EventWatcher: new(
ethClient: EthClient,
@@ -75,13 +101,9 @@ export class FillCmd {
pubsub: PubSub,
jobQueue: JobQueue
) => EventWatcherInterface,
clients: { [key: string]: any } = {},
entityQueryTypeMap?: Map<any, any>,
entityToLatestEntityMap?: Map<any, any>
): Promise<void> {
await this.initConfig();
await this._baseCmd.init(Database, Indexer, clients, entityQueryTypeMap, entityToLatestEntityMap);
graphWatcher?: GraphWatcherInterface
) {
await this._baseCmd.initIndexer(Indexer, graphWatcher);
await this._baseCmd.initEventWatcher(EventWatcher);
}
+36 -15
View File
@@ -12,7 +12,6 @@ import { ConnectionOptions } from 'typeorm';
import { PubSub } from 'graphql-subscriptions';
import { JsonRpcProvider } from '@ethersproject/providers';
import { GraphWatcher, updateEntitiesFromState } from '@cerc-io/graph-node';
import { EthClient } from '@cerc-io/ipld-eth-client';
import {
DEFAULT_CONFIG_PATH,
@@ -23,7 +22,11 @@ import {
Clients,
EventWatcherInterface,
fillBlocks,
StateKind
StateKind,
GraphWatcherInterface,
GraphDatabase,
updateEntitiesFromState,
Config
} from '@cerc-io/util';
import * as codec from '@ipld/dag-cbor';
@@ -44,6 +47,22 @@ export class ImportStateCmd {
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> (): Promise<ConfigType> {
this._argv = this._getArgv();
assert(this._argv);
@@ -56,13 +75,21 @@ export class ImportStateCmd {
config: ConnectionOptions,
serverConfig?: ServerConfig
) => DatabaseInterface,
clients: { [key: string]: any } = {}
): Promise<void> {
await this.initConfig();
await this._baseCmd.init(Database, clients);
}
async initIndexer (
Indexer: new (
serverConfig: ServerConfig,
db: DatabaseInterface,
clients: Clients,
ethProvider: JsonRpcProvider,
jobQueue: JobQueue,
graphWatcher?: GraphWatcher
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
EventWatcher: new(
ethClient: EthClient,
@@ -70,15 +97,13 @@ export class ImportStateCmd {
pubsub: PubSub,
jobQueue: JobQueue
) => EventWatcherInterface,
clients: { [key: string]: any } = {}
): Promise<void> {
await this.initConfig();
await this._baseCmd.init(Database, Indexer, clients);
graphWatcher?: GraphWatcherInterface
) {
await this._baseCmd.initIndexer(Indexer, graphWatcher);
await this._baseCmd.initEventWatcher(EventWatcher);
}
async exec (State: new() => any): Promise<void> {
async exec (State: new() => any, graphDb?: GraphDatabase): Promise<void> {
assert(this._argv);
const config = this._baseCmd.config;
@@ -134,12 +159,8 @@ export class ImportStateCmd {
// relationsMap defined for the watcher,
// graphDb instance is avaiable
// TODO: Fill latest entity tables
if (indexer.getRelationsMap) {
if (this._baseCmd.graphDb) {
await updateEntitiesFromState(this._baseCmd.graphDb, indexer, state);
} else if (database.graphDatabase) {
await updateEntitiesFromState(database.graphDatabase, indexer, state);
}
if (indexer.getRelationsMap && graphDb) {
await updateEntitiesFromState(graphDb, indexer, state);
}
}
+31 -8
View File
@@ -8,7 +8,6 @@ import assert from 'assert';
import { ConnectionOptions } from 'typeorm';
import { JsonRpcProvider } from '@ethersproject/providers';
import { GraphWatcher } from '@cerc-io/graph-node';
import {
DEFAULT_CONFIG_PATH,
JobQueue,
@@ -16,7 +15,9 @@ import {
IndexerInterface,
ServerConfig,
Clients,
indexBlock
indexBlock,
GraphWatcherInterface,
Config
} from '@cerc-io/util';
import { BaseCmd } from './base';
@@ -34,6 +35,22 @@ export class IndexBlockCmd {
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> (): Promise<ConfigType> {
this._argv = this._getArgv();
assert(this._argv);
@@ -46,19 +63,25 @@ export class IndexBlockCmd {
config: ConnectionOptions,
serverConfig?: ServerConfig
) => DatabaseInterface,
clients: { [key: string]: any } = {}
): Promise<void> {
await this.initConfig();
await this._baseCmd.init(Database, clients);
}
async initIndexer (
Indexer: new (
serverConfig: ServerConfig,
db: DatabaseInterface,
clients: Clients,
ethProvider: JsonRpcProvider,
jobQueue: JobQueue,
graphWatcher?: GraphWatcher
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
clients: { [key: string]: any } = {}
): Promise<void> {
await this.initConfig();
await this._baseCmd.init(Database, Indexer, clients);
graphWatcher?: GraphWatcherInterface
) {
return this._baseCmd.initIndexer(Indexer, graphWatcher);
}
async exec (): Promise<void> {
+31 -8
View File
@@ -10,14 +10,15 @@ import { ConnectionOptions } from 'typeorm';
import util from 'util';
import { JsonRpcProvider } from '@ethersproject/providers';
import { GraphWatcher } from '@cerc-io/graph-node';
import {
DEFAULT_CONFIG_PATH,
JobQueue,
DatabaseInterface,
IndexerInterface,
ServerConfig,
Clients
Clients,
GraphWatcherInterface,
Config
} from '@cerc-io/util';
import { BaseCmd } from './base';
@@ -37,6 +38,22 @@ export class InspectCIDCmd {
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> (): Promise<ConfigType> {
this._argv = this._getArgv();
assert(this._argv);
@@ -49,19 +66,25 @@ export class InspectCIDCmd {
config: ConnectionOptions,
serverConfig?: ServerConfig
) => DatabaseInterface,
clients: { [key: string]: any } = {}
): Promise<void> {
await this.initConfig();
await this._baseCmd.init(Database, clients);
}
async initIndexer (
Indexer: new (
serverConfig: ServerConfig,
db: DatabaseInterface,
clients: Clients,
ethProvider: JsonRpcProvider,
jobQueue: JobQueue,
graphWatcher?: GraphWatcher
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
clients: { [key: string]: any } = {}
): Promise<void> {
await this.initConfig();
await this._baseCmd.init(Database, Indexer, clients);
graphWatcher?: GraphWatcherInterface
) {
return this._baseCmd.initIndexer(Indexer, graphWatcher);
}
async exec (): Promise<void> {
+31 -10
View File
@@ -9,7 +9,6 @@ import assert from 'assert';
import { ConnectionOptions } from 'typeorm';
import { JsonRpcProvider } from '@ethersproject/providers';
import { GraphWatcher } from '@cerc-io/graph-node';
import {
DEFAULT_CONFIG_PATH,
JobQueue,
@@ -18,7 +17,9 @@ import {
ServerConfig,
Clients,
JobRunner,
startMetricsServer
GraphWatcherInterface,
startMetricsServer,
Config
} from '@cerc-io/util';
import { BaseCmd } from './base';
@@ -35,6 +36,22 @@ export class JobRunnerCmd {
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;
}
get jobQueue (): JobQueue | undefined {
return this._baseCmd.jobQueue;
}
@@ -55,21 +72,25 @@ export class JobRunnerCmd {
config: ConnectionOptions,
serverConfig?: ServerConfig
) => DatabaseInterface,
clients: { [key: string]: any } = {}
): Promise<void> {
await this.initConfig();
await this._baseCmd.init(Database, clients);
}
async initIndexer (
Indexer: new (
serverConfig: ServerConfig,
db: DatabaseInterface,
clients: Clients,
ethProvider: JsonRpcProvider,
jobQueue: JobQueue,
graphWatcher?: GraphWatcher
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
clients: { [key: string]: any } = {},
entityQueryTypeMap?: Map<any, any>,
entityToLatestEntityMap?: Map<any, any>
): Promise<void> {
await this.initConfig();
await this._baseCmd.init(Database, Indexer, clients, entityQueryTypeMap, entityToLatestEntityMap);
graphWatcher?: GraphWatcherInterface
) {
return this._baseCmd.initIndexer(Indexer, graphWatcher);
}
async exec (startJobRunner: (jobRunner: JobRunner) => Promise<void>): Promise<void> {
+32 -9
View File
@@ -8,13 +8,14 @@ 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
Clients,
GraphWatcherInterface,
Config
} from '@cerc-io/util';
import { BaseCmd } from '../base';
@@ -34,6 +35,22 @@ export class ResetWatcherCmd {
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);
}
@@ -44,20 +61,26 @@ export class ResetWatcherCmd {
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?: GraphWatcher
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
clients: { [key: string]: any } = {}
): Promise<void> {
this._argv = argv;
await this.initConfig(argv.configFile);
await this._baseCmd.init(Database, Indexer, clients);
graphWatcher?: GraphWatcherInterface
) {
return this._baseCmd.initIndexer(Indexer, graphWatcher);
}
async exec (): Promise<void> {
+31 -10
View File
@@ -12,7 +12,6 @@ import express, { Application } from 'express';
import { ApolloServer } from 'apollo-server-express';
import { JsonRpcProvider } from '@ethersproject/providers';
import { GraphWatcher } from '@cerc-io/graph-node';
import { EthClient } from '@cerc-io/ipld-eth-client';
import {
DEFAULT_CONFIG_PATH,
@@ -24,7 +23,9 @@ import {
EventWatcherInterface,
KIND_ACTIVE,
createAndStartServer,
startGQLMetricsServer
startGQLMetricsServer,
GraphWatcherInterface,
Config
} from '@cerc-io/util';
import { TypeSource } from '@graphql-tools/utils';
@@ -42,6 +43,22 @@ export class ServerCmd {
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> (): Promise<ConfigType> {
this._argv = this._getArgv();
assert(this._argv);
@@ -54,13 +71,21 @@ export class ServerCmd {
config: ConnectionOptions,
serverConfig?: ServerConfig
) => DatabaseInterface,
clients: { [key: string]: any } = {}
): Promise<void> {
await this.initConfig();
await this._baseCmd.init(Database, clients);
}
async initIndexer (
Indexer: new (
serverConfig: ServerConfig,
db: DatabaseInterface,
clients: Clients,
ethProvider: JsonRpcProvider,
jobQueue: JobQueue,
graphWatcher?: GraphWatcher
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
EventWatcher: new(
ethClient: EthClient,
@@ -68,13 +93,9 @@ export class ServerCmd {
pubsub: PubSub,
jobQueue: JobQueue
) => EventWatcherInterface,
clients: { [key: string]: any } = {},
entityQueryTypeMap?: Map<any, any>,
entityToLatestEntityMap?: Map<any, any>
): Promise<void> {
await this.initConfig();
await this._baseCmd.init(Database, Indexer, clients, entityQueryTypeMap, entityToLatestEntityMap);
graphWatcher?: GraphWatcherInterface
) {
await this._baseCmd.initIndexer(Indexer, graphWatcher);
await this._baseCmd.initEventWatcher(EventWatcher);
}
+31 -8
View File
@@ -8,14 +8,15 @@ import assert from 'assert';
import { ConnectionOptions } from 'typeorm';
import { JsonRpcProvider } from '@ethersproject/providers';
import { GraphWatcher } from '@cerc-io/graph-node';
import {
DEFAULT_CONFIG_PATH,
JobQueue,
DatabaseInterface,
IndexerInterface,
ServerConfig,
Clients
Clients,
GraphWatcherInterface,
Config
} from '@cerc-io/util';
import { BaseCmd } from './base';
@@ -36,6 +37,22 @@ export class WatchContractCmd {
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> (): Promise<ConfigType> {
this._argv = this._getArgv();
assert(this._argv);
@@ -48,19 +65,25 @@ export class WatchContractCmd {
config: ConnectionOptions,
serverConfig?: ServerConfig
) => DatabaseInterface,
clients: { [key: string]: any } = {}
): Promise<void> {
await this.initConfig();
await this._baseCmd.init(Database, clients);
}
async initIndexer (
Indexer: new (
serverConfig: ServerConfig,
db: DatabaseInterface,
clients: Clients,
ethProvider: JsonRpcProvider,
jobQueue: JobQueue,
graphWatcher?: GraphWatcher
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
clients: { [key: string]: any } = {}
): Promise<void> {
await this.initConfig();
await this._baseCmd.init(Database, Indexer, clients);
graphWatcher?: GraphWatcherInterface
) {
return this._baseCmd.initIndexer(Indexer, graphWatcher);
}
async exec (): Promise<void> {