Fix running erc20-watcher as active kind watcher (#116)

This commit is contained in:
nikugogoi 2022-05-23 18:54:14 +05:30 committed by GitHub
parent 977564d17f
commit b2233e16ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 7 deletions

View File

@ -33,8 +33,33 @@ createdb erc20-watcher
```
Update `environments/local.toml` with database connection settings for both the databases.
```toml
[database]
type = "postgres"
host = "localhost"
port = 5432
database = "erc20-watcher"
username = "postgres"
password = "postgres"
Update the `upstream` config in `environments/local.toml` and provide the `ipld-eth-server` GQL API and the `indexer-db` postgraphile endpoints.
[jobQueue]
dbConnectionString = "postgres://postgres:postgres@localhost/erc20-watcher-job-queue"
```
Update the `upstream` config in `environments/local.toml`. Provide the `ipld-eth-server` GQL and RPC API and the `indexer-db` postgraphile endpoints.
```toml
[upstream]
[upstream.ethServer]
gqlApiEndpoint = "http://127.0.0.1:8082/graphql"
gqlPostgraphileEndpoint = "http://127.0.0.1:5000/graphql"
rpcProviderEndpoint = "http://127.0.0.1:8081"
```
Ensure that watcher is of active kind. Update the kind in `server` config to active.
```toml
[server]
kind = "active"
```
## Run
@ -70,6 +95,11 @@ $ yarn job-runner -f environments/local.toml
GQL console: http://localhost:3001/graphql
Deploy an ERC20 token:
```bash
$ yarn token:deploy
```
Start watching a token:
```bash

View File

@ -76,6 +76,10 @@ export class Indexer implements IndexerInterface {
this._contract = new ethers.utils.Interface(this._abi);
}
async init (): Promise<void> {
await this._baseIndexer.fetchContracts();
}
getResultEvent (event: Event): EventResult {
const eventFields = JSON.parse(event.eventInfo);
@ -303,6 +307,10 @@ export class Indexer implements IndexerInterface {
return this._baseIndexer.watchContract(address, kind, checkpoint, startingBlock);
}
cacheContract (contract: Contract): void {
return this._baseIndexer.cacheContract(contract);
}
async saveEventEntity (dbEvent: Event): Promise<Event> {
return this._baseIndexer.saveEventEntity(dbEvent);
}

View File

@ -83,6 +83,7 @@ export const main = async (): Promise<any> => {
await jobQueue.start();
const indexer = new Indexer(db, ethClient, postgraphileClient, ethProvider, jobQueue, config.server.mode);
await indexer.init();
const jobRunner = new JobRunner(jobQueueConfig, indexer, jobQueue);
await jobRunner.start();

View File

@ -56,6 +56,7 @@ export const main = async (): Promise<any> => {
const jobQueue = new JobQueue({ dbConnectionString, maxCompletionLag: maxCompletionLagInSecs });
const indexer = new Indexer(db, ethClient, postgraphileClient, ethProvider, jobQueue, mode);
await indexer.init();
const eventWatcher = new EventWatcher(config.upstream, ethClient, postgraphileClient, indexer, pubsub, jobQueue);

View File

@ -209,12 +209,14 @@ export class Indexer {
}
async getEventsByFilter (blockHash: string, contract?: string, name?: string): Promise<Array<EventInterface>> {
if (contract) {
const watchedContract = await this.isWatchedContract(contract);
if (!watchedContract) {
throw new Error('Not a watched contract');
}
}
// TODO: Uncomment after implementing hot reload of watched contracts in server process.
// This doesn't affect functionality as we already have a filter condition on the contract in the query.
// if (contract) {
// const watchedContract = await this.isWatchedContract(contract);
// if (!watchedContract) {
// throw new Error('Not a watched contract');
// }
// }
const where: Where = {
eventName: [{