diff --git a/packages/erc20-watcher/README.md b/packages/erc20-watcher/README.md index fa0ca998d..5fa464504 100644 --- a/packages/erc20-watcher/README.md +++ b/packages/erc20-watcher/README.md @@ -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 diff --git a/packages/erc20-watcher/src/indexer.ts b/packages/erc20-watcher/src/indexer.ts index f098ffd29..4415bb918 100644 --- a/packages/erc20-watcher/src/indexer.ts +++ b/packages/erc20-watcher/src/indexer.ts @@ -76,6 +76,10 @@ export class Indexer implements IndexerInterface { this._contract = new ethers.utils.Interface(this._abi); } + async init (): Promise { + 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 { return this._baseIndexer.saveEventEntity(dbEvent); } diff --git a/packages/erc20-watcher/src/job-runner.ts b/packages/erc20-watcher/src/job-runner.ts index 526a6987c..402b2062c 100644 --- a/packages/erc20-watcher/src/job-runner.ts +++ b/packages/erc20-watcher/src/job-runner.ts @@ -83,6 +83,7 @@ export const main = async (): Promise => { 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(); diff --git a/packages/erc20-watcher/src/server.ts b/packages/erc20-watcher/src/server.ts index 18d59181b..ac3a2f25d 100644 --- a/packages/erc20-watcher/src/server.ts +++ b/packages/erc20-watcher/src/server.ts @@ -56,6 +56,7 @@ export const main = async (): Promise => { 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); diff --git a/packages/util/src/indexer.ts b/packages/util/src/indexer.ts index 4c9c0b264..634ba3db3 100644 --- a/packages/util/src/indexer.ts +++ b/packages/util/src/indexer.ts @@ -209,12 +209,14 @@ export class Indexer { } async getEventsByFilter (blockHash: string, contract?: string, name?: string): Promise> { - 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: [{