mirror of
https://github.com/cerc-io/watcher-ts
synced 2024-11-19 20:36:19 +00:00
Refactor graph-node database and move to util (#259)
* Move graph-database from graph-node to util * Refactor and remove graph-node dependency from cli package * Modify dependencies using depcheck * Implement CLI refactoring changes in other watchers * Review changes to remove eden comment and fix local import in util * Import GraphDatabase from util instead of graph-node * Move graph-node non assemblyscript code to util package * Implement CLI refactoring changes in codegen * Fix graph-node tests after refactoring * Move fromStateEntityValues to graph state utils
This commit is contained in:
parent
63a2c5804e
commit
b66dcb4af9
@ -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"
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import { ConnectionOptions } from 'typeorm';
|
||||
import { PubSub } from 'graphql-subscriptions';
|
||||
|
||||
import { JsonRpcProvider } from '@ethersproject/providers';
|
||||
import { GraphWatcher, Database as GraphDatabase } from '@cerc-io/graph-node';
|
||||
import {
|
||||
Config,
|
||||
getConfig,
|
||||
@ -17,9 +16,9 @@ import {
|
||||
DatabaseInterface,
|
||||
IndexerInterface,
|
||||
ServerConfig,
|
||||
Database as BaseDatabase,
|
||||
Clients,
|
||||
EventWatcherInterface
|
||||
EventWatcherInterface,
|
||||
GraphWatcherInterface
|
||||
} from '@cerc-io/util';
|
||||
import { EthClient } from '@cerc-io/ipld-eth-client';
|
||||
|
||||
@ -30,13 +29,20 @@ export class BaseCmd {
|
||||
_jobQueue?: JobQueue
|
||||
_database?: DatabaseInterface;
|
||||
_indexer?: IndexerInterface;
|
||||
_graphDb?: GraphDatabase;
|
||||
_eventWatcher?: EventWatcherInterface;
|
||||
|
||||
get config (): Config | undefined {
|
||||
return this._config;
|
||||
}
|
||||
|
||||
get clients (): Clients | undefined {
|
||||
return this._clients;
|
||||
}
|
||||
|
||||
get ethProvider (): JsonRpcProvider | undefined {
|
||||
return this._ethProvider;
|
||||
}
|
||||
|
||||
get jobQueue (): JobQueue | undefined {
|
||||
return this._jobQueue;
|
||||
}
|
||||
@ -45,10 +51,6 @@ export class BaseCmd {
|
||||
return this._database;
|
||||
}
|
||||
|
||||
get graphDb (): GraphDatabase | undefined {
|
||||
return this._graphDb;
|
||||
}
|
||||
|
||||
get indexer (): IndexerInterface | undefined {
|
||||
return this._indexer;
|
||||
}
|
||||
@ -70,17 +72,7 @@ export class BaseCmd {
|
||||
config: ConnectionOptions,
|
||||
serverConfig?: ServerConfig
|
||||
) => DatabaseInterface,
|
||||
Indexer: new (
|
||||
serverConfig: ServerConfig,
|
||||
db: DatabaseInterface,
|
||||
clients: Clients,
|
||||
ethProvider: JsonRpcProvider,
|
||||
jobQueue: JobQueue,
|
||||
graphWatcher?: GraphWatcher
|
||||
) => IndexerInterface,
|
||||
clients: { [key: string]: any } = {},
|
||||
entityQueryTypeMap?: Map<any, any>,
|
||||
entityToLatestEntityMap?: Map<any, any>
|
||||
clients: { [key: string]: any } = {}
|
||||
): Promise<void> {
|
||||
assert(this._config);
|
||||
|
||||
@ -99,18 +91,31 @@ export class BaseCmd {
|
||||
const { ethClient, ethProvider } = await initClients(this._config);
|
||||
this._ethProvider = ethProvider;
|
||||
this._clients = { ethClient, ...clients };
|
||||
}
|
||||
|
||||
// Check if subgraph watcher.
|
||||
if (this._config.server.subgraphPath) {
|
||||
const graphWatcher = await this._getGraphWatcher(this._database.baseDatabase, entityQueryTypeMap, entityToLatestEntityMap);
|
||||
this._indexer = new Indexer(this._config.server, this._database, this._clients, ethProvider, this._jobQueue, graphWatcher);
|
||||
await this._indexer.init();
|
||||
async initIndexer (
|
||||
Indexer: new (
|
||||
serverConfig: ServerConfig,
|
||||
db: DatabaseInterface,
|
||||
clients: Clients,
|
||||
ethProvider: JsonRpcProvider,
|
||||
jobQueue: JobQueue,
|
||||
graphWatcher?: GraphWatcherInterface
|
||||
) => IndexerInterface,
|
||||
graphWatcher?: GraphWatcherInterface
|
||||
) {
|
||||
assert(this._config);
|
||||
assert(this._database);
|
||||
assert(this._clients);
|
||||
assert(this._ethProvider);
|
||||
assert(this._jobQueue);
|
||||
|
||||
this._indexer = new Indexer(this._config.server, this._database, this._clients, this._ethProvider, this._jobQueue, graphWatcher);
|
||||
await this._indexer.init();
|
||||
|
||||
if (graphWatcher) {
|
||||
graphWatcher.setIndexer(this._indexer);
|
||||
await graphWatcher.init();
|
||||
} else {
|
||||
this._indexer = new Indexer(this._config.server, this._database, this._clients, ethProvider, this._jobQueue);
|
||||
await this._indexer.init();
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,19 +136,4 @@ export class BaseCmd {
|
||||
const pubsub = new PubSub();
|
||||
this._eventWatcher = new EventWatcher(this._clients.ethClient, this._indexer, pubsub, this._jobQueue);
|
||||
}
|
||||
|
||||
async _getGraphWatcher (
|
||||
baseDatabase: BaseDatabase,
|
||||
entityQueryTypeMap?: Map<any, any>,
|
||||
entityToLatestEntityMap?: Map<any, any>
|
||||
): Promise<GraphWatcher> {
|
||||
assert(this._config);
|
||||
assert(this._clients?.ethClient);
|
||||
assert(this._ethProvider);
|
||||
|
||||
this._graphDb = new GraphDatabase(this._config.server, baseDatabase, entityQueryTypeMap, entityToLatestEntityMap);
|
||||
await this._graphDb.init();
|
||||
|
||||
return new GraphWatcher(this._graphDb, this._clients.ethClient, this._ethProvider, this._config.server);
|
||||
}
|
||||
}
|
||||
|
@ -8,13 +8,14 @@ import assert from 'assert';
|
||||
import { ConnectionOptions } from 'typeorm';
|
||||
|
||||
import { JsonRpcProvider } from '@ethersproject/providers';
|
||||
import { GraphWatcher } from '@cerc-io/graph-node';
|
||||
import {
|
||||
JobQueue,
|
||||
DatabaseInterface,
|
||||
IndexerInterface,
|
||||
ServerConfig,
|
||||
Clients
|
||||
Clients,
|
||||
GraphWatcherInterface,
|
||||
Config
|
||||
} from '@cerc-io/util';
|
||||
|
||||
import { BaseCmd } from '../base';
|
||||
@ -35,6 +36,22 @@ export class CreateCheckpointCmd {
|
||||
this._baseCmd = new BaseCmd();
|
||||
}
|
||||
|
||||
get config (): Config | undefined {
|
||||
return this._baseCmd.config;
|
||||
}
|
||||
|
||||
get clients (): Clients | undefined {
|
||||
return this._baseCmd.clients;
|
||||
}
|
||||
|
||||
get ethProvider (): JsonRpcProvider | undefined {
|
||||
return this._baseCmd.ethProvider;
|
||||
}
|
||||
|
||||
get database (): DatabaseInterface | undefined {
|
||||
return this._baseCmd.database;
|
||||
}
|
||||
|
||||
async initConfig<ConfigType> (configFile: string): Promise<ConfigType> {
|
||||
return this._baseCmd.initConfig(configFile);
|
||||
}
|
||||
@ -45,20 +62,26 @@ export class CreateCheckpointCmd {
|
||||
config: ConnectionOptions,
|
||||
serverConfig?: ServerConfig
|
||||
) => DatabaseInterface,
|
||||
clients: { [key: string]: any } = {}
|
||||
): Promise<void> {
|
||||
this._argv = argv;
|
||||
await this.initConfig(argv.configFile);
|
||||
|
||||
await this._baseCmd.init(Database, clients);
|
||||
}
|
||||
|
||||
async initIndexer (
|
||||
Indexer: new (
|
||||
serverConfig: ServerConfig,
|
||||
db: DatabaseInterface,
|
||||
clients: Clients,
|
||||
ethProvider: JsonRpcProvider,
|
||||
jobQueue: JobQueue,
|
||||
graphWatcher?: GraphWatcher
|
||||
graphWatcher?: GraphWatcherInterface
|
||||
) => IndexerInterface,
|
||||
clients: { [key: string]: any } = {}
|
||||
): Promise<void> {
|
||||
this._argv = argv;
|
||||
await this.initConfig(argv.configFile);
|
||||
|
||||
await this._baseCmd.init(Database, Indexer, clients);
|
||||
graphWatcher?: GraphWatcherInterface
|
||||
) {
|
||||
return this._baseCmd.initIndexer(Indexer, graphWatcher);
|
||||
}
|
||||
|
||||
async exec (): Promise<void> {
|
||||
|
@ -8,14 +8,16 @@ import assert from 'assert';
|
||||
import { ConnectionOptions } from 'typeorm';
|
||||
|
||||
import { JsonRpcProvider } from '@ethersproject/providers';
|
||||
import { GraphWatcher, Database as GraphDatabase } from '@cerc-io/graph-node';
|
||||
import {
|
||||
JobQueue,
|
||||
DatabaseInterface,
|
||||
IndexerInterface,
|
||||
ServerConfig,
|
||||
Clients,
|
||||
verifyCheckpointData
|
||||
verifyCheckpointData,
|
||||
GraphDatabase,
|
||||
GraphWatcherInterface,
|
||||
Config
|
||||
} from '@cerc-io/util';
|
||||
|
||||
import { BaseCmd } from '../base';
|
||||
@ -35,6 +37,22 @@ export class VerifyCheckpointCmd {
|
||||
this._baseCmd = new BaseCmd();
|
||||
}
|
||||
|
||||
get config (): Config | undefined {
|
||||
return this._baseCmd.config;
|
||||
}
|
||||
|
||||
get clients (): Clients | undefined {
|
||||
return this._baseCmd.clients;
|
||||
}
|
||||
|
||||
get ethProvider (): JsonRpcProvider | undefined {
|
||||
return this._baseCmd.ethProvider;
|
||||
}
|
||||
|
||||
get database (): DatabaseInterface | undefined {
|
||||
return this._baseCmd.database;
|
||||
}
|
||||
|
||||
async initConfig<ConfigType> (configFile: string): Promise<ConfigType> {
|
||||
return this._baseCmd.initConfig(configFile);
|
||||
}
|
||||
@ -45,23 +63,29 @@ export class VerifyCheckpointCmd {
|
||||
config: ConnectionOptions,
|
||||
serverConfig?: ServerConfig
|
||||
) => DatabaseInterface,
|
||||
clients: { [key: string]: any } = {}
|
||||
): Promise<void> {
|
||||
this._argv = argv;
|
||||
await this.initConfig(argv.configFile);
|
||||
|
||||
await this._baseCmd.init(Database, clients);
|
||||
}
|
||||
|
||||
async initIndexer (
|
||||
Indexer: new (
|
||||
serverConfig: ServerConfig,
|
||||
db: DatabaseInterface,
|
||||
clients: Clients,
|
||||
ethProvider: JsonRpcProvider,
|
||||
jobQueue: JobQueue,
|
||||
graphWatcher?: GraphWatcher
|
||||
graphWatcher?: GraphWatcherInterface
|
||||
) => IndexerInterface,
|
||||
clients: { [key: string]: any } = {}
|
||||
): Promise<void> {
|
||||
this._argv = argv;
|
||||
await this.initConfig(argv.configFile);
|
||||
|
||||
await this._baseCmd.init(Database, Indexer, clients);
|
||||
graphWatcher?: GraphWatcherInterface
|
||||
) {
|
||||
return this._baseCmd.initIndexer(Indexer, graphWatcher);
|
||||
}
|
||||
|
||||
async exec (): Promise<void> {
|
||||
async exec (graphDb: GraphDatabase): Promise<void> {
|
||||
assert(this._argv);
|
||||
|
||||
const database = this._baseCmd.database;
|
||||
@ -70,9 +94,6 @@ export class VerifyCheckpointCmd {
|
||||
assert(database);
|
||||
assert(indexer);
|
||||
|
||||
const graphDb: GraphDatabase | undefined = this._baseCmd.graphDb || database.graphDatabase;
|
||||
assert(graphDb);
|
||||
|
||||
const state = await indexer.getStateByCID(this._argv.cid);
|
||||
assert(state, 'State for the provided CID doesn\'t exist.');
|
||||
const data = indexer.getStateData(state);
|
||||
|
@ -11,7 +11,6 @@ import debug from 'debug';
|
||||
import { ConnectionOptions } from 'typeorm';
|
||||
|
||||
import { JsonRpcProvider } from '@ethersproject/providers';
|
||||
import { GraphWatcher } from '@cerc-io/graph-node';
|
||||
import {
|
||||
DEFAULT_CONFIG_PATH,
|
||||
JobQueue,
|
||||
@ -19,7 +18,9 @@ import {
|
||||
IndexerInterface,
|
||||
ServerConfig,
|
||||
StateKind,
|
||||
Clients
|
||||
Clients,
|
||||
GraphWatcherInterface,
|
||||
Config
|
||||
} from '@cerc-io/util';
|
||||
import * as codec from '@ipld/dag-cbor';
|
||||
|
||||
@ -41,6 +42,22 @@ export class ExportStateCmd {
|
||||
this._baseCmd = new BaseCmd();
|
||||
}
|
||||
|
||||
get config (): Config | undefined {
|
||||
return this._baseCmd.config;
|
||||
}
|
||||
|
||||
get clients (): Clients | undefined {
|
||||
return this._baseCmd.clients;
|
||||
}
|
||||
|
||||
get ethProvider (): JsonRpcProvider | undefined {
|
||||
return this._baseCmd.ethProvider;
|
||||
}
|
||||
|
||||
get database (): DatabaseInterface | undefined {
|
||||
return this._baseCmd.database;
|
||||
}
|
||||
|
||||
async initConfig<ConfigType> (): Promise<ConfigType> {
|
||||
this._argv = this._getArgv();
|
||||
assert(this._argv);
|
||||
@ -53,19 +70,25 @@ export class ExportStateCmd {
|
||||
config: ConnectionOptions,
|
||||
serverConfig?: ServerConfig
|
||||
) => DatabaseInterface,
|
||||
clients: { [key: string]: any } = {}
|
||||
): Promise<void> {
|
||||
await this.initConfig();
|
||||
|
||||
await this._baseCmd.init(Database, clients);
|
||||
}
|
||||
|
||||
async initIndexer (
|
||||
Indexer: new (
|
||||
serverConfig: ServerConfig,
|
||||
db: DatabaseInterface,
|
||||
clients: Clients,
|
||||
ethProvider: JsonRpcProvider,
|
||||
jobQueue: JobQueue,
|
||||
graphWatcher?: GraphWatcher
|
||||
graphWatcher?: GraphWatcherInterface
|
||||
) => IndexerInterface,
|
||||
clients: { [key: string]: any } = {}
|
||||
): Promise<void> {
|
||||
await this.initConfig();
|
||||
|
||||
await this._baseCmd.init(Database, Indexer, clients);
|
||||
graphWatcher?: GraphWatcherInterface
|
||||
) {
|
||||
return this._baseCmd.initIndexer(Indexer, graphWatcher);
|
||||
}
|
||||
|
||||
async exec (): Promise<void> {
|
||||
|
@ -11,9 +11,8 @@ import { ConnectionOptions } from 'typeorm';
|
||||
import { PubSub } from 'graphql-subscriptions';
|
||||
|
||||
import { JsonRpcProvider } from '@ethersproject/providers';
|
||||
import { GraphWatcher, fillState } from '@cerc-io/graph-node';
|
||||
import { EthClient } from '@cerc-io/ipld-eth-client';
|
||||
import {
|
||||
fillState,
|
||||
DEFAULT_CONFIG_PATH,
|
||||
JobQueue,
|
||||
DatabaseInterface,
|
||||
@ -21,8 +20,11 @@ import {
|
||||
ServerConfig,
|
||||
Clients,
|
||||
EventWatcherInterface,
|
||||
fillBlocks
|
||||
fillBlocks,
|
||||
GraphWatcherInterface,
|
||||
Config
|
||||
} from '@cerc-io/util';
|
||||
import { EthClient } from '@cerc-io/ipld-eth-client';
|
||||
|
||||
import { BaseCmd } from './base';
|
||||
|
||||
@ -45,6 +47,22 @@ export class FillCmd {
|
||||
this._baseCmd = new BaseCmd();
|
||||
}
|
||||
|
||||
get config (): Config | undefined {
|
||||
return this._baseCmd.config;
|
||||
}
|
||||
|
||||
get clients (): Clients | undefined {
|
||||
return this._baseCmd.clients;
|
||||
}
|
||||
|
||||
get ethProvider (): JsonRpcProvider | undefined {
|
||||
return this._baseCmd.ethProvider;
|
||||
}
|
||||
|
||||
get database (): DatabaseInterface | undefined {
|
||||
return this._baseCmd.database;
|
||||
}
|
||||
|
||||
get indexer (): IndexerInterface | undefined {
|
||||
return this._baseCmd.indexer;
|
||||
}
|
||||
@ -61,13 +79,21 @@ export class FillCmd {
|
||||
config: ConnectionOptions,
|
||||
serverConfig?: ServerConfig
|
||||
) => DatabaseInterface,
|
||||
clients: { [key: string]: any } = {}
|
||||
): Promise<void> {
|
||||
await this.initConfig();
|
||||
|
||||
await this._baseCmd.init(Database, clients);
|
||||
}
|
||||
|
||||
async initIndexer (
|
||||
Indexer: new (
|
||||
serverConfig: ServerConfig,
|
||||
db: DatabaseInterface,
|
||||
clients: Clients,
|
||||
ethProvider: JsonRpcProvider,
|
||||
jobQueue: JobQueue,
|
||||
graphWatcher?: GraphWatcher
|
||||
graphWatcher?: GraphWatcherInterface
|
||||
) => IndexerInterface,
|
||||
EventWatcher: new(
|
||||
ethClient: EthClient,
|
||||
@ -75,13 +101,9 @@ export class FillCmd {
|
||||
pubsub: PubSub,
|
||||
jobQueue: JobQueue
|
||||
) => EventWatcherInterface,
|
||||
clients: { [key: string]: any } = {},
|
||||
entityQueryTypeMap?: Map<any, any>,
|
||||
entityToLatestEntityMap?: Map<any, any>
|
||||
): Promise<void> {
|
||||
await this.initConfig();
|
||||
|
||||
await this._baseCmd.init(Database, Indexer, clients, entityQueryTypeMap, entityToLatestEntityMap);
|
||||
graphWatcher?: GraphWatcherInterface
|
||||
) {
|
||||
await this._baseCmd.initIndexer(Indexer, graphWatcher);
|
||||
await this._baseCmd.initEventWatcher(EventWatcher);
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,6 @@ import { ConnectionOptions } from 'typeorm';
|
||||
import { PubSub } from 'graphql-subscriptions';
|
||||
|
||||
import { JsonRpcProvider } from '@ethersproject/providers';
|
||||
import { GraphWatcher, updateEntitiesFromState } from '@cerc-io/graph-node';
|
||||
import { EthClient } from '@cerc-io/ipld-eth-client';
|
||||
import {
|
||||
DEFAULT_CONFIG_PATH,
|
||||
@ -23,7 +22,11 @@ import {
|
||||
Clients,
|
||||
EventWatcherInterface,
|
||||
fillBlocks,
|
||||
StateKind
|
||||
StateKind,
|
||||
GraphWatcherInterface,
|
||||
GraphDatabase,
|
||||
updateEntitiesFromState,
|
||||
Config
|
||||
} from '@cerc-io/util';
|
||||
import * as codec from '@ipld/dag-cbor';
|
||||
|
||||
@ -44,6 +47,22 @@ export class ImportStateCmd {
|
||||
this._baseCmd = new BaseCmd();
|
||||
}
|
||||
|
||||
get config (): Config | undefined {
|
||||
return this._baseCmd.config;
|
||||
}
|
||||
|
||||
get clients (): Clients | undefined {
|
||||
return this._baseCmd.clients;
|
||||
}
|
||||
|
||||
get ethProvider (): JsonRpcProvider | undefined {
|
||||
return this._baseCmd.ethProvider;
|
||||
}
|
||||
|
||||
get database (): DatabaseInterface | undefined {
|
||||
return this._baseCmd.database;
|
||||
}
|
||||
|
||||
async initConfig<ConfigType> (): Promise<ConfigType> {
|
||||
this._argv = this._getArgv();
|
||||
assert(this._argv);
|
||||
@ -56,13 +75,21 @@ export class ImportStateCmd {
|
||||
config: ConnectionOptions,
|
||||
serverConfig?: ServerConfig
|
||||
) => DatabaseInterface,
|
||||
clients: { [key: string]: any } = {}
|
||||
): Promise<void> {
|
||||
await this.initConfig();
|
||||
|
||||
await this._baseCmd.init(Database, clients);
|
||||
}
|
||||
|
||||
async initIndexer (
|
||||
Indexer: new (
|
||||
serverConfig: ServerConfig,
|
||||
db: DatabaseInterface,
|
||||
clients: Clients,
|
||||
ethProvider: JsonRpcProvider,
|
||||
jobQueue: JobQueue,
|
||||
graphWatcher?: GraphWatcher
|
||||
graphWatcher?: GraphWatcherInterface
|
||||
) => IndexerInterface,
|
||||
EventWatcher: new(
|
||||
ethClient: EthClient,
|
||||
@ -70,15 +97,13 @@ export class ImportStateCmd {
|
||||
pubsub: PubSub,
|
||||
jobQueue: JobQueue
|
||||
) => EventWatcherInterface,
|
||||
clients: { [key: string]: any } = {}
|
||||
): Promise<void> {
|
||||
await this.initConfig();
|
||||
|
||||
await this._baseCmd.init(Database, Indexer, clients);
|
||||
graphWatcher?: GraphWatcherInterface
|
||||
) {
|
||||
await this._baseCmd.initIndexer(Indexer, graphWatcher);
|
||||
await this._baseCmd.initEventWatcher(EventWatcher);
|
||||
}
|
||||
|
||||
async exec (State: new() => any): Promise<void> {
|
||||
async exec (State: new() => any, graphDb?: GraphDatabase): Promise<void> {
|
||||
assert(this._argv);
|
||||
|
||||
const config = this._baseCmd.config;
|
||||
@ -134,12 +159,8 @@ export class ImportStateCmd {
|
||||
// relationsMap defined for the watcher,
|
||||
// graphDb instance is avaiable
|
||||
// TODO: Fill latest entity tables
|
||||
if (indexer.getRelationsMap) {
|
||||
if (this._baseCmd.graphDb) {
|
||||
await updateEntitiesFromState(this._baseCmd.graphDb, indexer, state);
|
||||
} else if (database.graphDatabase) {
|
||||
await updateEntitiesFromState(database.graphDatabase, indexer, state);
|
||||
}
|
||||
if (indexer.getRelationsMap && graphDb) {
|
||||
await updateEntitiesFromState(graphDb, indexer, state);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,6 @@ import assert from 'assert';
|
||||
import { ConnectionOptions } from 'typeorm';
|
||||
|
||||
import { JsonRpcProvider } from '@ethersproject/providers';
|
||||
import { GraphWatcher } from '@cerc-io/graph-node';
|
||||
import {
|
||||
DEFAULT_CONFIG_PATH,
|
||||
JobQueue,
|
||||
@ -16,7 +15,9 @@ import {
|
||||
IndexerInterface,
|
||||
ServerConfig,
|
||||
Clients,
|
||||
indexBlock
|
||||
indexBlock,
|
||||
GraphWatcherInterface,
|
||||
Config
|
||||
} from '@cerc-io/util';
|
||||
|
||||
import { BaseCmd } from './base';
|
||||
@ -34,6 +35,22 @@ export class IndexBlockCmd {
|
||||
this._baseCmd = new BaseCmd();
|
||||
}
|
||||
|
||||
get config (): Config | undefined {
|
||||
return this._baseCmd.config;
|
||||
}
|
||||
|
||||
get clients (): Clients | undefined {
|
||||
return this._baseCmd.clients;
|
||||
}
|
||||
|
||||
get ethProvider (): JsonRpcProvider | undefined {
|
||||
return this._baseCmd.ethProvider;
|
||||
}
|
||||
|
||||
get database (): DatabaseInterface | undefined {
|
||||
return this._baseCmd.database;
|
||||
}
|
||||
|
||||
async initConfig<ConfigType> (): Promise<ConfigType> {
|
||||
this._argv = this._getArgv();
|
||||
assert(this._argv);
|
||||
@ -46,19 +63,25 @@ export class IndexBlockCmd {
|
||||
config: ConnectionOptions,
|
||||
serverConfig?: ServerConfig
|
||||
) => DatabaseInterface,
|
||||
clients: { [key: string]: any } = {}
|
||||
): Promise<void> {
|
||||
await this.initConfig();
|
||||
|
||||
await this._baseCmd.init(Database, clients);
|
||||
}
|
||||
|
||||
async initIndexer (
|
||||
Indexer: new (
|
||||
serverConfig: ServerConfig,
|
||||
db: DatabaseInterface,
|
||||
clients: Clients,
|
||||
ethProvider: JsonRpcProvider,
|
||||
jobQueue: JobQueue,
|
||||
graphWatcher?: GraphWatcher
|
||||
graphWatcher?: GraphWatcherInterface
|
||||
) => IndexerInterface,
|
||||
clients: { [key: string]: any } = {}
|
||||
): Promise<void> {
|
||||
await this.initConfig();
|
||||
|
||||
await this._baseCmd.init(Database, Indexer, clients);
|
||||
graphWatcher?: GraphWatcherInterface
|
||||
) {
|
||||
return this._baseCmd.initIndexer(Indexer, graphWatcher);
|
||||
}
|
||||
|
||||
async exec (): Promise<void> {
|
||||
|
@ -10,14 +10,15 @@ import { ConnectionOptions } from 'typeorm';
|
||||
import util from 'util';
|
||||
|
||||
import { JsonRpcProvider } from '@ethersproject/providers';
|
||||
import { GraphWatcher } from '@cerc-io/graph-node';
|
||||
import {
|
||||
DEFAULT_CONFIG_PATH,
|
||||
JobQueue,
|
||||
DatabaseInterface,
|
||||
IndexerInterface,
|
||||
ServerConfig,
|
||||
Clients
|
||||
Clients,
|
||||
GraphWatcherInterface,
|
||||
Config
|
||||
} from '@cerc-io/util';
|
||||
|
||||
import { BaseCmd } from './base';
|
||||
@ -37,6 +38,22 @@ export class InspectCIDCmd {
|
||||
this._baseCmd = new BaseCmd();
|
||||
}
|
||||
|
||||
get config (): Config | undefined {
|
||||
return this._baseCmd.config;
|
||||
}
|
||||
|
||||
get clients (): Clients | undefined {
|
||||
return this._baseCmd.clients;
|
||||
}
|
||||
|
||||
get ethProvider (): JsonRpcProvider | undefined {
|
||||
return this._baseCmd.ethProvider;
|
||||
}
|
||||
|
||||
get database (): DatabaseInterface | undefined {
|
||||
return this._baseCmd.database;
|
||||
}
|
||||
|
||||
async initConfig<ConfigType> (): Promise<ConfigType> {
|
||||
this._argv = this._getArgv();
|
||||
assert(this._argv);
|
||||
@ -49,19 +66,25 @@ export class InspectCIDCmd {
|
||||
config: ConnectionOptions,
|
||||
serverConfig?: ServerConfig
|
||||
) => DatabaseInterface,
|
||||
clients: { [key: string]: any } = {}
|
||||
): Promise<void> {
|
||||
await this.initConfig();
|
||||
|
||||
await this._baseCmd.init(Database, clients);
|
||||
}
|
||||
|
||||
async initIndexer (
|
||||
Indexer: new (
|
||||
serverConfig: ServerConfig,
|
||||
db: DatabaseInterface,
|
||||
clients: Clients,
|
||||
ethProvider: JsonRpcProvider,
|
||||
jobQueue: JobQueue,
|
||||
graphWatcher?: GraphWatcher
|
||||
graphWatcher?: GraphWatcherInterface
|
||||
) => IndexerInterface,
|
||||
clients: { [key: string]: any } = {}
|
||||
): Promise<void> {
|
||||
await this.initConfig();
|
||||
|
||||
await this._baseCmd.init(Database, Indexer, clients);
|
||||
graphWatcher?: GraphWatcherInterface
|
||||
) {
|
||||
return this._baseCmd.initIndexer(Indexer, graphWatcher);
|
||||
}
|
||||
|
||||
async exec (): Promise<void> {
|
||||
|
@ -9,7 +9,6 @@ import assert from 'assert';
|
||||
import { ConnectionOptions } from 'typeorm';
|
||||
|
||||
import { JsonRpcProvider } from '@ethersproject/providers';
|
||||
import { GraphWatcher } from '@cerc-io/graph-node';
|
||||
import {
|
||||
DEFAULT_CONFIG_PATH,
|
||||
JobQueue,
|
||||
@ -18,7 +17,9 @@ import {
|
||||
ServerConfig,
|
||||
Clients,
|
||||
JobRunner,
|
||||
startMetricsServer
|
||||
GraphWatcherInterface,
|
||||
startMetricsServer,
|
||||
Config
|
||||
} from '@cerc-io/util';
|
||||
|
||||
import { BaseCmd } from './base';
|
||||
@ -35,6 +36,22 @@ export class JobRunnerCmd {
|
||||
this._baseCmd = new BaseCmd();
|
||||
}
|
||||
|
||||
get config (): Config | undefined {
|
||||
return this._baseCmd.config;
|
||||
}
|
||||
|
||||
get clients (): Clients | undefined {
|
||||
return this._baseCmd.clients;
|
||||
}
|
||||
|
||||
get ethProvider (): JsonRpcProvider | undefined {
|
||||
return this._baseCmd.ethProvider;
|
||||
}
|
||||
|
||||
get database (): DatabaseInterface | undefined {
|
||||
return this._baseCmd.database;
|
||||
}
|
||||
|
||||
get jobQueue (): JobQueue | undefined {
|
||||
return this._baseCmd.jobQueue;
|
||||
}
|
||||
@ -55,21 +72,25 @@ export class JobRunnerCmd {
|
||||
config: ConnectionOptions,
|
||||
serverConfig?: ServerConfig
|
||||
) => DatabaseInterface,
|
||||
clients: { [key: string]: any } = {}
|
||||
): Promise<void> {
|
||||
await this.initConfig();
|
||||
|
||||
await this._baseCmd.init(Database, clients);
|
||||
}
|
||||
|
||||
async initIndexer (
|
||||
Indexer: new (
|
||||
serverConfig: ServerConfig,
|
||||
db: DatabaseInterface,
|
||||
clients: Clients,
|
||||
ethProvider: JsonRpcProvider,
|
||||
jobQueue: JobQueue,
|
||||
graphWatcher?: GraphWatcher
|
||||
graphWatcher?: GraphWatcherInterface
|
||||
) => IndexerInterface,
|
||||
clients: { [key: string]: any } = {},
|
||||
entityQueryTypeMap?: Map<any, any>,
|
||||
entityToLatestEntityMap?: Map<any, any>
|
||||
): Promise<void> {
|
||||
await this.initConfig();
|
||||
|
||||
await this._baseCmd.init(Database, Indexer, clients, entityQueryTypeMap, entityToLatestEntityMap);
|
||||
graphWatcher?: GraphWatcherInterface
|
||||
) {
|
||||
return this._baseCmd.initIndexer(Indexer, graphWatcher);
|
||||
}
|
||||
|
||||
async exec (startJobRunner: (jobRunner: JobRunner) => Promise<void>): Promise<void> {
|
||||
|
@ -8,13 +8,14 @@ import assert from 'assert';
|
||||
import { ConnectionOptions } from 'typeorm';
|
||||
|
||||
import { JsonRpcProvider } from '@ethersproject/providers';
|
||||
import { GraphWatcher } from '@cerc-io/graph-node';
|
||||
import {
|
||||
JobQueue,
|
||||
DatabaseInterface,
|
||||
IndexerInterface,
|
||||
ServerConfig,
|
||||
Clients
|
||||
Clients,
|
||||
GraphWatcherInterface,
|
||||
Config
|
||||
} from '@cerc-io/util';
|
||||
|
||||
import { BaseCmd } from '../base';
|
||||
@ -34,6 +35,22 @@ export class ResetWatcherCmd {
|
||||
this._baseCmd = new BaseCmd();
|
||||
}
|
||||
|
||||
get config (): Config | undefined {
|
||||
return this._baseCmd.config;
|
||||
}
|
||||
|
||||
get clients (): Clients | undefined {
|
||||
return this._baseCmd.clients;
|
||||
}
|
||||
|
||||
get ethProvider (): JsonRpcProvider | undefined {
|
||||
return this._baseCmd.ethProvider;
|
||||
}
|
||||
|
||||
get database (): DatabaseInterface | undefined {
|
||||
return this._baseCmd.database;
|
||||
}
|
||||
|
||||
async initConfig<ConfigType> (configFile: string): Promise<ConfigType> {
|
||||
return this._baseCmd.initConfig(configFile);
|
||||
}
|
||||
@ -44,20 +61,26 @@ export class ResetWatcherCmd {
|
||||
config: ConnectionOptions,
|
||||
serverConfig?: ServerConfig
|
||||
) => DatabaseInterface,
|
||||
clients: { [key: string]: any } = {}
|
||||
): Promise<void> {
|
||||
this._argv = argv;
|
||||
await this.initConfig(argv.configFile);
|
||||
|
||||
await this._baseCmd.init(Database, clients);
|
||||
}
|
||||
|
||||
async initIndexer (
|
||||
Indexer: new (
|
||||
serverConfig: ServerConfig,
|
||||
db: DatabaseInterface,
|
||||
clients: Clients,
|
||||
ethProvider: JsonRpcProvider,
|
||||
jobQueue: JobQueue,
|
||||
graphWatcher?: GraphWatcher
|
||||
graphWatcher?: GraphWatcherInterface
|
||||
) => IndexerInterface,
|
||||
clients: { [key: string]: any } = {}
|
||||
): Promise<void> {
|
||||
this._argv = argv;
|
||||
await this.initConfig(argv.configFile);
|
||||
|
||||
await this._baseCmd.init(Database, Indexer, clients);
|
||||
graphWatcher?: GraphWatcherInterface
|
||||
) {
|
||||
return this._baseCmd.initIndexer(Indexer, graphWatcher);
|
||||
}
|
||||
|
||||
async exec (): Promise<void> {
|
||||
|
@ -12,7 +12,6 @@ import express, { Application } from 'express';
|
||||
import { ApolloServer } from 'apollo-server-express';
|
||||
|
||||
import { JsonRpcProvider } from '@ethersproject/providers';
|
||||
import { GraphWatcher } from '@cerc-io/graph-node';
|
||||
import { EthClient } from '@cerc-io/ipld-eth-client';
|
||||
import {
|
||||
DEFAULT_CONFIG_PATH,
|
||||
@ -24,7 +23,9 @@ import {
|
||||
EventWatcherInterface,
|
||||
KIND_ACTIVE,
|
||||
createAndStartServer,
|
||||
startGQLMetricsServer
|
||||
startGQLMetricsServer,
|
||||
GraphWatcherInterface,
|
||||
Config
|
||||
} from '@cerc-io/util';
|
||||
import { TypeSource } from '@graphql-tools/utils';
|
||||
|
||||
@ -42,6 +43,22 @@ export class ServerCmd {
|
||||
this._baseCmd = new BaseCmd();
|
||||
}
|
||||
|
||||
get config (): Config | undefined {
|
||||
return this._baseCmd.config;
|
||||
}
|
||||
|
||||
get clients (): Clients | undefined {
|
||||
return this._baseCmd.clients;
|
||||
}
|
||||
|
||||
get ethProvider (): JsonRpcProvider | undefined {
|
||||
return this._baseCmd.ethProvider;
|
||||
}
|
||||
|
||||
get database (): DatabaseInterface | undefined {
|
||||
return this._baseCmd.database;
|
||||
}
|
||||
|
||||
async initConfig<ConfigType> (): Promise<ConfigType> {
|
||||
this._argv = this._getArgv();
|
||||
assert(this._argv);
|
||||
@ -54,13 +71,21 @@ export class ServerCmd {
|
||||
config: ConnectionOptions,
|
||||
serverConfig?: ServerConfig
|
||||
) => DatabaseInterface,
|
||||
clients: { [key: string]: any } = {}
|
||||
): Promise<void> {
|
||||
await this.initConfig();
|
||||
|
||||
await this._baseCmd.init(Database, clients);
|
||||
}
|
||||
|
||||
async initIndexer (
|
||||
Indexer: new (
|
||||
serverConfig: ServerConfig,
|
||||
db: DatabaseInterface,
|
||||
clients: Clients,
|
||||
ethProvider: JsonRpcProvider,
|
||||
jobQueue: JobQueue,
|
||||
graphWatcher?: GraphWatcher
|
||||
graphWatcher?: GraphWatcherInterface
|
||||
) => IndexerInterface,
|
||||
EventWatcher: new(
|
||||
ethClient: EthClient,
|
||||
@ -68,13 +93,9 @@ export class ServerCmd {
|
||||
pubsub: PubSub,
|
||||
jobQueue: JobQueue
|
||||
) => EventWatcherInterface,
|
||||
clients: { [key: string]: any } = {},
|
||||
entityQueryTypeMap?: Map<any, any>,
|
||||
entityToLatestEntityMap?: Map<any, any>
|
||||
): Promise<void> {
|
||||
await this.initConfig();
|
||||
|
||||
await this._baseCmd.init(Database, Indexer, clients, entityQueryTypeMap, entityToLatestEntityMap);
|
||||
graphWatcher?: GraphWatcherInterface
|
||||
) {
|
||||
await this._baseCmd.initIndexer(Indexer, graphWatcher);
|
||||
await this._baseCmd.initEventWatcher(EventWatcher);
|
||||
}
|
||||
|
||||
|
@ -8,14 +8,15 @@ import assert from 'assert';
|
||||
import { ConnectionOptions } from 'typeorm';
|
||||
|
||||
import { JsonRpcProvider } from '@ethersproject/providers';
|
||||
import { GraphWatcher } from '@cerc-io/graph-node';
|
||||
import {
|
||||
DEFAULT_CONFIG_PATH,
|
||||
JobQueue,
|
||||
DatabaseInterface,
|
||||
IndexerInterface,
|
||||
ServerConfig,
|
||||
Clients
|
||||
Clients,
|
||||
GraphWatcherInterface,
|
||||
Config
|
||||
} from '@cerc-io/util';
|
||||
|
||||
import { BaseCmd } from './base';
|
||||
@ -36,6 +37,22 @@ export class WatchContractCmd {
|
||||
this._baseCmd = new BaseCmd();
|
||||
}
|
||||
|
||||
get config (): Config | undefined {
|
||||
return this._baseCmd.config;
|
||||
}
|
||||
|
||||
get clients (): Clients | undefined {
|
||||
return this._baseCmd.clients;
|
||||
}
|
||||
|
||||
get ethProvider (): JsonRpcProvider | undefined {
|
||||
return this._baseCmd.ethProvider;
|
||||
}
|
||||
|
||||
get database (): DatabaseInterface | undefined {
|
||||
return this._baseCmd.database;
|
||||
}
|
||||
|
||||
async initConfig<ConfigType> (): Promise<ConfigType> {
|
||||
this._argv = this._getArgv();
|
||||
assert(this._argv);
|
||||
@ -48,19 +65,25 @@ export class WatchContractCmd {
|
||||
config: ConnectionOptions,
|
||||
serverConfig?: ServerConfig
|
||||
) => DatabaseInterface,
|
||||
clients: { [key: string]: any } = {}
|
||||
): Promise<void> {
|
||||
await this.initConfig();
|
||||
|
||||
await this._baseCmd.init(Database, clients);
|
||||
}
|
||||
|
||||
async initIndexer (
|
||||
Indexer: new (
|
||||
serverConfig: ServerConfig,
|
||||
db: DatabaseInterface,
|
||||
clients: Clients,
|
||||
ethProvider: JsonRpcProvider,
|
||||
jobQueue: JobQueue,
|
||||
graphWatcher?: GraphWatcher
|
||||
graphWatcher?: GraphWatcherInterface
|
||||
) => IndexerInterface,
|
||||
clients: { [key: string]: any } = {}
|
||||
): Promise<void> {
|
||||
await this.initConfig();
|
||||
|
||||
await this._baseCmd.init(Database, Indexer, clients);
|
||||
graphWatcher?: GraphWatcherInterface
|
||||
) {
|
||||
return this._baseCmd.initIndexer(Indexer, graphWatcher);
|
||||
}
|
||||
|
||||
async exec (): Promise<void> {
|
||||
|
@ -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<void> => {
|
||||
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();
|
||||
};
|
||||
|
@ -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<void> => {
|
||||
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);
|
||||
};
|
||||
|
@ -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';
|
||||
|
@ -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<void> => {
|
||||
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();
|
||||
};
|
||||
|
||||
|
@ -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<any> => {
|
||||
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}});
|
||||
|
@ -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<any> => {
|
||||
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 => {
|
||||
|
@ -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<void> => {
|
||||
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();
|
||||
};
|
||||
|
||||
|
@ -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<string, any>
|
||||
|
||||
{{/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();
|
||||
|
@ -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<void> => {
|
||||
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();
|
||||
};
|
||||
|
||||
|
@ -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<any> => {
|
||||
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<void> => {
|
||||
await jobRunner.subscribeBlockProcessingQueue();
|
||||
|
@ -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<void> => {
|
||||
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();
|
||||
};
|
||||
|
@ -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<any> => {
|
||||
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);
|
||||
};
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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<void> => {
|
||||
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();
|
||||
};
|
||||
|
||||
|
@ -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<void> => {
|
||||
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();
|
||||
};
|
||||
|
@ -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<void> => {
|
||||
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);
|
||||
};
|
||||
|
@ -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<void> => {
|
||||
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();
|
||||
};
|
||||
|
||||
|
@ -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<any> => {
|
||||
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 => {
|
||||
|
@ -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<void> => {
|
||||
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();
|
||||
};
|
||||
|
||||
|
@ -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<void> => {
|
||||
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();
|
||||
};
|
||||
|
||||
|
@ -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<void> => {
|
||||
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();
|
||||
};
|
||||
|
@ -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<void> => {
|
||||
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();
|
||||
};
|
||||
|
||||
|
@ -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';
|
||||
|
@ -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<any> => {
|
||||
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);
|
||||
};
|
||||
|
@ -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<string, any>
|
||||
|
||||
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();
|
||||
|
@ -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<any> => {
|
||||
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<void> => {
|
||||
await jobRunner.subscribeBlockProcessingQueue();
|
||||
|
@ -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<any> => {
|
||||
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);
|
||||
};
|
||||
|
||||
|
@ -19,7 +19,7 @@ export const builder = {
|
||||
|
||||
export const handler = async (argv: any): Promise<void> => {
|
||||
const resetWatcherCmd = new ResetWatcherCmd();
|
||||
await resetWatcherCmd.init(argv, Database, Indexer);
|
||||
|
||||
await resetWatcherCmd.init(argv, Database);
|
||||
await resetWatcherCmd.initIndexer(Indexer);
|
||||
await resetWatcherCmd.exec();
|
||||
};
|
||||
|
@ -14,8 +14,8 @@ const log = debug('vulcanize:watch-contract');
|
||||
|
||||
const main = async (): Promise<void> => {
|
||||
const watchContractCmd = new WatchContractCmd();
|
||||
await watchContractCmd.init(Database, Indexer);
|
||||
|
||||
await watchContractCmd.init(Database);
|
||||
await watchContractCmd.initIndexer(Indexer);
|
||||
await watchContractCmd.exec();
|
||||
};
|
||||
|
||||
|
@ -15,8 +15,8 @@ const log = debug('vulcanize:fill');
|
||||
|
||||
export const main = async (): Promise<any> => {
|
||||
const fillCmd = new FillCmd();
|
||||
await fillCmd.init(Database, Indexer, EventWatcher);
|
||||
|
||||
await fillCmd.init(Database);
|
||||
await fillCmd.initIndexer(Indexer, EventWatcher);
|
||||
await fillCmd.exec();
|
||||
};
|
||||
|
||||
|
@ -14,7 +14,8 @@ const log = debug('vulcanize:job-runner');
|
||||
|
||||
export const main = async (): Promise<any> => {
|
||||
const jobRunnerCmd = new JobRunnerCmd();
|
||||
await jobRunnerCmd.init(Database, Indexer);
|
||||
await jobRunnerCmd.init(Database);
|
||||
await jobRunnerCmd.initIndexer(Indexer);
|
||||
|
||||
await jobRunnerCmd.exec(async (jobRunner: JobRunner): Promise<void> => {
|
||||
await jobRunner.subscribeBlockProcessingQueue();
|
||||
|
@ -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<any> => {
|
||||
const serverCmd = new ServerCmd();
|
||||
await serverCmd.init(Database, Indexer, EventWatcher);
|
||||
await serverCmd.init(Database);
|
||||
await serverCmd.initIndexer(Indexer, EventWatcher);
|
||||
|
||||
return serverCmd.exec(createResolvers, typeDefs);
|
||||
};
|
||||
|
@ -26,7 +26,7 @@ export const builder = {
|
||||
|
||||
export const handler = async (argv: any): Promise<void> => {
|
||||
const createCheckpointCmd = new CreateCheckpointCmd();
|
||||
await createCheckpointCmd.init(argv, Database, Indexer);
|
||||
|
||||
await createCheckpointCmd.init(argv, Database);
|
||||
await createCheckpointCmd.initIndexer(Indexer);
|
||||
await createCheckpointCmd.exec();
|
||||
};
|
||||
|
@ -14,8 +14,8 @@ const log = debug('vulcanize:export-state');
|
||||
|
||||
const main = async (): Promise<void> => {
|
||||
const exportStateCmd = new ExportStateCmd();
|
||||
await exportStateCmd.init(Database, Indexer);
|
||||
|
||||
await exportStateCmd.init(Database);
|
||||
await exportStateCmd.initIndexer(Indexer);
|
||||
await exportStateCmd.exec();
|
||||
};
|
||||
|
||||
|
@ -16,8 +16,8 @@ const log = debug('vulcanize:import-state');
|
||||
|
||||
export const main = async (): Promise<any> => {
|
||||
const importStateCmd = new ImportStateCmd();
|
||||
await importStateCmd.init(Database, Indexer, EventWatcher);
|
||||
|
||||
await importStateCmd.init(Database);
|
||||
await importStateCmd.initIndexer(Indexer, EventWatcher);
|
||||
await importStateCmd.exec(State);
|
||||
};
|
||||
|
||||
|
@ -14,8 +14,8 @@ const log = debug('vulcanize:index-block');
|
||||
|
||||
const main = async (): Promise<void> => {
|
||||
const indexBlockCmd = new IndexBlockCmd();
|
||||
await indexBlockCmd.init(Database, Indexer);
|
||||
|
||||
await indexBlockCmd.init(Database);
|
||||
await indexBlockCmd.initIndexer(Indexer);
|
||||
await indexBlockCmd.exec();
|
||||
};
|
||||
|
||||
|
@ -14,8 +14,8 @@ const log = debug('vulcanize:inspect-cid');
|
||||
|
||||
const main = async (): Promise<void> => {
|
||||
const inspectCIDCmd = new InspectCIDCmd();
|
||||
await inspectCIDCmd.init(Database, Indexer);
|
||||
|
||||
await inspectCIDCmd.init(Database);
|
||||
await inspectCIDCmd.initIndexer(Indexer);
|
||||
await inspectCIDCmd.exec();
|
||||
};
|
||||
|
||||
|
@ -19,7 +19,7 @@ export const builder = {
|
||||
|
||||
export const handler = async (argv: any): Promise<void> => {
|
||||
const resetWatcherCmd = new ResetWatcherCmd();
|
||||
await resetWatcherCmd.init(argv, Database, Indexer);
|
||||
|
||||
await resetWatcherCmd.init(argv, Database);
|
||||
await resetWatcherCmd.initIndexer(Indexer);
|
||||
await resetWatcherCmd.exec();
|
||||
};
|
||||
|
@ -14,8 +14,8 @@ const log = debug('vulcanize:watch-contract');
|
||||
|
||||
const main = async (): Promise<void> => {
|
||||
const watchContractCmd = new WatchContractCmd();
|
||||
await watchContractCmd.init(Database, Indexer);
|
||||
|
||||
await watchContractCmd.init(Database);
|
||||
await watchContractCmd.initIndexer(Indexer);
|
||||
await watchContractCmd.exec();
|
||||
};
|
||||
|
||||
|
@ -15,8 +15,9 @@ const log = debug('vulcanize:fill');
|
||||
|
||||
export const main = async (): Promise<any> => {
|
||||
const fillCmd = new FillCmd();
|
||||
await fillCmd.init(Database, Indexer, EventWatcher);
|
||||
await fillCmd.init(Database);
|
||||
|
||||
await fillCmd.initIndexer(Indexer, EventWatcher);
|
||||
await fillCmd.exec();
|
||||
};
|
||||
|
||||
|
@ -14,7 +14,8 @@ const log = debug('vulcanize:job-runner');
|
||||
|
||||
export const main = async (): Promise<any> => {
|
||||
const jobRunnerCmd = new JobRunnerCmd();
|
||||
await jobRunnerCmd.init(Database, Indexer);
|
||||
await jobRunnerCmd.init(Database);
|
||||
await jobRunnerCmd.initIndexer(Indexer);
|
||||
|
||||
await jobRunnerCmd.exec(async (jobRunner: JobRunner): Promise<void> => {
|
||||
await jobRunner.subscribeBlockProcessingQueue();
|
||||
|
@ -18,10 +18,10 @@ const log = debug('vulcanize:server');
|
||||
|
||||
export const main = async (): Promise<any> => {
|
||||
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);
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<void> => {
|
||||
let blockDelay = wait(0);
|
||||
let subgraphContracts: string[] = [];
|
||||
const contractLatestStateCIDMap: Map<string, { diff: string, checkpoint: string }> = 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<void> => {
|
||||
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) {
|
||||
|
@ -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');
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -1,7 +1 @@
|
||||
export * from './watcher';
|
||||
export * from './database';
|
||||
export {
|
||||
resolveEntityFieldConflicts,
|
||||
afterEntityInsertOrUpdate
|
||||
} from './utils';
|
||||
export * from './state-utils';
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<any, any>,
|
||||
entityToLatestEntityMap?: Map<any, any>
|
||||
): 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
|
||||
};
|
||||
};
|
||||
|
@ -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<string, StorageLayout>): Indexer => {
|
||||
|
@ -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<void> => {
|
||||
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();
|
||||
};
|
||||
|
@ -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<void> => {
|
||||
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);
|
||||
};
|
||||
|
@ -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<void> => {
|
||||
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();
|
||||
};
|
||||
|
||||
|
@ -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<any> => {
|
||||
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 => {
|
||||
|
@ -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<void> => {
|
||||
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();
|
||||
};
|
||||
|
||||
|
@ -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<void> => {
|
||||
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();
|
||||
};
|
||||
|
||||
|
@ -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<void> => {
|
||||
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();
|
||||
};
|
||||
|
@ -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<void> => {
|
||||
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();
|
||||
};
|
||||
|
||||
|
@ -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';
|
||||
|
@ -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<any> => {
|
||||
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);
|
||||
};
|
||||
|
@ -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<string, any>
|
||||
|
||||
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();
|
||||
|
@ -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<any> => {
|
||||
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<void> => {
|
||||
await jobRunner.subscribeBlockProcessingQueue();
|
||||
|
@ -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<any> => {
|
||||
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);
|
||||
};
|
||||
|
||||
|
@ -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"
|
||||
},
|
||||
|
@ -26,7 +26,7 @@ export const builder = {
|
||||
|
||||
export const handler = async (argv: any): Promise<void> => {
|
||||
const createCheckpointCmd = new CreateCheckpointCmd();
|
||||
await createCheckpointCmd.init(argv, Database, Indexer);
|
||||
|
||||
await createCheckpointCmd.init(argv, Database);
|
||||
await createCheckpointCmd.initIndexer(Indexer);
|
||||
await createCheckpointCmd.exec();
|
||||
};
|
||||
|
@ -14,8 +14,8 @@ const log = debug('vulcanize:export-state');
|
||||
|
||||
const main = async (): Promise<void> => {
|
||||
const exportStateCmd = new ExportStateCmd();
|
||||
await exportStateCmd.init(Database, Indexer);
|
||||
|
||||
await exportStateCmd.init(Database);
|
||||
await exportStateCmd.initIndexer(Indexer);
|
||||
await exportStateCmd.exec();
|
||||
};
|
||||
|
||||
|
@ -16,8 +16,8 @@ const log = debug('vulcanize:import-state');
|
||||
|
||||
export const main = async (): Promise<any> => {
|
||||
const importStateCmd = new ImportStateCmd();
|
||||
await importStateCmd.init(Database, Indexer, EventWatcher);
|
||||
|
||||
await importStateCmd.init(Database);
|
||||
await importStateCmd.initIndexer(Indexer, EventWatcher);
|
||||
await importStateCmd.exec(State);
|
||||
};
|
||||
|
||||
|
@ -14,8 +14,8 @@ const log = debug('vulcanize:index-block');
|
||||
|
||||
const main = async (): Promise<void> => {
|
||||
const indexBlockCmd = new IndexBlockCmd();
|
||||
await indexBlockCmd.init(Database, Indexer);
|
||||
|
||||
await indexBlockCmd.init(Database);
|
||||
await indexBlockCmd.initIndexer(Indexer);
|
||||
await indexBlockCmd.exec();
|
||||
};
|
||||
|
||||
|
@ -14,8 +14,8 @@ const log = debug('vulcanize:inspect-cid');
|
||||
|
||||
const main = async (): Promise<void> => {
|
||||
const inspectCIDCmd = new InspectCIDCmd();
|
||||
await inspectCIDCmd.init(Database, Indexer);
|
||||
|
||||
await inspectCIDCmd.init(Database);
|
||||
await inspectCIDCmd.initIndexer(Indexer);
|
||||
await inspectCIDCmd.exec();
|
||||
};
|
||||
|
||||
|
@ -19,7 +19,7 @@ export const builder = {
|
||||
|
||||
export const handler = async (argv: any): Promise<void> => {
|
||||
const resetWatcherCmd = new ResetWatcherCmd();
|
||||
await resetWatcherCmd.init(argv, Database, Indexer);
|
||||
|
||||
await resetWatcherCmd.init(argv, Database);
|
||||
await resetWatcherCmd.initIndexer(Indexer);
|
||||
await resetWatcherCmd.exec();
|
||||
};
|
||||
|
@ -14,8 +14,8 @@ const log = debug('vulcanize:watch-contract');
|
||||
|
||||
const main = async (): Promise<void> => {
|
||||
const watchContractCmd = new WatchContractCmd();
|
||||
await watchContractCmd.init(Database, Indexer);
|
||||
|
||||
await watchContractCmd.init(Database);
|
||||
await watchContractCmd.initIndexer(Indexer);
|
||||
await watchContractCmd.exec();
|
||||
};
|
||||
|
||||
|
@ -15,8 +15,9 @@ const log = debug('vulcanize:fill');
|
||||
|
||||
export const main = async (): Promise<any> => {
|
||||
const fillCmd = new FillCmd();
|
||||
await fillCmd.init(Database, Indexer, EventWatcher);
|
||||
await fillCmd.init(Database);
|
||||
|
||||
await fillCmd.initIndexer(Indexer, EventWatcher);
|
||||
await fillCmd.exec();
|
||||
};
|
||||
|
||||
|
@ -14,7 +14,8 @@ const log = debug('vulcanize:job-runner');
|
||||
|
||||
export const main = async (): Promise<any> => {
|
||||
const jobRunnerCmd = new JobRunnerCmd();
|
||||
await jobRunnerCmd.init(Database, Indexer);
|
||||
await jobRunnerCmd.init(Database);
|
||||
await jobRunnerCmd.initIndexer(Indexer);
|
||||
|
||||
await jobRunnerCmd.exec(async (jobRunner: JobRunner): Promise<void> => {
|
||||
await jobRunner.subscribeBlockProcessingQueue();
|
||||
|
@ -18,10 +18,10 @@ const log = debug('vulcanize:server');
|
||||
|
||||
export const main = async (): Promise<any> => {
|
||||
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);
|
||||
};
|
||||
|
||||
|
@ -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",
|
||||
|
@ -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 .",
|
||||
|
@ -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<string, Map<string, { [key: string]: any }>>;
|
||||
}
|
||||
|
||||
export class Database {
|
||||
export class GraphDatabase {
|
||||
_serverConfig: ServerConfig
|
||||
_conn!: Connection
|
||||
_baseDatabase: BaseDatabase
|
@ -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];
|
||||
};
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user