Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fill and fill-state CLIs from cli package #411

Merged
merged 7 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions packages/erc20-watcher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,3 @@ $ yarn fill --startBlock 1000 --endBlock 2000
}

```

## Test

To run tests (GQL queries) against the mock server:

```
yarn run server:mock
```

```bash
yarn test
```
2 changes: 0 additions & 2 deletions packages/erc20-watcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
"main": "dist/index.js",
"scripts": {
"lint": "eslint .",
"test": "mocha -r ts-node/register src/**/*.test.ts",
"build": "tsc",
"server": "DEBUG=vulcanize:* node --enable-source-maps dist/server.js",
"server:dev": "DEBUG=vulcanize:* nodemon --watch src src/server.ts",
"server:mock": "MOCK=1 nodemon src/server.ts",
"job-runner": "DEBUG=vulcanize:* node --enable-source-maps dist/job-runner.js",
"job-runner:dev": "DEBUG=vulcanize:* nodemon --watch src src/job-runner.ts",
"watch:contract": "node --enable-source-maps dist/cli/watch-contract.js",
Expand Down
4 changes: 4 additions & 0 deletions packages/erc20-watcher/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ export class Database implements DatabaseInterface {
return this._baseDatabase.getBlockProgressEntities(repo, where, options);
}

async getEntitiesForBlock (blockHash: string, tableName: string): Promise<any[]> {
return this._baseDatabase.getEntitiesForBlock(blockHash, tableName);
}

async saveBlockProgress (queryRunner: QueryRunner, block: DeepPartial<BlockProgress>): Promise<BlockProgress> {
const repo = queryRunner.manager.getRepository(BlockProgress);

Expand Down
91 changes: 4 additions & 87 deletions packages/erc20-watcher/src/fill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@
// Copyright 2021 Vulcanize, Inc.
//

import assert from 'assert';
import 'reflect-metadata';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import debug from 'debug';
import { PubSub } from 'graphql-subscriptions';

import { DEFAULT_CONFIG_PATH, JobQueue, getCustomProvider, getConfig, fillBlocks, DEFAULT_PREFETCH_BATCH_SIZE } from '@cerc-io/util';
import { EthClient } from '@cerc-io/ipld-eth-client';
import { getCache } from '@cerc-io/cache';
import { Config } from '@vulcanize/util';
import { FillCmd } from '@cerc-io/cli';

import { Database } from './database';
import { Indexer } from './indexer';
Expand All @@ -21,86 +14,10 @@ import { EventWatcher } from './events';
const log = debug('vulcanize:server');

export const main = async (): Promise<any> => {
const argv = await yargs(hideBin(process.argv)).parserConfiguration({
'parse-numbers': false
}).env(
'FILL'
).options({
configFile: {
alias: 'f',
type: 'string',
require: true,
demandOption: true,
describe: 'configuration file path (toml)',
default: DEFAULT_CONFIG_PATH
},
startBlock: {
type: 'number',
require: true,
demandOption: true,
describe: 'Block number to start processing at'
},
endBlock: {
type: 'number',
require: true,
demandOption: true,
describe: 'Block number to stop processing at'
},
prefetch: {
type: 'boolean',
default: false,
describe: 'Block and events prefetch mode'
},
batchBlocks: {
type: 'number',
default: DEFAULT_PREFETCH_BATCH_SIZE,
describe: 'Number of blocks prefetched in batch'
},
blockCid: {
type: 'boolean',
default: false,
describe: 'Only fetch and update block CIDs'
}
}).argv;
const fillCmd = new FillCmd();
await fillCmd.init(Database, Indexer, EventWatcher);

const config: Config = await getConfig(argv.configFile);

assert(config.server, 'Missing server config');

const { upstream, database: dbConfig, jobQueue: jobQueueConfig } = config;

assert(dbConfig, 'Missing database config');

const db = new Database(dbConfig);
await db.init();

assert(upstream, 'Missing upstream config');
const { ethServer: { gqlApiEndpoint, rpcProviderEndpoint }, cache: cacheConfig } = upstream;

const cache = await getCache(cacheConfig);
const ethClient = new EthClient({
gqlEndpoint: gqlApiEndpoint,
cache
});

const ethProvider = getCustomProvider(rpcProviderEndpoint);

// Note: In-memory pubsub works fine for now, as each watcher is a single process anyway.
// Later: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#production-pubsub-libraries
const pubsub = new PubSub();

assert(jobQueueConfig, 'Missing job queue config');
const { dbConnectionString, maxCompletionLagInSecs } = jobQueueConfig;
assert(dbConnectionString, 'Missing job queue db connection string');

const jobQueue = new JobQueue({ dbConnectionString, maxCompletionLag: maxCompletionLagInSecs });
await jobQueue.start();

const indexer = new Indexer(config.server, db, { ethClient }, ethProvider, jobQueue);

const eventWatcher = new EventWatcher(ethClient, indexer, pubsub, jobQueue);

await fillBlocks(jobQueue, indexer, eventWatcher, jobQueueConfig.blockDelayInMilliSecs, argv);
await fillCmd.exec();
};

main().catch(err => {
Expand Down
18 changes: 17 additions & 1 deletion packages/erc20-watcher/src/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ export class Indexer implements IndexerInterface {
);
}

async getEntitiesForBlock (blockHash: string, tableName: string): Promise<any[]> {
return this._db.getEntitiesForBlock(blockHash, tableName);
}

getStateData (state: State): any {
return this._baseIndexer.getStateData(state);
}
Expand Down Expand Up @@ -378,7 +382,19 @@ export class Indexer implements IndexerInterface {
return undefined;
}

// Method to be used by export-state CLI.
async getStates (where: FindConditions<State>): Promise<State[]> {
// TODO Implement
return [];
}

async createDiffStaged (contractAddress: string, blockHash: string, data: any): Promise<void> {
// TODO Implement
}

async createDiff (contractAddress: string, blockHash: string, data: any): Promise<void> {
// TODO Implement
}

async createCheckpoint (contractAddress: string, blockHash: string): Promise<string | undefined> {
// TODO Implement
return undefined;
Expand Down
50 changes: 0 additions & 50 deletions packages/erc20-watcher/src/mock/data.ts

This file was deleted.

90 changes: 0 additions & 90 deletions packages/erc20-watcher/src/mock/resolvers.ts

This file was deleted.

Loading