From b66dcb4af919520aa582a09183c4c40271dcb452 Mon Sep 17 00:00:00 2001 From: nikugogoi Date: Fri, 25 Nov 2022 15:54:35 +0530 Subject: [PATCH] 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 --- packages/cli/package.json | 13 +++- packages/cli/src/base.ts | 74 ++++++++----------- packages/cli/src/checkpoint/create.ts | 41 +++++++--- packages/cli/src/checkpoint/verify.ts | 47 ++++++++---- packages/cli/src/export-state.ts | 39 ++++++++-- packages/cli/src/fill.ts | 44 ++++++++--- packages/cli/src/import-state.ts | 51 +++++++++---- packages/cli/src/index-block.ts | 39 ++++++++-- packages/cli/src/inspect-cid.ts | 39 ++++++++-- packages/cli/src/job-runner.ts | 41 +++++++--- packages/cli/src/reset/watcher.ts | 41 +++++++--- packages/cli/src/server.ts | 41 +++++++--- packages/cli/src/watch-contract.ts | 39 ++++++++-- .../checkpoint-create-template.handlebars | 19 ++++- .../checkpoint-verify-template.handlebars | 17 ++++- .../templates/database-template.handlebars | 14 +++- .../export-state-template.handlebars | 19 ++++- .../src/templates/fill-template.handlebars | 23 ++++-- .../import-state-template.handlebars | 21 +++++- .../templates/index-block-template.handlebars | 19 ++++- .../src/templates/indexer-template.handlebars | 9 ++- .../templates/inspect-cid-template.handlebars | 19 ++++- .../templates/job-runner-template.handlebars | 18 ++++- .../reset-watcher-template.handlebars | 19 ++++- .../src/templates/server-template.handlebars | 19 ++++- .../templates/subscriber-template.handlebars | 3 +- .../watch-contract-template.handlebars | 19 ++++- .../src/cli/checkpoint-cmds/create.ts | 15 +++- .../src/cli/checkpoint-cmds/verify.ts | 17 ++++- packages/eden-watcher/src/cli/export-state.ts | 15 +++- packages/eden-watcher/src/cli/import-state.ts | 17 ++++- packages/eden-watcher/src/cli/index-block.ts | 15 +++- packages/eden-watcher/src/cli/inspect-cid.ts | 15 +++- .../src/cli/reset-cmds/watcher.ts | 15 +++- .../eden-watcher/src/cli/watch-contract.ts | 15 +++- .../eden-watcher/src/entity/Subscriber.ts | 2 +- packages/eden-watcher/src/fill.ts | 19 +++-- packages/eden-watcher/src/indexer.ts | 11 ++- packages/eden-watcher/src/job-runner.ts | 14 +++- packages/eden-watcher/src/server.ts | 15 +++- .../src/cli/reset-cmds/watcher.ts | 4 +- .../erc20-watcher/src/cli/watch-contract.ts | 4 +- packages/erc20-watcher/src/fill.ts | 4 +- packages/erc20-watcher/src/job-runner.ts | 3 +- packages/erc20-watcher/src/server.ts | 6 +- .../src/cli/checkpoint-cmds/create.ts | 4 +- .../erc721-watcher/src/cli/export-state.ts | 4 +- .../erc721-watcher/src/cli/import-state.ts | 4 +- .../erc721-watcher/src/cli/index-block.ts | 4 +- .../erc721-watcher/src/cli/inspect-cid.ts | 4 +- .../src/cli/reset-cmds/watcher.ts | 4 +- .../erc721-watcher/src/cli/watch-contract.ts | 4 +- packages/erc721-watcher/src/fill.ts | 3 +- packages/erc721-watcher/src/job-runner.ts | 3 +- packages/erc721-watcher/src/server.ts | 4 +- packages/graph-node/src/call-handler.test.ts | 5 +- .../src/cli/compare/compare-blocks.ts | 16 ++-- packages/graph-node/src/cli/compare/utils.ts | 2 +- packages/graph-node/src/crypto.test.ts | 4 +- packages/graph-node/src/eden.test.ts | 5 +- packages/graph-node/src/eth-abi.test.ts | 4 +- packages/graph-node/src/eth-call.test.ts | 5 +- packages/graph-node/src/index.ts | 6 -- packages/graph-node/src/json.test.ts | 4 +- packages/graph-node/src/loader.test.ts | 4 +- packages/graph-node/src/loader.ts | 16 ++-- packages/graph-node/src/numbers.test.ts | 18 ++--- packages/graph-node/src/storage-call.test.ts | 5 +- .../graph-node/src/type-conversion.test.ts | 4 +- packages/graph-node/src/watcher.ts | 43 +++++++++-- packages/graph-node/test/utils/index.ts | 8 +- .../src/cli/checkpoint-cmds/create.ts | 15 +++- .../src/cli/checkpoint-cmds/verify.ts | 17 ++++- .../src/cli/export-state.ts | 15 +++- .../src/cli/import-state.ts | 17 ++++- .../graph-test-watcher/src/cli/index-block.ts | 15 +++- .../graph-test-watcher/src/cli/inspect-cid.ts | 15 +++- .../src/cli/reset-cmds/watcher.ts | 15 +++- .../src/cli/watch-contract.ts | 15 +++- .../src/entity/Subscriber.ts | 2 +- packages/graph-test-watcher/src/fill.ts | 20 +++-- packages/graph-test-watcher/src/indexer.ts | 11 ++- packages/graph-test-watcher/src/job-runner.ts | 16 +++- packages/graph-test-watcher/src/server.ts | 15 +++- packages/ipld-eth-client/package.json | 1 - .../src/cli/checkpoint-cmds/create.ts | 4 +- .../mobymask-watcher/src/cli/export-state.ts | 4 +- .../mobymask-watcher/src/cli/import-state.ts | 4 +- .../mobymask-watcher/src/cli/index-block.ts | 4 +- .../mobymask-watcher/src/cli/inspect-cid.ts | 4 +- .../src/cli/reset-cmds/watcher.ts | 4 +- .../src/cli/watch-contract.ts | 4 +- packages/mobymask-watcher/src/fill.ts | 3 +- packages/mobymask-watcher/src/job-runner.ts | 3 +- packages/mobymask-watcher/src/server.ts | 4 +- packages/solidity-mapper/package.json | 1 - packages/util/package.json | 13 +++- .../src => util/src/graph}/database.ts | 22 ++---- .../util/src/{ => graph}/graph-decimal.ts | 0 .../src => util/src/graph}/state-utils.ts | 43 +++++++++-- .../src => util/src/graph}/types.ts | 2 +- .../src => util/src/graph}/utils.ts | 47 ++---------- packages/util/src/index.ts | 6 +- packages/util/src/misc.ts | 2 +- packages/util/src/types.ts | 5 ++ 105 files changed, 1120 insertions(+), 428 deletions(-) rename packages/{graph-node/src => util/src/graph}/database.ts (98%) rename packages/util/src/{ => graph}/graph-decimal.ts (100%) rename packages/{graph-node/src => util/src/graph}/state-utils.ts (85%) rename packages/{graph-node/src => util/src/graph}/types.ts (98%) rename packages/{graph-node/src => util/src/graph}/utils.ts (95%) diff --git a/packages/cli/package.json b/packages/cli/package.json index 8b321385..b1f94d0b 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -10,12 +10,18 @@ "copy-assets": "copyfiles -u 1 src/**/*.gql dist/" }, "dependencies": { - "@cerc-io/graph-node": "^0.2.15", + "@cerc-io/ipld-eth-client": "^0.2.15", "@cerc-io/util": "^0.2.15", "@ethersproject/providers": "^5.4.4", + "@graphql-tools/utils": "^9.1.1", + "@ipld/dag-cbor": "^6.0.12", "reflect-metadata": "^0.1.13", "typeorm": "^0.2.32", - "yargs": "^17.0.1" + "yargs": "^17.0.1", + "graphql-subscriptions": "^2.0.0", + "debug": "^4.3.1", + "express": "^4.18.2", + "apollo-server-express": "^3.11.1" }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^4.25.0", @@ -24,6 +30,7 @@ "eslint-config-standard": "^5.0.0", "eslint-plugin-import": "^2.23.3", "eslint-plugin-node": "^11.1.0", - "eslint-plugin-promise": "^5.1.0" + "eslint-plugin-promise": "^5.1.0", + "eslint-plugin-standard": "^5.0.0" } } diff --git a/packages/cli/src/base.ts b/packages/cli/src/base.ts index 78349dd4..6e7e2f16 100644 --- a/packages/cli/src/base.ts +++ b/packages/cli/src/base.ts @@ -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, - entityToLatestEntityMap?: Map + clients: { [key: string]: any } = {} ): Promise { 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, - entityToLatestEntityMap?: Map - ): Promise { - 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); - } } diff --git a/packages/cli/src/checkpoint/create.ts b/packages/cli/src/checkpoint/create.ts index 58dd9e3b..61476813 100644 --- a/packages/cli/src/checkpoint/create.ts +++ b/packages/cli/src/checkpoint/create.ts @@ -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 (configFile: string): Promise { return this._baseCmd.initConfig(configFile); } @@ -45,20 +62,26 @@ export class CreateCheckpointCmd { config: ConnectionOptions, serverConfig?: ServerConfig ) => DatabaseInterface, + clients: { [key: string]: any } = {} + ): Promise { + 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 { - 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 { diff --git a/packages/cli/src/checkpoint/verify.ts b/packages/cli/src/checkpoint/verify.ts index b602fb86..9806e87b 100644 --- a/packages/cli/src/checkpoint/verify.ts +++ b/packages/cli/src/checkpoint/verify.ts @@ -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 (configFile: string): Promise { return this._baseCmd.initConfig(configFile); } @@ -45,23 +63,29 @@ export class VerifyCheckpointCmd { config: ConnectionOptions, serverConfig?: ServerConfig ) => DatabaseInterface, + clients: { [key: string]: any } = {} + ): Promise { + 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 { - 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 { + async exec (graphDb: GraphDatabase): Promise { 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); diff --git a/packages/cli/src/export-state.ts b/packages/cli/src/export-state.ts index 496e08fd..0ded6b70 100644 --- a/packages/cli/src/export-state.ts +++ b/packages/cli/src/export-state.ts @@ -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 (): Promise { this._argv = this._getArgv(); assert(this._argv); @@ -53,19 +70,25 @@ export class ExportStateCmd { config: ConnectionOptions, serverConfig?: ServerConfig ) => DatabaseInterface, + clients: { [key: string]: any } = {} + ): Promise { + 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 { - await this.initConfig(); - - await this._baseCmd.init(Database, Indexer, clients); + graphWatcher?: GraphWatcherInterface + ) { + return this._baseCmd.initIndexer(Indexer, graphWatcher); } async exec (): Promise { diff --git a/packages/cli/src/fill.ts b/packages/cli/src/fill.ts index 63b0bd9e..90cf076a 100644 --- a/packages/cli/src/fill.ts +++ b/packages/cli/src/fill.ts @@ -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 { + 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, - entityToLatestEntityMap?: Map - ): Promise { - 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); } diff --git a/packages/cli/src/import-state.ts b/packages/cli/src/import-state.ts index dcda9ea3..e042b2ac 100644 --- a/packages/cli/src/import-state.ts +++ b/packages/cli/src/import-state.ts @@ -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 (): Promise { this._argv = this._getArgv(); assert(this._argv); @@ -56,13 +75,21 @@ export class ImportStateCmd { config: ConnectionOptions, serverConfig?: ServerConfig ) => DatabaseInterface, + clients: { [key: string]: any } = {} + ): Promise { + 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 { - 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 { + async exec (State: new() => any, graphDb?: GraphDatabase): Promise { 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); } } diff --git a/packages/cli/src/index-block.ts b/packages/cli/src/index-block.ts index 2535f296..7d08caf8 100644 --- a/packages/cli/src/index-block.ts +++ b/packages/cli/src/index-block.ts @@ -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 (): Promise { this._argv = this._getArgv(); assert(this._argv); @@ -46,19 +63,25 @@ export class IndexBlockCmd { config: ConnectionOptions, serverConfig?: ServerConfig ) => DatabaseInterface, + clients: { [key: string]: any } = {} + ): Promise { + 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 { - await this.initConfig(); - - await this._baseCmd.init(Database, Indexer, clients); + graphWatcher?: GraphWatcherInterface + ) { + return this._baseCmd.initIndexer(Indexer, graphWatcher); } async exec (): Promise { diff --git a/packages/cli/src/inspect-cid.ts b/packages/cli/src/inspect-cid.ts index d4563579..61b9111e 100644 --- a/packages/cli/src/inspect-cid.ts +++ b/packages/cli/src/inspect-cid.ts @@ -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 (): Promise { this._argv = this._getArgv(); assert(this._argv); @@ -49,19 +66,25 @@ export class InspectCIDCmd { config: ConnectionOptions, serverConfig?: ServerConfig ) => DatabaseInterface, + clients: { [key: string]: any } = {} + ): Promise { + 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 { - await this.initConfig(); - - await this._baseCmd.init(Database, Indexer, clients); + graphWatcher?: GraphWatcherInterface + ) { + return this._baseCmd.initIndexer(Indexer, graphWatcher); } async exec (): Promise { diff --git a/packages/cli/src/job-runner.ts b/packages/cli/src/job-runner.ts index 2cc02163..9e624b39 100644 --- a/packages/cli/src/job-runner.ts +++ b/packages/cli/src/job-runner.ts @@ -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 { + 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, - entityToLatestEntityMap?: Map - ): Promise { - 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): Promise { diff --git a/packages/cli/src/reset/watcher.ts b/packages/cli/src/reset/watcher.ts index 430bfbc5..c92d6aba 100644 --- a/packages/cli/src/reset/watcher.ts +++ b/packages/cli/src/reset/watcher.ts @@ -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 (configFile: string): Promise { return this._baseCmd.initConfig(configFile); } @@ -44,20 +61,26 @@ export class ResetWatcherCmd { config: ConnectionOptions, serverConfig?: ServerConfig ) => DatabaseInterface, + clients: { [key: string]: any } = {} + ): Promise { + 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 { - 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 { diff --git a/packages/cli/src/server.ts b/packages/cli/src/server.ts index b54d7f2f..6541de5f 100644 --- a/packages/cli/src/server.ts +++ b/packages/cli/src/server.ts @@ -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 (): Promise { this._argv = this._getArgv(); assert(this._argv); @@ -54,13 +71,21 @@ export class ServerCmd { config: ConnectionOptions, serverConfig?: ServerConfig ) => DatabaseInterface, + clients: { [key: string]: any } = {} + ): Promise { + 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, - entityToLatestEntityMap?: Map - ): Promise { - 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); } diff --git a/packages/cli/src/watch-contract.ts b/packages/cli/src/watch-contract.ts index 610cb3c0..bf32a7fb 100644 --- a/packages/cli/src/watch-contract.ts +++ b/packages/cli/src/watch-contract.ts @@ -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 (): Promise { this._argv = this._getArgv(); assert(this._argv); @@ -48,19 +65,25 @@ export class WatchContractCmd { config: ConnectionOptions, serverConfig?: ServerConfig ) => DatabaseInterface, + clients: { [key: string]: any } = {} + ): Promise { + 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 { - await this.initConfig(); - - await this._baseCmd.init(Database, Indexer, clients); + graphWatcher?: GraphWatcherInterface + ) { + return this._baseCmd.initIndexer(Indexer, graphWatcher); } async exec (): Promise { diff --git a/packages/codegen/src/templates/checkpoint-create-template.handlebars b/packages/codegen/src/templates/checkpoint-create-template.handlebars index 63f844ce..9f584493 100644 --- a/packages/codegen/src/templates/checkpoint-create-template.handlebars +++ b/packages/codegen/src/templates/checkpoint-create-template.handlebars @@ -3,8 +3,11 @@ // import { CreateCheckpointCmd } from '@cerc-io/cli'; +{{#if (subgraphPath)}} +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; +{{/if}} -import { Database } from '../../database'; +import { Database{{#if (subgraphPath)}}, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP{{/if}} } from '../../database'; import { Indexer } from '../../indexer'; export const command = 'create'; @@ -26,7 +29,19 @@ export const builder = { export const handler = async (argv: any): Promise => { const createCheckpointCmd = new CreateCheckpointCmd(); - await createCheckpointCmd.init(argv, Database, Indexer); + await createCheckpointCmd.init(argv, Database); + {{#if (subgraphPath)}} + const { graphWatcher } = await getGraphDbAndWatcher( + createCheckpointCmd.config!.server, + createCheckpointCmd.clients!.ethClient, + createCheckpointCmd.ethProvider!, + createCheckpointCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + {{/if}} + await createCheckpointCmd.initIndexer(Indexer{{#if (subgraphPath)}}, graphWatcher{{/if}}); await createCheckpointCmd.exec(); }; diff --git a/packages/codegen/src/templates/checkpoint-verify-template.handlebars b/packages/codegen/src/templates/checkpoint-verify-template.handlebars index 9513d719..3fdfda99 100644 --- a/packages/codegen/src/templates/checkpoint-verify-template.handlebars +++ b/packages/codegen/src/templates/checkpoint-verify-template.handlebars @@ -3,8 +3,9 @@ // import { VerifyCheckpointCmd } from '@cerc-io/cli'; +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; -import { Database } from '../../database'; +import { Database, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP } from '../../database'; import { Indexer } from '../../indexer'; export const command = 'verify'; @@ -22,7 +23,17 @@ export const builder = { export const handler = async (argv: any): Promise => { const verifyCheckpointCmd = new VerifyCheckpointCmd(); - await verifyCheckpointCmd.init(argv, Database, Indexer); + await verifyCheckpointCmd.init(argv, Database); - await verifyCheckpointCmd.exec(); + const { graphWatcher, graphDb } = await getGraphDbAndWatcher( + verifyCheckpointCmd.config!.server, + verifyCheckpointCmd.clients!.ethClient, + verifyCheckpointCmd.ethProvider!, + verifyCheckpointCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + await verifyCheckpointCmd.initIndexer(Indexer, graphWatcher); + await verifyCheckpointCmd.exec(graphDb); }; diff --git a/packages/codegen/src/templates/database-template.handlebars b/packages/codegen/src/templates/database-template.handlebars index 34032d0b..f137e9a7 100644 --- a/packages/codegen/src/templates/database-template.handlebars +++ b/packages/codegen/src/templates/database-template.handlebars @@ -6,10 +6,16 @@ import assert from 'assert'; import { Connection, ConnectionOptions, DeepPartial, FindConditions, QueryRunner, FindManyOptions, EntityTarget } from 'typeorm'; import path from 'path'; -import { Database as BaseDatabase, DatabaseInterface, QueryOptions, StateKind, Where } from '@cerc-io/util'; -{{#if (subgraphPath)}} -import { ENTITY_QUERY_TYPE } from '@cerc-io/graph-node'; -{{/if}} +import { + {{#if (subgraphPath)}} + ENTITY_QUERY_TYPE, + {{/if}} + Database as BaseDatabase, + DatabaseInterface, + QueryOptions, + StateKind, + Where +} from '@cerc-io/util'; import { Contract } from './entity/Contract'; import { Event } from './entity/Event'; diff --git a/packages/codegen/src/templates/export-state-template.handlebars b/packages/codegen/src/templates/export-state-template.handlebars index 2411b960..dcbcd694 100644 --- a/packages/codegen/src/templates/export-state-template.handlebars +++ b/packages/codegen/src/templates/export-state-template.handlebars @@ -6,16 +6,31 @@ import 'reflect-metadata'; import debug from 'debug'; import { ExportStateCmd } from '@cerc-io/cli'; +{{#if (subgraphPath)}} +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; +{{/if}} -import { Database } from '../database'; +import { Database{{#if (subgraphPath)}}, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP{{/if}} } from '../database'; import { Indexer } from '../indexer'; const log = debug('vulcanize:export-state'); const main = async (): Promise => { const exportStateCmd = new ExportStateCmd(); - await exportStateCmd.init(Database, Indexer); + await exportStateCmd.init(Database); + {{#if (subgraphPath)}} + const { graphWatcher } = await getGraphDbAndWatcher( + exportStateCmd.config!.server, + exportStateCmd.clients!.ethClient, + exportStateCmd.ethProvider!, + exportStateCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + {{/if}} + await exportStateCmd.initIndexer(Indexer{{#if (subgraphPath)}}, graphWatcher{{/if}}); await exportStateCmd.exec(); }; diff --git a/packages/codegen/src/templates/fill-template.handlebars b/packages/codegen/src/templates/fill-template.handlebars index 1c7ffe0e..fba4dc55 100644 --- a/packages/codegen/src/templates/fill-template.handlebars +++ b/packages/codegen/src/templates/fill-template.handlebars @@ -2,15 +2,14 @@ // Copyright 2021 Vulcanize, Inc. // -{{#if (subgraphPath)}} import assert from 'assert'; -{{/if}} import 'reflect-metadata'; import debug from 'debug'; import { FillCmd } from '@cerc-io/cli'; {{#if (subgraphPath)}} -import { getContractEntitiesMap } from '@cerc-io/graph-node'; +import { getContractEntitiesMap } from '@cerc-io/util'; +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; {{/if}} import { Database{{#if (subgraphPath)}}, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP{{/if}} } from './database'; @@ -21,15 +20,25 @@ const log = debug('vulcanize:fill'); export const main = async (): Promise => { const fillCmd = new FillCmd(); - await fillCmd.init(Database, Indexer, EventWatcher{{#if (subgraphPath)}}, {}, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP{{/if}}); + await fillCmd.init(Database); {{#if (subgraphPath)}} - const indexer = fillCmd.indexer as Indexer; - assert(indexer); + const { graphWatcher } = await getGraphDbAndWatcher( + fillCmd.config!.server, + fillCmd.clients!.ethClient, + fillCmd.ethProvider!, + fillCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + {{/if}} + await fillCmd.initIndexer(Indexer, EventWatcher{{#if (subgraphPath)}}, graphWatcher{{/if}}); + + {{#if (subgraphPath)}} // Get contractEntitiesMap required for fill-state // NOTE: Assuming each entity type is only mapped to a single contract - const contractEntitiesMap = getContractEntitiesMap(indexer.graphWatcher.dataSources); + const contractEntitiesMap = getContractEntitiesMap(graphWatcher.dataSources); {{/if}} await fillCmd.exec({{#if (subgraphPath)}}contractEntitiesMap{{/if}}); diff --git a/packages/codegen/src/templates/import-state-template.handlebars b/packages/codegen/src/templates/import-state-template.handlebars index 871f1b00..95cbb3f1 100644 --- a/packages/codegen/src/templates/import-state-template.handlebars +++ b/packages/codegen/src/templates/import-state-template.handlebars @@ -6,8 +6,11 @@ import 'reflect-metadata'; import debug from 'debug'; import { ImportStateCmd } from '@cerc-io/cli'; +{{#if (subgraphPath)}} +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; +{{/if}} -import { Database } from '../database'; +import { Database{{#if (subgraphPath)}}, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP{{/if}} } from '../database'; import { Indexer } from '../indexer'; import { EventWatcher } from '../events'; import { State } from '../entity/State'; @@ -16,9 +19,21 @@ const log = debug('vulcanize:import-state'); export const main = async (): Promise => { const importStateCmd = new ImportStateCmd(); - await importStateCmd.init(Database, Indexer, EventWatcher); + await importStateCmd.init(Database); - await importStateCmd.exec(State); + {{#if (subgraphPath)}} + const { graphWatcher, graphDb } = await getGraphDbAndWatcher( + importStateCmd.config!.server, + importStateCmd.clients!.ethClient, + importStateCmd.ethProvider!, + importStateCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + {{/if}} + await importStateCmd.initIndexer(Indexer, EventWatcher{{#if (subgraphPath)}}, graphWatcher{{/if}}); + await importStateCmd.exec(State{{#if (subgraphPath)}}, graphDb{{/if}}); }; main().catch(err => { diff --git a/packages/codegen/src/templates/index-block-template.handlebars b/packages/codegen/src/templates/index-block-template.handlebars index 6b59df5e..6044860f 100644 --- a/packages/codegen/src/templates/index-block-template.handlebars +++ b/packages/codegen/src/templates/index-block-template.handlebars @@ -6,16 +6,31 @@ import 'reflect-metadata'; import debug from 'debug'; import { IndexBlockCmd } from '@cerc-io/cli'; +{{#if (subgraphPath)}} +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; +{{/if}} -import { Database } from '../database'; +import { Database{{#if (subgraphPath)}}, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP{{/if}} } from '../database'; import { Indexer } from '../indexer'; const log = debug('vulcanize:index-block'); const main = async (): Promise => { const indexBlockCmd = new IndexBlockCmd(); - await indexBlockCmd.init(Database, Indexer); + await indexBlockCmd.init(Database); + {{#if (subgraphPath)}} + const { graphWatcher } = await getGraphDbAndWatcher( + indexBlockCmd.config!.server, + indexBlockCmd.clients!.ethClient, + indexBlockCmd.ethProvider!, + indexBlockCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + {{/if}} + await indexBlockCmd.initIndexer(Indexer{{#if (subgraphPath)}}, graphWatcher{{/if}}); await indexBlockCmd.exec(); }; diff --git a/packages/codegen/src/templates/indexer-template.handlebars b/packages/codegen/src/templates/indexer-template.handlebars index ad25a194..9fec790e 100644 --- a/packages/codegen/src/templates/indexer-template.handlebars +++ b/packages/codegen/src/templates/indexer-template.handlebars @@ -27,6 +27,9 @@ import { updateStateForMappingType, {{#if (subgraphPath)}} BlockHeight, + updateSubgraphState, + dumpSubgraphState, + GraphWatcherInterface, {{/if}} StateKind, StateStatus, @@ -36,7 +39,7 @@ import { Clients } from '@cerc-io/util'; {{#if (subgraphPath)}} -import { GraphWatcher, updateSubgraphState, dumpSubgraphState } from '@cerc-io/graph-node'; +import { GraphWatcher } from '@cerc-io/graph-node'; {{/if}} {{#each contracts as | contract |}} @@ -89,7 +92,7 @@ export class Indexer implements IndexerInterface { _subgraphStateMap: Map {{/if}} - constructor (serverConfig: ServerConfig, db: DatabaseInterface, clients: Clients, ethProvider: BaseProvider, jobQueue: JobQueue{{#if (subgraphPath)}}, graphWatcher?: GraphWatcher{{/if}}) { + constructor (serverConfig: ServerConfig, db: DatabaseInterface, clients: Clients, ethProvider: BaseProvider, jobQueue: JobQueue{{#if (subgraphPath)}}, graphWatcher?: GraphWatcherInterface{{/if}}) { assert(db); assert(clients.ethClient); @@ -100,7 +103,7 @@ export class Indexer implements IndexerInterface { this._baseIndexer = new BaseIndexer(this._serverConfig, this._db, this._ethClient, this._ethProvider, jobQueue); {{#if (subgraphPath)}} assert(graphWatcher); - this._graphWatcher = graphWatcher; + this._graphWatcher = graphWatcher as GraphWatcher; {{/if}} this._abiMap = new Map(); diff --git a/packages/codegen/src/templates/inspect-cid-template.handlebars b/packages/codegen/src/templates/inspect-cid-template.handlebars index 3b1f44d7..a6812f3d 100644 --- a/packages/codegen/src/templates/inspect-cid-template.handlebars +++ b/packages/codegen/src/templates/inspect-cid-template.handlebars @@ -6,16 +6,31 @@ import 'reflect-metadata'; import debug from 'debug'; import { InspectCIDCmd } from '@cerc-io/cli'; +{{#if (subgraphPath)}} +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; +{{/if}} -import { Database } from '../database'; +import { Database{{#if (subgraphPath)}}, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP{{/if}} } from '../database'; import { Indexer } from '../indexer'; const log = debug('vulcanize:inspect-cid'); const main = async (): Promise => { const inspectCIDCmd = new InspectCIDCmd(); - await inspectCIDCmd.init(Database, Indexer); + await inspectCIDCmd.init(Database); + {{#if (subgraphPath)}} + const { graphWatcher } = await getGraphDbAndWatcher( + inspectCIDCmd.config!.server, + inspectCIDCmd.clients!.ethClient, + inspectCIDCmd.ethProvider!, + inspectCIDCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + {{/if}} + await inspectCIDCmd.initIndexer(Indexer{{#if (subgraphPath)}}, graphWatcher{{/if}}); await inspectCIDCmd.exec(); }; diff --git a/packages/codegen/src/templates/job-runner-template.handlebars b/packages/codegen/src/templates/job-runner-template.handlebars index fa6685f1..dbc69bfb 100644 --- a/packages/codegen/src/templates/job-runner-template.handlebars +++ b/packages/codegen/src/templates/job-runner-template.handlebars @@ -6,6 +6,9 @@ import debug from 'debug'; import { JobRunnerCmd } from '@cerc-io/cli'; import { JobRunner } from '@cerc-io/util'; +{{#if (subgraphPath)}} +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; +{{/if}} import { Indexer } from './indexer'; import { Database{{#if (subgraphPath)}}, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP{{/if}} } from './database'; @@ -14,7 +17,20 @@ const log = debug('vulcanize:job-runner'); export const main = async (): Promise => { const jobRunnerCmd = new JobRunnerCmd(); - await jobRunnerCmd.init(Database, Indexer{{#if (subgraphPath)}}, {}, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP{{/if}}); + await jobRunnerCmd.init(Database); + + {{#if (subgraphPath)}} + const { graphWatcher } = await getGraphDbAndWatcher( + jobRunnerCmd.config!.server, + jobRunnerCmd.clients!.ethClient, + jobRunnerCmd.ethProvider!, + jobRunnerCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + {{/if}} + await jobRunnerCmd.initIndexer(Indexer{{#if (subgraphPath)}}, graphWatcher{{/if}}); await jobRunnerCmd.exec(async (jobRunner: JobRunner): Promise => { await jobRunner.subscribeBlockProcessingQueue(); diff --git a/packages/codegen/src/templates/reset-watcher-template.handlebars b/packages/codegen/src/templates/reset-watcher-template.handlebars index 295adc45..a70007cb 100644 --- a/packages/codegen/src/templates/reset-watcher-template.handlebars +++ b/packages/codegen/src/templates/reset-watcher-template.handlebars @@ -3,8 +3,11 @@ // import { ResetWatcherCmd } from '@cerc-io/cli'; +{{#if (subgraphPath)}} +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; +{{/if}} -import { Database } from '../../database'; +import { Database{{#if (subgraphPath)}}, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP{{/if}} } from '../../database'; import { Indexer } from '../../indexer'; export const command = 'watcher'; @@ -19,7 +22,19 @@ export const builder = { export const handler = async (argv: any): Promise => { const resetWatcherCmd = new ResetWatcherCmd(); - await resetWatcherCmd.init(argv, Database, Indexer); + await resetWatcherCmd.init(argv, Database); + {{#if (subgraphPath)}} + const { graphWatcher, graphDb } = await getGraphDbAndWatcher( + resetWatcherCmd.config!.server, + resetWatcherCmd.clients!.ethClient, + resetWatcherCmd.ethProvider!, + resetWatcherCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + {{/if}} + await resetWatcherCmd.initIndexer(Indexer{{#if (subgraphPath)}}, graphWatcher{{/if}}); await resetWatcherCmd.exec(); }; diff --git a/packages/codegen/src/templates/server-template.handlebars b/packages/codegen/src/templates/server-template.handlebars index 07f010b3..af0f1118 100644 --- a/packages/codegen/src/templates/server-template.handlebars +++ b/packages/codegen/src/templates/server-template.handlebars @@ -8,6 +8,9 @@ import 'reflect-metadata'; import debug from 'debug'; import { ServerCmd } from '@cerc-io/cli'; +{{#if (subgraphPath)}} +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; +{{/if}} import { createResolvers } from './resolvers'; import { Indexer } from './indexer'; @@ -18,10 +21,22 @@ const log = debug('vulcanize:server'); export const main = async (): Promise => { const serverCmd = new ServerCmd(); - await serverCmd.init(Database, Indexer, EventWatcher{{#if (subgraphPath)}}, {}, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP{{/if}}); + await serverCmd.init(Database); + + {{#if (subgraphPath)}} + const { graphWatcher } = await getGraphDbAndWatcher( + serverCmd.config!.server, + serverCmd.clients!.ethClient, + serverCmd.ethProvider!, + serverCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + {{/if}} + await serverCmd.initIndexer(Indexer, EventWatcher{{#if (subgraphPath)}}, graphWatcher{{/if}}); const typeDefs = fs.readFileSync(path.join(__dirname, 'schema.gql')).toString(); - return serverCmd.exec(createResolvers, typeDefs); }; diff --git a/packages/codegen/src/templates/subscriber-template.handlebars b/packages/codegen/src/templates/subscriber-template.handlebars index e18e4173..2cccb841 100644 --- a/packages/codegen/src/templates/subscriber-template.handlebars +++ b/packages/codegen/src/templates/subscriber-template.handlebars @@ -4,9 +4,10 @@ import { EventSubscriber, EntitySubscriberInterface, InsertEvent, UpdateEvent } from 'typeorm'; +import { afterEntityInsertOrUpdate } from '@cerc-io/util'; + import { FrothyEntity } from './FrothyEntity'; import { ENTITY_TO_LATEST_ENTITY_MAP, SUBGRAPH_ENTITIES } from '../database'; -import { afterEntityInsertOrUpdate } from '@cerc-io/graph-node'; @EventSubscriber() export class EntitySubscriber implements EntitySubscriberInterface { diff --git a/packages/codegen/src/templates/watch-contract-template.handlebars b/packages/codegen/src/templates/watch-contract-template.handlebars index bf1e7834..2c277d54 100644 --- a/packages/codegen/src/templates/watch-contract-template.handlebars +++ b/packages/codegen/src/templates/watch-contract-template.handlebars @@ -6,16 +6,31 @@ import 'reflect-metadata'; import debug from 'debug'; import { WatchContractCmd } from '@cerc-io/cli'; +{{#if (subgraphPath)}} +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; +{{/if}} -import { Database } from '../database'; +import { Database{{#if (subgraphPath)}}, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP{{/if}} } from '../database'; import { Indexer } from '../indexer'; const log = debug('vulcanize:watch-contract'); const main = async (): Promise => { const watchContractCmd = new WatchContractCmd(); - await watchContractCmd.init(Database, Indexer); + await watchContractCmd.init(Database); + {{#if (subgraphPath)}} + const { graphWatcher } = await getGraphDbAndWatcher( + watchContractCmd.config!.server, + watchContractCmd.clients!.ethClient, + watchContractCmd.ethProvider!, + watchContractCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + {{/if}} + await watchContractCmd.initIndexer(Indexer{{#if (subgraphPath)}}, graphWatcher{{/if}}); await watchContractCmd.exec(); }; diff --git a/packages/eden-watcher/src/cli/checkpoint-cmds/create.ts b/packages/eden-watcher/src/cli/checkpoint-cmds/create.ts index 63f844ce..f2f1971d 100644 --- a/packages/eden-watcher/src/cli/checkpoint-cmds/create.ts +++ b/packages/eden-watcher/src/cli/checkpoint-cmds/create.ts @@ -3,8 +3,9 @@ // import { CreateCheckpointCmd } from '@cerc-io/cli'; +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; -import { Database } from '../../database'; +import { Database, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP } from '../../database'; import { Indexer } from '../../indexer'; export const command = 'create'; @@ -26,7 +27,17 @@ export const builder = { export const handler = async (argv: any): Promise => { const createCheckpointCmd = new CreateCheckpointCmd(); - await createCheckpointCmd.init(argv, Database, Indexer); + await createCheckpointCmd.init(argv, Database); + const { graphWatcher } = await getGraphDbAndWatcher( + createCheckpointCmd.config!.server, + createCheckpointCmd.clients!.ethClient, + createCheckpointCmd.ethProvider!, + createCheckpointCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + await createCheckpointCmd.initIndexer(Indexer, graphWatcher); await createCheckpointCmd.exec(); }; diff --git a/packages/eden-watcher/src/cli/checkpoint-cmds/verify.ts b/packages/eden-watcher/src/cli/checkpoint-cmds/verify.ts index 9513d719..3fdfda99 100644 --- a/packages/eden-watcher/src/cli/checkpoint-cmds/verify.ts +++ b/packages/eden-watcher/src/cli/checkpoint-cmds/verify.ts @@ -3,8 +3,9 @@ // import { VerifyCheckpointCmd } from '@cerc-io/cli'; +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; -import { Database } from '../../database'; +import { Database, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP } from '../../database'; import { Indexer } from '../../indexer'; export const command = 'verify'; @@ -22,7 +23,17 @@ export const builder = { export const handler = async (argv: any): Promise => { const verifyCheckpointCmd = new VerifyCheckpointCmd(); - await verifyCheckpointCmd.init(argv, Database, Indexer); + await verifyCheckpointCmd.init(argv, Database); - await verifyCheckpointCmd.exec(); + const { graphWatcher, graphDb } = await getGraphDbAndWatcher( + verifyCheckpointCmd.config!.server, + verifyCheckpointCmd.clients!.ethClient, + verifyCheckpointCmd.ethProvider!, + verifyCheckpointCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + await verifyCheckpointCmd.initIndexer(Indexer, graphWatcher); + await verifyCheckpointCmd.exec(graphDb); }; diff --git a/packages/eden-watcher/src/cli/export-state.ts b/packages/eden-watcher/src/cli/export-state.ts index 2411b960..3f6de118 100644 --- a/packages/eden-watcher/src/cli/export-state.ts +++ b/packages/eden-watcher/src/cli/export-state.ts @@ -6,16 +6,27 @@ import 'reflect-metadata'; import debug from 'debug'; import { ExportStateCmd } from '@cerc-io/cli'; +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; -import { Database } from '../database'; +import { Database, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP } from '../database'; import { Indexer } from '../indexer'; const log = debug('vulcanize:export-state'); const main = async (): Promise => { const exportStateCmd = new ExportStateCmd(); - await exportStateCmd.init(Database, Indexer); + await exportStateCmd.init(Database); + const { graphWatcher } = await getGraphDbAndWatcher( + exportStateCmd.config!.server, + exportStateCmd.clients!.ethClient, + exportStateCmd.ethProvider!, + exportStateCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + await exportStateCmd.initIndexer(Indexer, graphWatcher); await exportStateCmd.exec(); }; diff --git a/packages/eden-watcher/src/cli/import-state.ts b/packages/eden-watcher/src/cli/import-state.ts index 871f1b00..1b0368d9 100644 --- a/packages/eden-watcher/src/cli/import-state.ts +++ b/packages/eden-watcher/src/cli/import-state.ts @@ -6,8 +6,9 @@ import 'reflect-metadata'; import debug from 'debug'; import { ImportStateCmd } from '@cerc-io/cli'; +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; -import { Database } from '../database'; +import { Database, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP } from '../database'; import { Indexer } from '../indexer'; import { EventWatcher } from '../events'; import { State } from '../entity/State'; @@ -16,9 +17,19 @@ const log = debug('vulcanize:import-state'); export const main = async (): Promise => { const importStateCmd = new ImportStateCmd(); - await importStateCmd.init(Database, Indexer, EventWatcher); + await importStateCmd.init(Database); - await importStateCmd.exec(State); + const { graphWatcher, graphDb } = await getGraphDbAndWatcher( + importStateCmd.config!.server, + importStateCmd.clients!.ethClient, + importStateCmd.ethProvider!, + importStateCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + await importStateCmd.initIndexer(Indexer, EventWatcher, graphWatcher); + await importStateCmd.exec(State, graphDb); }; main().catch(err => { diff --git a/packages/eden-watcher/src/cli/index-block.ts b/packages/eden-watcher/src/cli/index-block.ts index 6b59df5e..78d4ec7b 100644 --- a/packages/eden-watcher/src/cli/index-block.ts +++ b/packages/eden-watcher/src/cli/index-block.ts @@ -6,16 +6,27 @@ import 'reflect-metadata'; import debug from 'debug'; import { IndexBlockCmd } from '@cerc-io/cli'; +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; -import { Database } from '../database'; +import { Database, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP } from '../database'; import { Indexer } from '../indexer'; const log = debug('vulcanize:index-block'); const main = async (): Promise => { const indexBlockCmd = new IndexBlockCmd(); - await indexBlockCmd.init(Database, Indexer); + await indexBlockCmd.init(Database); + const { graphWatcher } = await getGraphDbAndWatcher( + indexBlockCmd.config!.server, + indexBlockCmd.clients!.ethClient, + indexBlockCmd.ethProvider!, + indexBlockCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + await indexBlockCmd.initIndexer(Indexer, graphWatcher); await indexBlockCmd.exec(); }; diff --git a/packages/eden-watcher/src/cli/inspect-cid.ts b/packages/eden-watcher/src/cli/inspect-cid.ts index 3b1f44d7..2dc25314 100644 --- a/packages/eden-watcher/src/cli/inspect-cid.ts +++ b/packages/eden-watcher/src/cli/inspect-cid.ts @@ -6,16 +6,27 @@ import 'reflect-metadata'; import debug from 'debug'; import { InspectCIDCmd } from '@cerc-io/cli'; +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; -import { Database } from '../database'; +import { Database, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP } from '../database'; import { Indexer } from '../indexer'; const log = debug('vulcanize:inspect-cid'); const main = async (): Promise => { const inspectCIDCmd = new InspectCIDCmd(); - await inspectCIDCmd.init(Database, Indexer); + await inspectCIDCmd.init(Database); + const { graphWatcher } = await getGraphDbAndWatcher( + inspectCIDCmd.config!.server, + inspectCIDCmd.clients!.ethClient, + inspectCIDCmd.ethProvider!, + inspectCIDCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + await inspectCIDCmd.initIndexer(Indexer, graphWatcher); await inspectCIDCmd.exec(); }; diff --git a/packages/eden-watcher/src/cli/reset-cmds/watcher.ts b/packages/eden-watcher/src/cli/reset-cmds/watcher.ts index 295adc45..c0a92058 100644 --- a/packages/eden-watcher/src/cli/reset-cmds/watcher.ts +++ b/packages/eden-watcher/src/cli/reset-cmds/watcher.ts @@ -3,8 +3,9 @@ // import { ResetWatcherCmd } from '@cerc-io/cli'; +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; -import { Database } from '../../database'; +import { Database, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP } from '../../database'; import { Indexer } from '../../indexer'; export const command = 'watcher'; @@ -19,7 +20,17 @@ export const builder = { export const handler = async (argv: any): Promise => { const resetWatcherCmd = new ResetWatcherCmd(); - await resetWatcherCmd.init(argv, Database, Indexer); + await resetWatcherCmd.init(argv, Database); + const { graphWatcher, graphDb } = await getGraphDbAndWatcher( + resetWatcherCmd.config!.server, + resetWatcherCmd.clients!.ethClient, + resetWatcherCmd.ethProvider!, + resetWatcherCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + await resetWatcherCmd.initIndexer(Indexer, graphWatcher); await resetWatcherCmd.exec(); }; diff --git a/packages/eden-watcher/src/cli/watch-contract.ts b/packages/eden-watcher/src/cli/watch-contract.ts index bf1e7834..9b2291dc 100644 --- a/packages/eden-watcher/src/cli/watch-contract.ts +++ b/packages/eden-watcher/src/cli/watch-contract.ts @@ -6,16 +6,27 @@ import 'reflect-metadata'; import debug from 'debug'; import { WatchContractCmd } from '@cerc-io/cli'; +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; -import { Database } from '../database'; +import { Database, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP } from '../database'; import { Indexer } from '../indexer'; const log = debug('vulcanize:watch-contract'); const main = async (): Promise => { const watchContractCmd = new WatchContractCmd(); - await watchContractCmd.init(Database, Indexer); + await watchContractCmd.init(Database); + const { graphWatcher } = await getGraphDbAndWatcher( + watchContractCmd.config!.server, + watchContractCmd.clients!.ethClient, + watchContractCmd.ethProvider!, + watchContractCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + await watchContractCmd.initIndexer(Indexer, graphWatcher); await watchContractCmd.exec(); }; diff --git a/packages/eden-watcher/src/entity/Subscriber.ts b/packages/eden-watcher/src/entity/Subscriber.ts index 8a685533..2cccb841 100644 --- a/packages/eden-watcher/src/entity/Subscriber.ts +++ b/packages/eden-watcher/src/entity/Subscriber.ts @@ -4,7 +4,7 @@ import { EventSubscriber, EntitySubscriberInterface, InsertEvent, UpdateEvent } from 'typeorm'; -import { afterEntityInsertOrUpdate } from '@cerc-io/graph-node'; +import { afterEntityInsertOrUpdate } from '@cerc-io/util'; import { FrothyEntity } from './FrothyEntity'; import { ENTITY_TO_LATEST_ENTITY_MAP, SUBGRAPH_ENTITIES } from '../database'; diff --git a/packages/eden-watcher/src/fill.ts b/packages/eden-watcher/src/fill.ts index 1bd9d2f2..1971e4b5 100644 --- a/packages/eden-watcher/src/fill.ts +++ b/packages/eden-watcher/src/fill.ts @@ -7,7 +7,8 @@ import 'reflect-metadata'; import debug from 'debug'; import { FillCmd } from '@cerc-io/cli'; -import { getContractEntitiesMap } from '@cerc-io/graph-node'; +import { getContractEntitiesMap } from '@cerc-io/util'; +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; import { Database, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP } from './database'; import { Indexer } from './indexer'; @@ -17,15 +18,23 @@ const log = debug('vulcanize:fill'); export const main = async (): Promise => { const fillCmd = new FillCmd(); - await fillCmd.init(Database, Indexer, EventWatcher, {}, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP); + await fillCmd.init(Database); - const indexer = fillCmd.indexer as Indexer; - assert(indexer); + const { graphWatcher } = await getGraphDbAndWatcher( + fillCmd.config!.server, + fillCmd.clients!.ethClient, + fillCmd.ethProvider!, + fillCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + await fillCmd.initIndexer(Indexer, EventWatcher, graphWatcher); // Get contractEntitiesMap required for fill-state // NOTE: Assuming each entity type is only mapped to a single contract // This is true for eden subgraph; may not be the case for other subgraphs - const contractEntitiesMap = getContractEntitiesMap(indexer.graphWatcher.dataSources); + const contractEntitiesMap = getContractEntitiesMap(graphWatcher.dataSources); await fillCmd.exec(contractEntitiesMap); }; diff --git a/packages/eden-watcher/src/indexer.ts b/packages/eden-watcher/src/indexer.ts index da7eb6ac..790dd8e1 100644 --- a/packages/eden-watcher/src/indexer.ts +++ b/packages/eden-watcher/src/indexer.ts @@ -25,9 +25,12 @@ import { ResultEvent, getResultEvent, DatabaseInterface, - Clients + Clients, + GraphWatcherInterface, + updateSubgraphState, + dumpSubgraphState } from '@cerc-io/util'; -import { GraphWatcher, updateSubgraphState, dumpSubgraphState } from '@cerc-io/graph-node'; +import { GraphWatcher } from '@cerc-io/graph-node'; import { Database, ENTITIES, SUBGRAPH_ENTITIES } from './database'; import { Contract } from './entity/Contract'; @@ -79,7 +82,7 @@ export class Indexer implements IndexerInterface { _subgraphStateMap: Map - constructor (serverConfig: ServerConfig, db: DatabaseInterface, clients: Clients, ethProvider: BaseProvider, jobQueue: JobQueue, graphWatcher?: GraphWatcher) { + constructor (serverConfig: ServerConfig, db: DatabaseInterface, clients: Clients, ethProvider: BaseProvider, jobQueue: JobQueue, graphWatcher?: GraphWatcherInterface) { assert(db); assert(clients.ethClient); @@ -90,7 +93,7 @@ export class Indexer implements IndexerInterface { this._baseIndexer = new BaseIndexer(this._serverConfig, this._db, this._ethClient, this._ethProvider, jobQueue); assert(graphWatcher); - this._graphWatcher = graphWatcher; + this._graphWatcher = graphWatcher as GraphWatcher; this._abiMap = new Map(); this._storageLayoutMap = new Map(); diff --git a/packages/eden-watcher/src/job-runner.ts b/packages/eden-watcher/src/job-runner.ts index 77bb6b8a..9abbe64f 100644 --- a/packages/eden-watcher/src/job-runner.ts +++ b/packages/eden-watcher/src/job-runner.ts @@ -6,6 +6,7 @@ import debug from 'debug'; import { JobRunnerCmd } from '@cerc-io/cli'; import { JobRunner } from '@cerc-io/util'; +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; import { Indexer } from './indexer'; import { Database, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP } from './database'; @@ -14,7 +15,18 @@ const log = debug('vulcanize:job-runner'); export const main = async (): Promise => { const jobRunnerCmd = new JobRunnerCmd(); - await jobRunnerCmd.init(Database, Indexer, {}, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP); + await jobRunnerCmd.init(Database); + + const { graphWatcher } = await getGraphDbAndWatcher( + jobRunnerCmd.config!.server, + jobRunnerCmd.clients!.ethClient, + jobRunnerCmd.ethProvider!, + jobRunnerCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + await jobRunnerCmd.initIndexer(Indexer, graphWatcher); await jobRunnerCmd.exec(async (jobRunner: JobRunner): Promise => { await jobRunner.subscribeBlockProcessingQueue(); diff --git a/packages/eden-watcher/src/server.ts b/packages/eden-watcher/src/server.ts index 3d432ae3..43b4caea 100644 --- a/packages/eden-watcher/src/server.ts +++ b/packages/eden-watcher/src/server.ts @@ -8,6 +8,7 @@ import 'reflect-metadata'; import debug from 'debug'; import { ServerCmd } from '@cerc-io/cli'; +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; import { createResolvers } from './resolvers'; import { Indexer } from './indexer'; @@ -18,10 +19,20 @@ const log = debug('vulcanize:server'); export const main = async (): Promise => { const serverCmd = new ServerCmd(); - await serverCmd.init(Database, Indexer, EventWatcher, {}, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP); + await serverCmd.init(Database); + + const { graphWatcher } = await getGraphDbAndWatcher( + serverCmd.config!.server, + serverCmd.clients!.ethClient, + serverCmd.ethProvider!, + serverCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + await serverCmd.initIndexer(Indexer, EventWatcher, graphWatcher); const typeDefs = fs.readFileSync(path.join(__dirname, 'schema.gql')).toString(); - return serverCmd.exec(createResolvers, typeDefs); }; diff --git a/packages/erc20-watcher/src/cli/reset-cmds/watcher.ts b/packages/erc20-watcher/src/cli/reset-cmds/watcher.ts index 295adc45..2dfdd68c 100644 --- a/packages/erc20-watcher/src/cli/reset-cmds/watcher.ts +++ b/packages/erc20-watcher/src/cli/reset-cmds/watcher.ts @@ -19,7 +19,7 @@ export const builder = { export const handler = async (argv: any): Promise => { const resetWatcherCmd = new ResetWatcherCmd(); - await resetWatcherCmd.init(argv, Database, Indexer); - + await resetWatcherCmd.init(argv, Database); + await resetWatcherCmd.initIndexer(Indexer); await resetWatcherCmd.exec(); }; diff --git a/packages/erc20-watcher/src/cli/watch-contract.ts b/packages/erc20-watcher/src/cli/watch-contract.ts index bf1e7834..1934c09f 100644 --- a/packages/erc20-watcher/src/cli/watch-contract.ts +++ b/packages/erc20-watcher/src/cli/watch-contract.ts @@ -14,8 +14,8 @@ const log = debug('vulcanize:watch-contract'); const main = async (): Promise => { const watchContractCmd = new WatchContractCmd(); - await watchContractCmd.init(Database, Indexer); - + await watchContractCmd.init(Database); + await watchContractCmd.initIndexer(Indexer); await watchContractCmd.exec(); }; diff --git a/packages/erc20-watcher/src/fill.ts b/packages/erc20-watcher/src/fill.ts index c37485a1..f37755e1 100644 --- a/packages/erc20-watcher/src/fill.ts +++ b/packages/erc20-watcher/src/fill.ts @@ -15,8 +15,8 @@ const log = debug('vulcanize:fill'); export const main = async (): Promise => { const fillCmd = new FillCmd(); - await fillCmd.init(Database, Indexer, EventWatcher); - + await fillCmd.init(Database); + await fillCmd.initIndexer(Indexer, EventWatcher); await fillCmd.exec(); }; diff --git a/packages/erc20-watcher/src/job-runner.ts b/packages/erc20-watcher/src/job-runner.ts index 239da068..16c58d8d 100644 --- a/packages/erc20-watcher/src/job-runner.ts +++ b/packages/erc20-watcher/src/job-runner.ts @@ -14,7 +14,8 @@ const log = debug('vulcanize:job-runner'); export const main = async (): Promise => { const jobRunnerCmd = new JobRunnerCmd(); - await jobRunnerCmd.init(Database, Indexer); + await jobRunnerCmd.init(Database); + await jobRunnerCmd.initIndexer(Indexer); await jobRunnerCmd.exec(async (jobRunner: JobRunner): Promise => { await jobRunner.subscribeBlockProcessingQueue(); diff --git a/packages/erc20-watcher/src/server.ts b/packages/erc20-watcher/src/server.ts index cb9d3151..692b85a9 100644 --- a/packages/erc20-watcher/src/server.ts +++ b/packages/erc20-watcher/src/server.ts @@ -2,6 +2,9 @@ // Copyright 2021 Vulcanize, Inc. // +import fs from 'fs'; +import path from 'path'; +import 'reflect-metadata'; import debug from 'debug'; import { ServerCmd } from '@cerc-io/cli'; @@ -16,7 +19,8 @@ const log = debug('vulcanize:server'); export const main = async (): Promise => { const serverCmd = new ServerCmd(); - await serverCmd.init(Database, Indexer, EventWatcher); + await serverCmd.init(Database); + await serverCmd.initIndexer(Indexer, EventWatcher); return serverCmd.exec(createResolvers, typeDefs); }; diff --git a/packages/erc721-watcher/src/cli/checkpoint-cmds/create.ts b/packages/erc721-watcher/src/cli/checkpoint-cmds/create.ts index 63f844ce..75b09ba9 100644 --- a/packages/erc721-watcher/src/cli/checkpoint-cmds/create.ts +++ b/packages/erc721-watcher/src/cli/checkpoint-cmds/create.ts @@ -26,7 +26,7 @@ export const builder = { export const handler = async (argv: any): Promise => { const createCheckpointCmd = new CreateCheckpointCmd(); - await createCheckpointCmd.init(argv, Database, Indexer); - + await createCheckpointCmd.init(argv, Database); + await createCheckpointCmd.initIndexer(Indexer); await createCheckpointCmd.exec(); }; diff --git a/packages/erc721-watcher/src/cli/export-state.ts b/packages/erc721-watcher/src/cli/export-state.ts index 2411b960..5a9bbcfb 100644 --- a/packages/erc721-watcher/src/cli/export-state.ts +++ b/packages/erc721-watcher/src/cli/export-state.ts @@ -14,8 +14,8 @@ const log = debug('vulcanize:export-state'); const main = async (): Promise => { const exportStateCmd = new ExportStateCmd(); - await exportStateCmd.init(Database, Indexer); - + await exportStateCmd.init(Database); + await exportStateCmd.initIndexer(Indexer); await exportStateCmd.exec(); }; diff --git a/packages/erc721-watcher/src/cli/import-state.ts b/packages/erc721-watcher/src/cli/import-state.ts index 871f1b00..8980144e 100644 --- a/packages/erc721-watcher/src/cli/import-state.ts +++ b/packages/erc721-watcher/src/cli/import-state.ts @@ -16,8 +16,8 @@ const log = debug('vulcanize:import-state'); export const main = async (): Promise => { const importStateCmd = new ImportStateCmd(); - await importStateCmd.init(Database, Indexer, EventWatcher); - + await importStateCmd.init(Database); + await importStateCmd.initIndexer(Indexer, EventWatcher); await importStateCmd.exec(State); }; diff --git a/packages/erc721-watcher/src/cli/index-block.ts b/packages/erc721-watcher/src/cli/index-block.ts index 6b59df5e..fab95b2c 100644 --- a/packages/erc721-watcher/src/cli/index-block.ts +++ b/packages/erc721-watcher/src/cli/index-block.ts @@ -14,8 +14,8 @@ const log = debug('vulcanize:index-block'); const main = async (): Promise => { const indexBlockCmd = new IndexBlockCmd(); - await indexBlockCmd.init(Database, Indexer); - + await indexBlockCmd.init(Database); + await indexBlockCmd.initIndexer(Indexer); await indexBlockCmd.exec(); }; diff --git a/packages/erc721-watcher/src/cli/inspect-cid.ts b/packages/erc721-watcher/src/cli/inspect-cid.ts index 3b1f44d7..d708a1b3 100644 --- a/packages/erc721-watcher/src/cli/inspect-cid.ts +++ b/packages/erc721-watcher/src/cli/inspect-cid.ts @@ -14,8 +14,8 @@ const log = debug('vulcanize:inspect-cid'); const main = async (): Promise => { const inspectCIDCmd = new InspectCIDCmd(); - await inspectCIDCmd.init(Database, Indexer); - + await inspectCIDCmd.init(Database); + await inspectCIDCmd.initIndexer(Indexer); await inspectCIDCmd.exec(); }; diff --git a/packages/erc721-watcher/src/cli/reset-cmds/watcher.ts b/packages/erc721-watcher/src/cli/reset-cmds/watcher.ts index 295adc45..2dfdd68c 100644 --- a/packages/erc721-watcher/src/cli/reset-cmds/watcher.ts +++ b/packages/erc721-watcher/src/cli/reset-cmds/watcher.ts @@ -19,7 +19,7 @@ export const builder = { export const handler = async (argv: any): Promise => { const resetWatcherCmd = new ResetWatcherCmd(); - await resetWatcherCmd.init(argv, Database, Indexer); - + await resetWatcherCmd.init(argv, Database); + await resetWatcherCmd.initIndexer(Indexer); await resetWatcherCmd.exec(); }; diff --git a/packages/erc721-watcher/src/cli/watch-contract.ts b/packages/erc721-watcher/src/cli/watch-contract.ts index bf1e7834..1934c09f 100644 --- a/packages/erc721-watcher/src/cli/watch-contract.ts +++ b/packages/erc721-watcher/src/cli/watch-contract.ts @@ -14,8 +14,8 @@ const log = debug('vulcanize:watch-contract'); const main = async (): Promise => { const watchContractCmd = new WatchContractCmd(); - await watchContractCmd.init(Database, Indexer); - + await watchContractCmd.init(Database); + await watchContractCmd.initIndexer(Indexer); await watchContractCmd.exec(); }; diff --git a/packages/erc721-watcher/src/fill.ts b/packages/erc721-watcher/src/fill.ts index 75d2c508..4c0eaead 100644 --- a/packages/erc721-watcher/src/fill.ts +++ b/packages/erc721-watcher/src/fill.ts @@ -15,8 +15,9 @@ const log = debug('vulcanize:fill'); export const main = async (): Promise => { const fillCmd = new FillCmd(); - await fillCmd.init(Database, Indexer, EventWatcher); + await fillCmd.init(Database); + await fillCmd.initIndexer(Indexer, EventWatcher); await fillCmd.exec(); }; diff --git a/packages/erc721-watcher/src/job-runner.ts b/packages/erc721-watcher/src/job-runner.ts index 703c4397..92e57187 100644 --- a/packages/erc721-watcher/src/job-runner.ts +++ b/packages/erc721-watcher/src/job-runner.ts @@ -14,7 +14,8 @@ const log = debug('vulcanize:job-runner'); export const main = async (): Promise => { const jobRunnerCmd = new JobRunnerCmd(); - await jobRunnerCmd.init(Database, Indexer); + await jobRunnerCmd.init(Database); + await jobRunnerCmd.initIndexer(Indexer); await jobRunnerCmd.exec(async (jobRunner: JobRunner): Promise => { await jobRunner.subscribeBlockProcessingQueue(); diff --git a/packages/erc721-watcher/src/server.ts b/packages/erc721-watcher/src/server.ts index 20915d12..35a6240a 100644 --- a/packages/erc721-watcher/src/server.ts +++ b/packages/erc721-watcher/src/server.ts @@ -18,10 +18,10 @@ const log = debug('vulcanize:server'); export const main = async (): Promise => { const serverCmd = new ServerCmd(); - await serverCmd.init(Database, Indexer, EventWatcher); + await serverCmd.init(Database); + await serverCmd.initIndexer(Indexer, EventWatcher); const typeDefs = fs.readFileSync(path.join(__dirname, 'schema.gql')).toString(); - return serverCmd.exec(createResolvers, typeDefs); }; diff --git a/packages/graph-node/src/call-handler.test.ts b/packages/graph-node/src/call-handler.test.ts index 089ec16d..4bd9214d 100644 --- a/packages/graph-node/src/call-handler.test.ts +++ b/packages/graph-node/src/call-handler.test.ts @@ -8,12 +8,11 @@ import spies from 'chai-spies'; import { utils } from 'ethers'; import { BaseProvider } from '@ethersproject/providers'; +import { GraphDatabase, createEvent, createBlock, Block, EventData } from '@cerc-io/util'; import { getDummyEventData, getDummyGraphData, getTestDatabase, getTestIndexer, getTestProvider } from '../test/utils'; import abi from '../test/subgraph/example1/build/Example1/abis/Example1.json'; import { instantiate } from './loader'; -import { createEvent, createBlock, Block, EventData } from './utils'; -import { Database } from './database'; import { Indexer } from '../test/utils/indexer'; chai.use(spies); @@ -22,7 +21,7 @@ const sandbox = chai.spy.sandbox(); xdescribe('call handler in mapping code', () => { let exports: any; - let db: Database; + let db: GraphDatabase; let indexer: Indexer; let provider: BaseProvider; diff --git a/packages/graph-node/src/cli/compare/compare-blocks.ts b/packages/graph-node/src/cli/compare/compare-blocks.ts index d63f54a1..62b9cb47 100644 --- a/packages/graph-node/src/cli/compare/compare-blocks.ts +++ b/packages/graph-node/src/cli/compare/compare-blocks.ts @@ -8,7 +8,15 @@ import debug from 'debug'; import path from 'path'; import assert from 'assert'; import { SnakeNamingStrategy } from 'typeorm-naming-strategies'; -import { getConfig as getWatcherConfig, wait, Database as BaseDatabase, Config as WatcherConfig } from '@cerc-io/util'; + +import { + getConfig as getWatcherConfig, + wait, + Database as BaseDatabase, + Config as WatcherConfig, + GraphDatabase, + getSubgraphConfig +} from '@cerc-io/util'; import { GraphQLClient } from '@cerc-io/ipld-eth-client'; import { @@ -22,8 +30,6 @@ import { getConfig, checkGQLEntitiesInState } from './utils'; -import { Database } from '../../database'; -import { getSubgraphConfig } from '../../utils'; const DEFAULT_ENTITIES_LIMIT = 100; @@ -116,7 +122,7 @@ export const main = async (): Promise => { let blockDelay = wait(0); let subgraphContracts: string[] = []; const contractLatestStateCIDMap: Map = new Map(); - let db: Database | undefined, subgraphGQLClient: GraphQLClient | undefined; + let db: GraphDatabase | undefined, subgraphGQLClient: GraphQLClient | undefined; if (config.watcher) { const watcherConfigPath = path.resolve(path.dirname(configFile), config.watcher.configPath); @@ -126,7 +132,7 @@ export const main = async (): Promise => { const baseDatabase = new BaseDatabase({ ...watcherConfig.database, entities: [entitiesDir] }); await baseDatabase.init(); - db = new Database(watcherConfig.server, baseDatabase); + db = new GraphDatabase(watcherConfig.server, baseDatabase); await db.init(); if (config.watcher.verifyState) { diff --git a/packages/graph-node/src/cli/compare/utils.ts b/packages/graph-node/src/cli/compare/utils.ts index c617fffc..e79cb432 100644 --- a/packages/graph-node/src/cli/compare/utils.ts +++ b/packages/graph-node/src/cli/compare/utils.ts @@ -15,9 +15,9 @@ import debug from 'debug'; import { Config as CacheConfig, getCache } from '@cerc-io/cache'; import { GraphQLClient } from '@cerc-io/ipld-eth-client'; import { gql } from '@apollo/client/core'; +import { DEFAULT_LIMIT } from '@cerc-io/util'; import { Client } from './client'; -import { DEFAULT_LIMIT } from '../../database'; const log = debug('vulcanize:compare-utils'); diff --git a/packages/graph-node/src/crypto.test.ts b/packages/graph-node/src/crypto.test.ts index 6d8334ca..80f4e584 100644 --- a/packages/graph-node/src/crypto.test.ts +++ b/packages/graph-node/src/crypto.test.ts @@ -7,15 +7,15 @@ import { expect } from 'chai'; import { utils } from 'ethers'; import { BaseProvider } from '@ethersproject/providers'; +import { GraphDatabase } from '@cerc-io/util'; import { instantiate } from './loader'; import { getDummyGraphData, getTestDatabase, getTestIndexer, getTestProvider } from '../test/utils'; -import { Database } from './database'; import { Indexer } from '../test/utils/indexer'; describe('crypto host api', () => { let exports: any; - let db: Database; + let db: GraphDatabase; let indexer: Indexer; let provider: BaseProvider; diff --git a/packages/graph-node/src/eden.test.ts b/packages/graph-node/src/eden.test.ts index 9348b718..7f3d9628 100644 --- a/packages/graph-node/src/eden.test.ts +++ b/packages/graph-node/src/eden.test.ts @@ -9,14 +9,13 @@ import chai from 'chai'; import spies from 'chai-spies'; import { BaseProvider } from '@ethersproject/providers'; +import { GraphDatabase, createEvent, Block, createBlock, EventData } from '@cerc-io/util'; import { instantiate } from './loader'; -import { createEvent, Block, createBlock, EventData } from './utils'; import edenNetworkAbi from '../test/subgraph/eden/EdenNetwork/abis/EdenNetwork.json'; import merkleDistributorAbi from '../test/subgraph/eden/EdenNetworkDistribution/abis/MerkleDistributor.json'; import distributorGovernanceAbi from '../test/subgraph/eden/EdenNetworkGovernance/abis/DistributorGovernance.json'; import { getDummyEventData, getTestDatabase, getTestIndexer, getTestProvider } from '../test/utils'; -import { Database } from './database'; import { Indexer } from '../test/utils/indexer'; const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; @@ -26,7 +25,7 @@ chai.use(spies); const sandbox = chai.spy.sandbox(); xdescribe('eden wasm loader tests', async () => { - let db: Database; + let db: GraphDatabase; let indexer: Indexer; let provider: BaseProvider; diff --git a/packages/graph-node/src/eth-abi.test.ts b/packages/graph-node/src/eth-abi.test.ts index 4078bb4c..f59d1534 100644 --- a/packages/graph-node/src/eth-abi.test.ts +++ b/packages/graph-node/src/eth-abi.test.ts @@ -6,15 +6,15 @@ import path from 'path'; import { expect } from 'chai'; import { BaseProvider } from '@ethersproject/providers'; +import { GraphDatabase } from '@cerc-io/util'; import { instantiate } from './loader'; import { getDummyGraphData, getTestDatabase, getTestIndexer, getTestProvider } from '../test/utils'; -import { Database } from './database'; import { Indexer } from '../test/utils/indexer'; describe('ethereum ABI encode decode', () => { let exports: any; - let db: Database; + let db: GraphDatabase; let indexer: Indexer; let provider: BaseProvider; let encoded: string; diff --git a/packages/graph-node/src/eth-call.test.ts b/packages/graph-node/src/eth-call.test.ts index 2151dee6..700612fe 100644 --- a/packages/graph-node/src/eth-call.test.ts +++ b/packages/graph-node/src/eth-call.test.ts @@ -6,17 +6,16 @@ import assert from 'assert'; import path from 'path'; import { BaseProvider } from '@ethersproject/providers'; +import { GraphDatabase, EventData } from '@cerc-io/util'; import { instantiate } from './loader'; import exampleAbi from '../test/subgraph/example1/build/Example1/abis/Example1.json'; import { getTestDatabase, getTestIndexer, getTestProvider, getDummyEventData } from '../test/utils'; -import { Database } from './database'; import { Indexer } from '../test/utils/indexer'; -import { EventData } from './utils'; xdescribe('eth-call wasm tests', () => { let exports: any; - let db: Database; + let db: GraphDatabase; let indexer: Indexer; let provider: BaseProvider; diff --git a/packages/graph-node/src/index.ts b/packages/graph-node/src/index.ts index 4103d004..ed6bf4cd 100644 --- a/packages/graph-node/src/index.ts +++ b/packages/graph-node/src/index.ts @@ -1,7 +1 @@ export * from './watcher'; -export * from './database'; -export { - resolveEntityFieldConflicts, - afterEntityInsertOrUpdate -} from './utils'; -export * from './state-utils'; diff --git a/packages/graph-node/src/json.test.ts b/packages/graph-node/src/json.test.ts index 515002f3..7bb0fe2f 100644 --- a/packages/graph-node/src/json.test.ts +++ b/packages/graph-node/src/json.test.ts @@ -5,15 +5,15 @@ import path from 'path'; import { BaseProvider } from '@ethersproject/providers'; +import { GraphDatabase } from '@cerc-io/util'; import { instantiate } from './loader'; import { getDummyGraphData, getTestDatabase, getTestIndexer, getTestProvider } from '../test/utils'; -import { Database } from './database'; import { Indexer } from '../test/utils/indexer'; describe('json host api', () => { let exports: any; - let db: Database; + let db: GraphDatabase; let indexer: Indexer; let provider: BaseProvider; diff --git a/packages/graph-node/src/loader.test.ts b/packages/graph-node/src/loader.test.ts index a12ada90..e5bc4f2f 100644 --- a/packages/graph-node/src/loader.test.ts +++ b/packages/graph-node/src/loader.test.ts @@ -7,17 +7,17 @@ import { expect } from 'chai'; import { utils } from 'ethers'; import { BaseProvider } from '@ethersproject/providers'; +import { GraphDatabase } from '@cerc-io/util'; import { instantiate } from './loader'; import { getDummyGraphData, getTestDatabase, getTestIndexer, getTestProvider } from '../test/utils'; -import { Database } from './database'; import { Indexer } from '../test/utils/indexer'; const WASM_FILE_PATH = '../build/debug.wasm'; describe('wasm loader tests', () => { let exports: any; - let db: Database; + let db: GraphDatabase; let indexer: Indexer; let provider: BaseProvider; let module: WebAssembly.Module; diff --git a/packages/graph-node/src/loader.ts b/packages/graph-node/src/loader.ts index 70ef1c14..b558bf05 100644 --- a/packages/graph-node/src/loader.ts +++ b/packages/graph-node/src/loader.ts @@ -15,19 +15,21 @@ import debug from 'debug'; import { BaseProvider } from '@ethersproject/providers'; import loader from '@vulcanize/assemblyscript/lib/loader'; -import { IndexerInterface, GraphDecimal, getGraphDigitsAndExp } from '@cerc-io/util'; - -import { TypeId, Level } from './types'; import { + IndexerInterface, + GraphDecimal, + getGraphDigitsAndExp, + prepareEntityState, + TypeId, + Level, + GraphDatabase, Block, fromEthereumValue, toEthereumValue, getEthereumTypes, jsonFromBytes, getStorageValueType -} from './utils'; -import { prepareEntityState } from './state-utils'; -import { Database } from './database'; +} from '@cerc-io/util'; // Endianness of BN used in bigInt store host API. // Negative bigInt is being stored in wasm in 2's compliment, 'le' representation. @@ -52,7 +54,7 @@ export interface Context { const log = debug('vulcanize:graph-node'); export const instantiate = async ( - database: Database, + database: GraphDatabase, indexer: IndexerInterface, provider: BaseProvider, context: Context, diff --git a/packages/graph-node/src/numbers.test.ts b/packages/graph-node/src/numbers.test.ts index 6b58d903..1350d5aa 100644 --- a/packages/graph-node/src/numbers.test.ts +++ b/packages/graph-node/src/numbers.test.ts @@ -6,14 +6,9 @@ import path from 'path'; import { expect } from 'chai'; import BN from 'bn.js'; -import { GraphDecimal } from '@cerc-io/util'; -import { BaseProvider } from '@ethersproject/providers'; - -import { instantiate } from './loader'; -import { getDummyGraphData, getTestDatabase, getTestIndexer, getTestProvider } from '../test/utils'; -import { Database } from './database'; -import { Indexer } from '../test/utils/indexer'; import { + GraphDecimal, + GraphDatabase, UINT128_MAX, UINT256_MAX, INT256_MIN, @@ -22,13 +17,18 @@ import { DECIMAL128_MAX, DECIMAL128_PMIN, DECIMAL128_NMAX -} from './utils'; +} from '@cerc-io/util'; +import { BaseProvider } from '@ethersproject/providers'; + +import { instantiate } from './loader'; +import { getDummyGraphData, getTestDatabase, getTestIndexer, getTestProvider } from '../test/utils'; +import { Indexer } from '../test/utils/indexer'; const EXAMPLE_WASM_FILE_PATH = '../test/subgraph/example1/build/Example1/Example1.wasm'; describe('numbers wasm tests', () => { let exports: any; - let db: Database; + let db: GraphDatabase; let indexer: Indexer; let provider: BaseProvider; diff --git a/packages/graph-node/src/storage-call.test.ts b/packages/graph-node/src/storage-call.test.ts index 91c0199e..eafb5c77 100644 --- a/packages/graph-node/src/storage-call.test.ts +++ b/packages/graph-node/src/storage-call.test.ts @@ -6,18 +6,17 @@ import assert from 'assert'; import path from 'path'; import { BaseProvider } from '@ethersproject/providers'; +import { GraphDatabase, EventData } from '@cerc-io/util'; import { instantiate } from './loader'; import exampleAbi from '../test/subgraph/example1/build/Example1/abis/Example1.json'; import { storageLayout } from '../test/artifacts/Example1.json'; import { getTestDatabase, getTestIndexer, getTestProvider, getDummyEventData } from '../test/utils'; -import { Database } from './database'; import { Indexer } from '../test/utils/indexer'; -import { EventData } from './utils'; xdescribe('storage-call wasm tests', () => { let exports: any; - let db: Database; + let db: GraphDatabase; let indexer: Indexer; let provider: BaseProvider; diff --git a/packages/graph-node/src/type-conversion.test.ts b/packages/graph-node/src/type-conversion.test.ts index 03e6e618..6d9cbce0 100644 --- a/packages/graph-node/src/type-conversion.test.ts +++ b/packages/graph-node/src/type-conversion.test.ts @@ -7,17 +7,17 @@ import { expect } from 'chai'; import { utils, BigNumber } from 'ethers'; import { BaseProvider } from '@ethersproject/providers'; +import { GraphDatabase } from '@cerc-io/util'; import { instantiate } from './loader'; import { getDummyGraphData, getTestDatabase, getTestIndexer, getTestProvider } from '../test/utils'; -import { Database } from './database'; import { Indexer } from '../test/utils/indexer'; const EXAMPLE_WASM_FILE_PATH = '../test/subgraph/example1/build/Example1/Example1.wasm'; describe('typeConversion wasm tests', () => { let exports: any; - let db: Database; + let db: GraphDatabase; let indexer: Indexer; let provider: BaseProvider; diff --git a/packages/graph-node/src/watcher.ts b/packages/graph-node/src/watcher.ts index 938a4ddc..835f3538 100644 --- a/packages/graph-node/src/watcher.ts +++ b/packages/graph-node/src/watcher.ts @@ -12,11 +12,25 @@ import { SelectionNode } from 'graphql'; import { ResultObject } from '@vulcanize/assemblyscript/lib/loader'; import { EthClient } from '@cerc-io/ipld-eth-client'; -import { getFullBlock, BlockHeight, ServerConfig, getFullTransaction, QueryOptions, IndexerInterface, BlockProgressInterface } from '@cerc-io/util'; +import { + getFullBlock, + BlockHeight, + ServerConfig, + getFullTransaction, + QueryOptions, + IndexerInterface, + BlockProgressInterface, + Database as BaseDatabase, + GraphDatabase, + resolveEntityFieldConflicts, + createBlock, + createEvent, + getSubgraphConfig, + Transaction, + DEFAULT_LIMIT +} from '@cerc-io/util'; -import { createBlock, createEvent, getSubgraphConfig, resolveEntityFieldConflicts, Transaction } from './utils'; import { Context, GraphData, instantiate } from './loader'; -import { Database, DEFAULT_LIMIT } from './database'; const log = debug('vulcanize:graph-watcher'); @@ -27,7 +41,7 @@ interface DataSource { } export class GraphWatcher { - _database: Database; + _database: GraphDatabase; _indexer?: IndexerInterface; _ethClient: EthClient; _ethProvider: providers.BaseProvider; @@ -39,7 +53,7 @@ export class GraphWatcher { _context: Context = {}; - constructor (database: Database, ethClient: EthClient, ethProvider: providers.BaseProvider, serverConfig: ServerConfig) { + constructor (database: GraphDatabase, ethClient: EthClient, ethProvider: providers.BaseProvider, serverConfig: ServerConfig) { this._database = database; this._ethClient = ethClient; this._ethProvider = ethProvider; @@ -462,3 +476,22 @@ export class GraphWatcher { return transaction; } } + +export const getGraphDbAndWatcher = async ( + serverConfig: ServerConfig, + ethClient: EthClient, + ethProvider: providers.BaseProvider, + baseDatabase: BaseDatabase, + entityQueryTypeMap?: Map, + entityToLatestEntityMap?: Map +): Promise<{ graphDb: GraphDatabase, graphWatcher: GraphWatcher }> => { + const graphDb = new GraphDatabase(serverConfig, baseDatabase, entityQueryTypeMap, entityToLatestEntityMap); + await graphDb.init(); + + const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, serverConfig); + + return { + graphDb, + graphWatcher + }; +}; diff --git a/packages/graph-node/test/utils/index.ts b/packages/graph-node/test/utils/index.ts index fdcaeb10..bdab033a 100644 --- a/packages/graph-node/test/utils/index.ts +++ b/packages/graph-node/test/utils/index.ts @@ -3,12 +3,10 @@ // import { BaseProvider } from '@ethersproject/providers'; -import { getCustomProvider, Database as BaseDatabase, ServerConfig } from '@cerc-io/util'; +import { getCustomProvider, Database as BaseDatabase, ServerConfig, GraphDatabase, EventData } from '@cerc-io/util'; import { EthClient } from '@cerc-io/ipld-eth-client'; import { StorageLayout } from '@cerc-io/solidity-mapper'; -import { EventData } from '../../src/utils'; -import { Database } from '../../src/database'; import { Indexer } from './indexer'; const NETWORK_URL = 'http://127.0.0.1:8081'; @@ -70,10 +68,10 @@ export const getDummyGraphData = (): any => { }; }; -export const getTestDatabase = (): Database => { +export const getTestDatabase = (): GraphDatabase => { const baseDatabase = new BaseDatabase({ type: 'postgres' }); const serverConfig = {} as ServerConfig; - return new Database(serverConfig, baseDatabase); + return new GraphDatabase(serverConfig, baseDatabase); }; export const getTestIndexer = (storageLayout?: Map): Indexer => { diff --git a/packages/graph-test-watcher/src/cli/checkpoint-cmds/create.ts b/packages/graph-test-watcher/src/cli/checkpoint-cmds/create.ts index 63f844ce..f2f1971d 100644 --- a/packages/graph-test-watcher/src/cli/checkpoint-cmds/create.ts +++ b/packages/graph-test-watcher/src/cli/checkpoint-cmds/create.ts @@ -3,8 +3,9 @@ // import { CreateCheckpointCmd } from '@cerc-io/cli'; +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; -import { Database } from '../../database'; +import { Database, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP } from '../../database'; import { Indexer } from '../../indexer'; export const command = 'create'; @@ -26,7 +27,17 @@ export const builder = { export const handler = async (argv: any): Promise => { const createCheckpointCmd = new CreateCheckpointCmd(); - await createCheckpointCmd.init(argv, Database, Indexer); + await createCheckpointCmd.init(argv, Database); + const { graphWatcher } = await getGraphDbAndWatcher( + createCheckpointCmd.config!.server, + createCheckpointCmd.clients!.ethClient, + createCheckpointCmd.ethProvider!, + createCheckpointCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + await createCheckpointCmd.initIndexer(Indexer, graphWatcher); await createCheckpointCmd.exec(); }; diff --git a/packages/graph-test-watcher/src/cli/checkpoint-cmds/verify.ts b/packages/graph-test-watcher/src/cli/checkpoint-cmds/verify.ts index 9513d719..3fdfda99 100644 --- a/packages/graph-test-watcher/src/cli/checkpoint-cmds/verify.ts +++ b/packages/graph-test-watcher/src/cli/checkpoint-cmds/verify.ts @@ -3,8 +3,9 @@ // import { VerifyCheckpointCmd } from '@cerc-io/cli'; +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; -import { Database } from '../../database'; +import { Database, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP } from '../../database'; import { Indexer } from '../../indexer'; export const command = 'verify'; @@ -22,7 +23,17 @@ export const builder = { export const handler = async (argv: any): Promise => { const verifyCheckpointCmd = new VerifyCheckpointCmd(); - await verifyCheckpointCmd.init(argv, Database, Indexer); + await verifyCheckpointCmd.init(argv, Database); - await verifyCheckpointCmd.exec(); + const { graphWatcher, graphDb } = await getGraphDbAndWatcher( + verifyCheckpointCmd.config!.server, + verifyCheckpointCmd.clients!.ethClient, + verifyCheckpointCmd.ethProvider!, + verifyCheckpointCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + await verifyCheckpointCmd.initIndexer(Indexer, graphWatcher); + await verifyCheckpointCmd.exec(graphDb); }; diff --git a/packages/graph-test-watcher/src/cli/export-state.ts b/packages/graph-test-watcher/src/cli/export-state.ts index 2411b960..3f6de118 100644 --- a/packages/graph-test-watcher/src/cli/export-state.ts +++ b/packages/graph-test-watcher/src/cli/export-state.ts @@ -6,16 +6,27 @@ import 'reflect-metadata'; import debug from 'debug'; import { ExportStateCmd } from '@cerc-io/cli'; +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; -import { Database } from '../database'; +import { Database, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP } from '../database'; import { Indexer } from '../indexer'; const log = debug('vulcanize:export-state'); const main = async (): Promise => { const exportStateCmd = new ExportStateCmd(); - await exportStateCmd.init(Database, Indexer); + await exportStateCmd.init(Database); + const { graphWatcher } = await getGraphDbAndWatcher( + exportStateCmd.config!.server, + exportStateCmd.clients!.ethClient, + exportStateCmd.ethProvider!, + exportStateCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + await exportStateCmd.initIndexer(Indexer, graphWatcher); await exportStateCmd.exec(); }; diff --git a/packages/graph-test-watcher/src/cli/import-state.ts b/packages/graph-test-watcher/src/cli/import-state.ts index 871f1b00..1b0368d9 100644 --- a/packages/graph-test-watcher/src/cli/import-state.ts +++ b/packages/graph-test-watcher/src/cli/import-state.ts @@ -6,8 +6,9 @@ import 'reflect-metadata'; import debug from 'debug'; import { ImportStateCmd } from '@cerc-io/cli'; +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; -import { Database } from '../database'; +import { Database, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP } from '../database'; import { Indexer } from '../indexer'; import { EventWatcher } from '../events'; import { State } from '../entity/State'; @@ -16,9 +17,19 @@ const log = debug('vulcanize:import-state'); export const main = async (): Promise => { const importStateCmd = new ImportStateCmd(); - await importStateCmd.init(Database, Indexer, EventWatcher); + await importStateCmd.init(Database); - await importStateCmd.exec(State); + const { graphWatcher, graphDb } = await getGraphDbAndWatcher( + importStateCmd.config!.server, + importStateCmd.clients!.ethClient, + importStateCmd.ethProvider!, + importStateCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + await importStateCmd.initIndexer(Indexer, EventWatcher, graphWatcher); + await importStateCmd.exec(State, graphDb); }; main().catch(err => { diff --git a/packages/graph-test-watcher/src/cli/index-block.ts b/packages/graph-test-watcher/src/cli/index-block.ts index 6b59df5e..78d4ec7b 100644 --- a/packages/graph-test-watcher/src/cli/index-block.ts +++ b/packages/graph-test-watcher/src/cli/index-block.ts @@ -6,16 +6,27 @@ import 'reflect-metadata'; import debug from 'debug'; import { IndexBlockCmd } from '@cerc-io/cli'; +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; -import { Database } from '../database'; +import { Database, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP } from '../database'; import { Indexer } from '../indexer'; const log = debug('vulcanize:index-block'); const main = async (): Promise => { const indexBlockCmd = new IndexBlockCmd(); - await indexBlockCmd.init(Database, Indexer); + await indexBlockCmd.init(Database); + const { graphWatcher } = await getGraphDbAndWatcher( + indexBlockCmd.config!.server, + indexBlockCmd.clients!.ethClient, + indexBlockCmd.ethProvider!, + indexBlockCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + await indexBlockCmd.initIndexer(Indexer, graphWatcher); await indexBlockCmd.exec(); }; diff --git a/packages/graph-test-watcher/src/cli/inspect-cid.ts b/packages/graph-test-watcher/src/cli/inspect-cid.ts index 3b1f44d7..2dc25314 100644 --- a/packages/graph-test-watcher/src/cli/inspect-cid.ts +++ b/packages/graph-test-watcher/src/cli/inspect-cid.ts @@ -6,16 +6,27 @@ import 'reflect-metadata'; import debug from 'debug'; import { InspectCIDCmd } from '@cerc-io/cli'; +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; -import { Database } from '../database'; +import { Database, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP } from '../database'; import { Indexer } from '../indexer'; const log = debug('vulcanize:inspect-cid'); const main = async (): Promise => { const inspectCIDCmd = new InspectCIDCmd(); - await inspectCIDCmd.init(Database, Indexer); + await inspectCIDCmd.init(Database); + const { graphWatcher } = await getGraphDbAndWatcher( + inspectCIDCmd.config!.server, + inspectCIDCmd.clients!.ethClient, + inspectCIDCmd.ethProvider!, + inspectCIDCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + await inspectCIDCmd.initIndexer(Indexer, graphWatcher); await inspectCIDCmd.exec(); }; diff --git a/packages/graph-test-watcher/src/cli/reset-cmds/watcher.ts b/packages/graph-test-watcher/src/cli/reset-cmds/watcher.ts index 295adc45..c0a92058 100644 --- a/packages/graph-test-watcher/src/cli/reset-cmds/watcher.ts +++ b/packages/graph-test-watcher/src/cli/reset-cmds/watcher.ts @@ -3,8 +3,9 @@ // import { ResetWatcherCmd } from '@cerc-io/cli'; +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; -import { Database } from '../../database'; +import { Database, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP } from '../../database'; import { Indexer } from '../../indexer'; export const command = 'watcher'; @@ -19,7 +20,17 @@ export const builder = { export const handler = async (argv: any): Promise => { const resetWatcherCmd = new ResetWatcherCmd(); - await resetWatcherCmd.init(argv, Database, Indexer); + await resetWatcherCmd.init(argv, Database); + const { graphWatcher, graphDb } = await getGraphDbAndWatcher( + resetWatcherCmd.config!.server, + resetWatcherCmd.clients!.ethClient, + resetWatcherCmd.ethProvider!, + resetWatcherCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + await resetWatcherCmd.initIndexer(Indexer, graphWatcher); await resetWatcherCmd.exec(); }; diff --git a/packages/graph-test-watcher/src/cli/watch-contract.ts b/packages/graph-test-watcher/src/cli/watch-contract.ts index bf1e7834..9b2291dc 100644 --- a/packages/graph-test-watcher/src/cli/watch-contract.ts +++ b/packages/graph-test-watcher/src/cli/watch-contract.ts @@ -6,16 +6,27 @@ import 'reflect-metadata'; import debug from 'debug'; import { WatchContractCmd } from '@cerc-io/cli'; +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; -import { Database } from '../database'; +import { Database, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP } from '../database'; import { Indexer } from '../indexer'; const log = debug('vulcanize:watch-contract'); const main = async (): Promise => { const watchContractCmd = new WatchContractCmd(); - await watchContractCmd.init(Database, Indexer); + await watchContractCmd.init(Database); + const { graphWatcher } = await getGraphDbAndWatcher( + watchContractCmd.config!.server, + watchContractCmd.clients!.ethClient, + watchContractCmd.ethProvider!, + watchContractCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + await watchContractCmd.initIndexer(Indexer, graphWatcher); await watchContractCmd.exec(); }; diff --git a/packages/graph-test-watcher/src/entity/Subscriber.ts b/packages/graph-test-watcher/src/entity/Subscriber.ts index 8a685533..2cccb841 100644 --- a/packages/graph-test-watcher/src/entity/Subscriber.ts +++ b/packages/graph-test-watcher/src/entity/Subscriber.ts @@ -4,7 +4,7 @@ import { EventSubscriber, EntitySubscriberInterface, InsertEvent, UpdateEvent } from 'typeorm'; -import { afterEntityInsertOrUpdate } from '@cerc-io/graph-node'; +import { afterEntityInsertOrUpdate } from '@cerc-io/util'; import { FrothyEntity } from './FrothyEntity'; import { ENTITY_TO_LATEST_ENTITY_MAP, SUBGRAPH_ENTITIES } from '../database'; diff --git a/packages/graph-test-watcher/src/fill.ts b/packages/graph-test-watcher/src/fill.ts index b4691cae..83745e35 100644 --- a/packages/graph-test-watcher/src/fill.ts +++ b/packages/graph-test-watcher/src/fill.ts @@ -7,7 +7,8 @@ import 'reflect-metadata'; import debug from 'debug'; import { FillCmd } from '@cerc-io/cli'; -import { getContractEntitiesMap } from '@cerc-io/graph-node'; +import { getContractEntitiesMap } from '@cerc-io/util'; +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; import { Database, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP } from './database'; import { Indexer } from './indexer'; @@ -17,13 +18,22 @@ const log = debug('vulcanize:fill'); export const main = async (): Promise => { const fillCmd = new FillCmd(); - await fillCmd.init(Database, Indexer, EventWatcher, {}, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP); + await fillCmd.init(Database); - const indexer = fillCmd.indexer as Indexer; - assert(indexer); + const { graphWatcher } = await getGraphDbAndWatcher( + fillCmd.config!.server, + fillCmd.clients!.ethClient, + fillCmd.ethProvider!, + fillCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + await fillCmd.initIndexer(Indexer, EventWatcher, graphWatcher); // Get contractEntitiesMap required for fill-state - const contractEntitiesMap = getContractEntitiesMap(indexer.graphWatcher.dataSources); + // NOTE: Assuming each entity type is only mapped to a single contract + const contractEntitiesMap = getContractEntitiesMap(graphWatcher.dataSources); await fillCmd.exec(contractEntitiesMap); }; diff --git a/packages/graph-test-watcher/src/indexer.ts b/packages/graph-test-watcher/src/indexer.ts index 1f39d271..1c0bfac7 100644 --- a/packages/graph-test-watcher/src/indexer.ts +++ b/packages/graph-test-watcher/src/indexer.ts @@ -28,9 +28,12 @@ import { ResultEvent, getResultEvent, DatabaseInterface, - Clients + Clients, + GraphWatcherInterface, + updateSubgraphState, + dumpSubgraphState } from '@cerc-io/util'; -import { GraphWatcher, updateSubgraphState, dumpSubgraphState } from '@cerc-io/graph-node'; +import { GraphWatcher } from '@cerc-io/graph-node'; import { Database, ENTITIES, SUBGRAPH_ENTITIES } from './database'; import { Contract } from './entity/Contract'; @@ -68,7 +71,7 @@ export class Indexer implements IndexerInterface { _subgraphStateMap: Map - constructor (serverConfig: ServerConfig, db: DatabaseInterface, clients: Clients, ethProvider: BaseProvider, jobQueue: JobQueue, graphWatcher?: GraphWatcher) { + constructor (serverConfig: ServerConfig, db: DatabaseInterface, clients: Clients, ethProvider: BaseProvider, jobQueue: JobQueue, graphWatcher?: GraphWatcherInterface) { assert(db); assert(clients.ethClient); @@ -79,7 +82,7 @@ export class Indexer implements IndexerInterface { this._baseIndexer = new BaseIndexer(this._serverConfig, this._db, this._ethClient, this._ethProvider, jobQueue); assert(graphWatcher); - this._graphWatcher = graphWatcher; + this._graphWatcher = graphWatcher as GraphWatcher; this._abiMap = new Map(); this._storageLayoutMap = new Map(); diff --git a/packages/graph-test-watcher/src/job-runner.ts b/packages/graph-test-watcher/src/job-runner.ts index 703c4397..9abbe64f 100644 --- a/packages/graph-test-watcher/src/job-runner.ts +++ b/packages/graph-test-watcher/src/job-runner.ts @@ -6,15 +6,27 @@ import debug from 'debug'; import { JobRunnerCmd } from '@cerc-io/cli'; import { JobRunner } from '@cerc-io/util'; +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; import { Indexer } from './indexer'; -import { Database } from './database'; +import { Database, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP } from './database'; const log = debug('vulcanize:job-runner'); export const main = async (): Promise => { const jobRunnerCmd = new JobRunnerCmd(); - await jobRunnerCmd.init(Database, Indexer); + await jobRunnerCmd.init(Database); + + const { graphWatcher } = await getGraphDbAndWatcher( + jobRunnerCmd.config!.server, + jobRunnerCmd.clients!.ethClient, + jobRunnerCmd.ethProvider!, + jobRunnerCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + await jobRunnerCmd.initIndexer(Indexer, graphWatcher); await jobRunnerCmd.exec(async (jobRunner: JobRunner): Promise => { await jobRunner.subscribeBlockProcessingQueue(); diff --git a/packages/graph-test-watcher/src/server.ts b/packages/graph-test-watcher/src/server.ts index 3d432ae3..43b4caea 100644 --- a/packages/graph-test-watcher/src/server.ts +++ b/packages/graph-test-watcher/src/server.ts @@ -8,6 +8,7 @@ import 'reflect-metadata'; import debug from 'debug'; import { ServerCmd } from '@cerc-io/cli'; +import { getGraphDbAndWatcher } from '@cerc-io/graph-node'; import { createResolvers } from './resolvers'; import { Indexer } from './indexer'; @@ -18,10 +19,20 @@ const log = debug('vulcanize:server'); export const main = async (): Promise => { const serverCmd = new ServerCmd(); - await serverCmd.init(Database, Indexer, EventWatcher, {}, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP); + await serverCmd.init(Database); + + const { graphWatcher } = await getGraphDbAndWatcher( + serverCmd.config!.server, + serverCmd.clients!.ethClient, + serverCmd.ethProvider!, + serverCmd.database!.baseDatabase, + ENTITY_QUERY_TYPE_MAP, + ENTITY_TO_LATEST_ENTITY_MAP + ); + + await serverCmd.initIndexer(Indexer, EventWatcher, graphWatcher); const typeDefs = fs.readFileSync(path.join(__dirname, 'schema.gql')).toString(); - return serverCmd.exec(createResolvers, typeDefs); }; diff --git a/packages/ipld-eth-client/package.json b/packages/ipld-eth-client/package.json index 8b19be90..7abec8fe 100644 --- a/packages/ipld-eth-client/package.json +++ b/packages/ipld-eth-client/package.json @@ -27,7 +27,6 @@ "graphql": "^15.5.0", "graphql-ws": "^5.11.2", "left-pad": "^1.3.0", - "lodash": "^4.17.21", "ws": "^8.11.0", "zen-observable-ts": "^1.1.0" }, diff --git a/packages/mobymask-watcher/src/cli/checkpoint-cmds/create.ts b/packages/mobymask-watcher/src/cli/checkpoint-cmds/create.ts index 63f844ce..75b09ba9 100644 --- a/packages/mobymask-watcher/src/cli/checkpoint-cmds/create.ts +++ b/packages/mobymask-watcher/src/cli/checkpoint-cmds/create.ts @@ -26,7 +26,7 @@ export const builder = { export const handler = async (argv: any): Promise => { const createCheckpointCmd = new CreateCheckpointCmd(); - await createCheckpointCmd.init(argv, Database, Indexer); - + await createCheckpointCmd.init(argv, Database); + await createCheckpointCmd.initIndexer(Indexer); await createCheckpointCmd.exec(); }; diff --git a/packages/mobymask-watcher/src/cli/export-state.ts b/packages/mobymask-watcher/src/cli/export-state.ts index 2411b960..5a9bbcfb 100644 --- a/packages/mobymask-watcher/src/cli/export-state.ts +++ b/packages/mobymask-watcher/src/cli/export-state.ts @@ -14,8 +14,8 @@ const log = debug('vulcanize:export-state'); const main = async (): Promise => { const exportStateCmd = new ExportStateCmd(); - await exportStateCmd.init(Database, Indexer); - + await exportStateCmd.init(Database); + await exportStateCmd.initIndexer(Indexer); await exportStateCmd.exec(); }; diff --git a/packages/mobymask-watcher/src/cli/import-state.ts b/packages/mobymask-watcher/src/cli/import-state.ts index 871f1b00..8980144e 100644 --- a/packages/mobymask-watcher/src/cli/import-state.ts +++ b/packages/mobymask-watcher/src/cli/import-state.ts @@ -16,8 +16,8 @@ const log = debug('vulcanize:import-state'); export const main = async (): Promise => { const importStateCmd = new ImportStateCmd(); - await importStateCmd.init(Database, Indexer, EventWatcher); - + await importStateCmd.init(Database); + await importStateCmd.initIndexer(Indexer, EventWatcher); await importStateCmd.exec(State); }; diff --git a/packages/mobymask-watcher/src/cli/index-block.ts b/packages/mobymask-watcher/src/cli/index-block.ts index 6b59df5e..fab95b2c 100644 --- a/packages/mobymask-watcher/src/cli/index-block.ts +++ b/packages/mobymask-watcher/src/cli/index-block.ts @@ -14,8 +14,8 @@ const log = debug('vulcanize:index-block'); const main = async (): Promise => { const indexBlockCmd = new IndexBlockCmd(); - await indexBlockCmd.init(Database, Indexer); - + await indexBlockCmd.init(Database); + await indexBlockCmd.initIndexer(Indexer); await indexBlockCmd.exec(); }; diff --git a/packages/mobymask-watcher/src/cli/inspect-cid.ts b/packages/mobymask-watcher/src/cli/inspect-cid.ts index 3b1f44d7..d708a1b3 100644 --- a/packages/mobymask-watcher/src/cli/inspect-cid.ts +++ b/packages/mobymask-watcher/src/cli/inspect-cid.ts @@ -14,8 +14,8 @@ const log = debug('vulcanize:inspect-cid'); const main = async (): Promise => { const inspectCIDCmd = new InspectCIDCmd(); - await inspectCIDCmd.init(Database, Indexer); - + await inspectCIDCmd.init(Database); + await inspectCIDCmd.initIndexer(Indexer); await inspectCIDCmd.exec(); }; diff --git a/packages/mobymask-watcher/src/cli/reset-cmds/watcher.ts b/packages/mobymask-watcher/src/cli/reset-cmds/watcher.ts index 295adc45..2dfdd68c 100644 --- a/packages/mobymask-watcher/src/cli/reset-cmds/watcher.ts +++ b/packages/mobymask-watcher/src/cli/reset-cmds/watcher.ts @@ -19,7 +19,7 @@ export const builder = { export const handler = async (argv: any): Promise => { const resetWatcherCmd = new ResetWatcherCmd(); - await resetWatcherCmd.init(argv, Database, Indexer); - + await resetWatcherCmd.init(argv, Database); + await resetWatcherCmd.initIndexer(Indexer); await resetWatcherCmd.exec(); }; diff --git a/packages/mobymask-watcher/src/cli/watch-contract.ts b/packages/mobymask-watcher/src/cli/watch-contract.ts index bf1e7834..1934c09f 100644 --- a/packages/mobymask-watcher/src/cli/watch-contract.ts +++ b/packages/mobymask-watcher/src/cli/watch-contract.ts @@ -14,8 +14,8 @@ const log = debug('vulcanize:watch-contract'); const main = async (): Promise => { const watchContractCmd = new WatchContractCmd(); - await watchContractCmd.init(Database, Indexer); - + await watchContractCmd.init(Database); + await watchContractCmd.initIndexer(Indexer); await watchContractCmd.exec(); }; diff --git a/packages/mobymask-watcher/src/fill.ts b/packages/mobymask-watcher/src/fill.ts index 75d2c508..4c0eaead 100644 --- a/packages/mobymask-watcher/src/fill.ts +++ b/packages/mobymask-watcher/src/fill.ts @@ -15,8 +15,9 @@ const log = debug('vulcanize:fill'); export const main = async (): Promise => { const fillCmd = new FillCmd(); - await fillCmd.init(Database, Indexer, EventWatcher); + await fillCmd.init(Database); + await fillCmd.initIndexer(Indexer, EventWatcher); await fillCmd.exec(); }; diff --git a/packages/mobymask-watcher/src/job-runner.ts b/packages/mobymask-watcher/src/job-runner.ts index 703c4397..92e57187 100644 --- a/packages/mobymask-watcher/src/job-runner.ts +++ b/packages/mobymask-watcher/src/job-runner.ts @@ -14,7 +14,8 @@ const log = debug('vulcanize:job-runner'); export const main = async (): Promise => { const jobRunnerCmd = new JobRunnerCmd(); - await jobRunnerCmd.init(Database, Indexer); + await jobRunnerCmd.init(Database); + await jobRunnerCmd.initIndexer(Indexer); await jobRunnerCmd.exec(async (jobRunner: JobRunner): Promise => { await jobRunner.subscribeBlockProcessingQueue(); diff --git a/packages/mobymask-watcher/src/server.ts b/packages/mobymask-watcher/src/server.ts index 20915d12..35a6240a 100644 --- a/packages/mobymask-watcher/src/server.ts +++ b/packages/mobymask-watcher/src/server.ts @@ -18,10 +18,10 @@ const log = debug('vulcanize:server'); export const main = async (): Promise => { const serverCmd = new ServerCmd(); - await serverCmd.init(Database, Indexer, EventWatcher); + await serverCmd.init(Database); + await serverCmd.initIndexer(Indexer, EventWatcher); const typeDefs = fs.readFileSync(path.join(__dirname, 'schema.gql')).toString(); - return serverCmd.exec(createResolvers, typeDefs); }; diff --git a/packages/solidity-mapper/package.json b/packages/solidity-mapper/package.json index b80f9b8b..41b74e82 100644 --- a/packages/solidity-mapper/package.json +++ b/packages/solidity-mapper/package.json @@ -9,7 +9,6 @@ "@nomiclabs/hardhat-ethers": "^2.0.2", "@nomiclabs/hardhat-waffle": "^2.0.1", "@types/chai": "^4.2.18", - "@types/mocha": "^8.2.2", "@typescript-eslint/eslint-plugin": "^4.25.0", "@typescript-eslint/parser": "^4.25.0", "chai": "^4.3.4", diff --git a/packages/util/package.json b/packages/util/package.json index 70cca7e9..cb97d18d 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -6,8 +6,10 @@ "dependencies": { "@apollo/utils.keyvaluecache": "^1.0.1", "@cerc-io/solidity-mapper": "^0.2.15", + "@ethersproject/providers": "^5.4.4", "@graphql-tools/schema": "^9.0.10", "@graphql-tools/utils": "^9.1.1", + "@ipld/dag-cbor": "^6.0.12", "apollo-server-core": "^3.11.1", "apollo-server-express": "^3.11.1", "apollo-server-plugin-response-cache": "^3.8.1", @@ -26,11 +28,16 @@ "pg-boss": "^6.1.0", "prom-client": "^14.0.1", "toml": "^3.0.0", - "ws": "^8.11.0" + "ws": "^8.11.0", + "typeorm": "^0.2.32", + "typeorm-naming-strategies": "^2.0.0", + "graphql-subscriptions": "^2.0.0", + "json-bigint": "^1.0.0" }, "devDependencies": { "@cerc-io/cache": "^0.2.15", "@cerc-io/ipld-eth-client": "^0.2.15", + "@nomiclabs/hardhat-waffle": "^2.0.1", "@types/express": "^4.17.14", "@types/fs-extra": "^9.0.11", "@types/pg": "^8.6.5", @@ -46,9 +53,7 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^5.1.0", "eslint-plugin-standard": "^5.0.0", - "hardhat": "^2.3.0", - "typeorm": "^0.2.32", - "typeorm-naming-strategies": "^2.0.0" + "hardhat": "^2.3.0" }, "scripts": { "lint": "eslint .", diff --git a/packages/graph-node/src/database.ts b/packages/util/src/graph/database.ts similarity index 98% rename from packages/graph-node/src/database.ts rename to packages/util/src/graph/database.ts index 364c6b2d..92386078 100644 --- a/packages/graph-node/src/database.ts +++ b/packages/util/src/graph/database.ts @@ -21,20 +21,12 @@ import { SelectionNode } from 'graphql'; import _ from 'lodash'; import debug from 'debug'; -import { - BlockHeight, - BlockProgressInterface, - cachePrunedEntitiesCount, - Database as BaseDatabase, - eventProcessingLoadEntityCacheHitCount, - eventProcessingLoadEntityCount, - eventProcessingLoadEntityDBQueryDuration, - QueryOptions, - ServerConfig, - Where -} from '@cerc-io/util'; - -import { Block, fromEntityValue, fromStateEntityValues, getLatestEntityFromEntity, resolveEntityFieldConflicts, toEntityValue } from './utils'; +import { BlockHeight, Database as BaseDatabase, QueryOptions, Where } from '../database'; +import { BlockProgressInterface } from '../types'; +import { cachePrunedEntitiesCount, eventProcessingLoadEntityCacheHitCount, eventProcessingLoadEntityCount, eventProcessingLoadEntityDBQueryDuration } from '../metrics'; +import { ServerConfig } from '../config'; +import { Block, fromEntityValue, getLatestEntityFromEntity, resolveEntityFieldConflicts, toEntityValue } from './utils'; +import { fromStateEntityValues } from './state-utils'; const log = debug('vulcanize:graph-database'); @@ -60,7 +52,7 @@ interface CachedEntities { latestPrunedEntities: Map>; } -export class Database { +export class GraphDatabase { _serverConfig: ServerConfig _conn!: Connection _baseDatabase: BaseDatabase diff --git a/packages/util/src/graph-decimal.ts b/packages/util/src/graph/graph-decimal.ts similarity index 100% rename from packages/util/src/graph-decimal.ts rename to packages/util/src/graph/graph-decimal.ts diff --git a/packages/graph-node/src/state-utils.ts b/packages/util/src/graph/state-utils.ts similarity index 85% rename from packages/graph-node/src/state-utils.ts rename to packages/util/src/graph/state-utils.ts index 1746bf38..5f69996a 100644 --- a/packages/graph-node/src/state-utils.ts +++ b/packages/util/src/graph/state-utils.ts @@ -5,11 +5,11 @@ import assert from 'assert'; import debug from 'debug'; import _ from 'lodash'; +import { Between, ValueTransformer } from 'typeorm'; -import { Between } from 'typeorm'; -import { IndexerInterface, jsonBigIntStringReplacer, StateInterface } from '@cerc-io/util'; - -import { Database } from './database'; +import { jsonBigIntStringReplacer } from '../misc'; +import { IndexerInterface, StateInterface } from '../types'; +import { GraphDatabase } from './database'; import { resolveEntityFieldConflicts } from './utils'; const log = debug('vulcanize:state-utils'); @@ -55,7 +55,7 @@ export const prepareEntityState = (updatedEntity: any, entityName: string, relat return diffData; }; -export const updateEntitiesFromState = async (database: Database, indexer: IndexerInterface, state: StateInterface) => { +export const updateEntitiesFromState = async (database: GraphDatabase, indexer: IndexerInterface, state: StateInterface) => { const data = indexer.getStateData(state); // Get relations for subgraph entity @@ -206,3 +206,36 @@ export const fillState = async ( console.timeEnd('time:fill-state'); }; + +export const fromStateEntityValues = ( + stateEntity: any, + propertyName: string, + relations: { [key: string]: any } = {}, + transformer?: ValueTransformer | ValueTransformer[] +): any => { + // Parse DB data value from state entity data. + if (relations) { + const relation = relations[propertyName]; + + if (relation) { + if (relation.isArray) { + return stateEntity[propertyName].map((relatedEntity: { id: string }) => relatedEntity.id); + } else { + return stateEntity[propertyName]?.id; + } + } + } + + if (transformer) { + if (Array.isArray(transformer)) { + // Apply transformer in reverse order similar to when reading from DB. + return transformer.reduceRight((acc, elTransformer) => { + return elTransformer.from(acc); + }, stateEntity[propertyName]); + } + + return transformer.from(stateEntity[propertyName]); + } + + return stateEntity[propertyName]; +}; diff --git a/packages/graph-node/src/types.ts b/packages/util/src/graph/types.ts similarity index 98% rename from packages/graph-node/src/types.ts rename to packages/util/src/graph/types.ts index 8eb034a3..32f98563 100644 --- a/packages/graph-node/src/types.ts +++ b/packages/util/src/graph/types.ts @@ -1,5 +1,5 @@ // -// Copyright 2021 Vulcanize, Inc. +// Copyright 2022 Vulcanize, Inc. // // Enum types from @graphprotocol/graph-ts. diff --git a/packages/graph-node/src/utils.ts b/packages/util/src/graph/utils.ts similarity index 95% rename from packages/graph-node/src/utils.ts rename to packages/util/src/graph/utils.ts index 4480435f..a6051097 100644 --- a/packages/graph-node/src/utils.ts +++ b/packages/util/src/graph/utils.ts @@ -1,21 +1,17 @@ -// -// Copyright 2022 Vulcanize, Inc. -// - import { BigNumber, utils } from 'ethers'; import path from 'path'; import fs from 'fs-extra'; import debug from 'debug'; import yaml from 'js-yaml'; -import { DeepPartial, EntityTarget, InsertEvent, Repository, UpdateEvent, ValueTransformer } from 'typeorm'; +import { DeepPartial, EntityTarget, InsertEvent, Repository, UpdateEvent } from 'typeorm'; import { ColumnMetadata } from 'typeorm/metadata/ColumnMetadata'; import assert from 'assert'; import _ from 'lodash'; -import { GraphDecimal } from '@cerc-io/util'; import { MappingKey, StorageLayout } from '@cerc-io/solidity-mapper'; -import { TypeId, EthereumValueKind, ValueKind } from './types'; +import { GraphDecimal } from './graph-decimal'; +import { EthereumValueKind, TypeId, ValueKind } from './types'; const log = debug('vulcanize:utils'); @@ -805,39 +801,6 @@ const getEthereumType = (storageTypes: StorageLayout['types'], type: string, map return utils.ParamType.from(label); }; -export const fromStateEntityValues = ( - stateEntity: any, - propertyName: string, - relations: { [key: string]: any } = {}, - transformer?: ValueTransformer | ValueTransformer[] -): any => { - // Parse DB data value from state entity data. - if (relations) { - const relation = relations[propertyName]; - - if (relation) { - if (relation.isArray) { - return stateEntity[propertyName].map((relatedEntity: { id: string }) => relatedEntity.id); - } else { - return stateEntity[propertyName]?.id; - } - } - } - - if (transformer) { - if (Array.isArray(transformer)) { - // Apply transformer in reverse order similar to when reading from DB. - return transformer.reduceRight((acc, elTransformer) => { - return elTransformer.from(acc); - }, stateEntity[propertyName]); - } - - return transformer.from(stateEntity[propertyName]); - } - - return stateEntity[propertyName]; -}; - export const afterEntityInsertOrUpdate = async ( frothyEntityType: EntityTarget, entities: Set, @@ -892,7 +855,7 @@ export const afterEntityInsertOrUpdate = async ( .execute(); }; -export const getLatestEntityFromEntity = (latestEntityRepo: Repository, entity: any): Entity => { +export function getLatestEntityFromEntity (latestEntityRepo: Repository, entity: any): Entity { const latestEntityFields = latestEntityRepo.metadata.columns.map(column => column.propertyName); return latestEntityRepo.create(_.pick(entity, latestEntityFields) as DeepPartial); -}; +} diff --git a/packages/util/src/index.ts b/packages/util/src/index.ts index 37dc823e..7e36591f 100644 --- a/packages/util/src/index.ts +++ b/packages/util/src/index.ts @@ -13,9 +13,13 @@ export * from './types'; export * from './indexer'; export * from './job-runner'; export * from './state-helper'; -export * from './graph-decimal'; export * from './index-block'; export * from './metrics'; export * from './gql-metrics'; export * from './common'; export * from './server'; +export * from './graph/graph-decimal'; +export * from './graph/database'; +export * from './graph/utils'; +export * from './graph/state-utils'; +export * from './graph/types'; diff --git a/packages/util/src/misc.ts b/packages/util/src/misc.ts index c7816a59..10fc2331 100644 --- a/packages/util/src/misc.ts +++ b/packages/util/src/misc.ts @@ -17,7 +17,7 @@ import { EthClient } from '@cerc-io/ipld-eth-client'; import { DEFAULT_CONFIG_PATH } from './constants'; import { GQLCacheConfig, Config } from './config'; import { JobQueue } from './job-queue'; -import { GraphDecimal } from './graph-decimal'; +import { GraphDecimal } from './graph/graph-decimal'; import * as EthDecoder from './eth'; import { getCachedBlockSize } from './block-size-cache'; import { ResultEvent } from './indexer'; diff --git a/packages/util/src/types.ts b/packages/util/src/types.ts index 5ea4f27f..db0c4162 100644 --- a/packages/util/src/types.ts +++ b/packages/util/src/types.ts @@ -192,6 +192,11 @@ export interface GraphDatabaseInterface { getEntity (entity: (new () => Entity) | string, id: string, blockHash?: string): Promise; } +export interface GraphWatcherInterface { + init (): Promise; + setIndexer (indexer: IndexerInterface): void; +} + export type Clients = { ethClient: EthClient; [key: string]: any;