From 168689a7c7574b85926b8d59ef34990eeab68cd3 Mon Sep 17 00:00:00 2001 From: nikugogoi Date: Thu, 26 May 2022 18:00:17 +0530 Subject: [PATCH] Fix codegen for non subgraph watchers (#120) * Fix codegen for non subgraph watchers * Remove graphWatcher.init from generated non subgraph watcher --- .gitignore | 2 ++ packages/codegen/src/checkpoint.ts | 4 ++-- packages/codegen/src/export-state.ts | 4 ++-- packages/codegen/src/fill.ts | 4 ++-- packages/codegen/src/generate-code.ts | 18 +++++++++--------- packages/codegen/src/import-state.ts | 4 ++-- packages/codegen/src/inspect-cid.ts | 4 ++-- packages/codegen/src/job-runner.ts | 4 ++-- packages/codegen/src/reset.ts | 5 +++-- packages/codegen/src/server.ts | 4 ++-- .../templates/checkpoint-template.handlebars | 2 ++ .../templates/export-state-template.handlebars | 2 ++ .../src/templates/fill-template.handlebars | 2 ++ .../templates/import-state-template.handlebars | 2 ++ .../src/templates/indexer-template.handlebars | 13 +++++++++---- .../templates/inspect-cid-template.handlebars | 2 ++ .../templates/job-runner-template.handlebars | 2 ++ .../templates/reset-state-template.handlebars | 2 ++ .../src/templates/server-template.handlebars | 2 ++ .../watch-contract-template.handlebars | 2 ++ packages/codegen/src/visitor.ts | 4 ++-- packages/codegen/src/watch-contract.ts | 4 ++-- packages/eden-watcher/src/indexer.ts | 13 +++++++++---- .../erc20-watcher/test/tasks/token-approve.ts | 2 +- .../erc20-watcher/test/tasks/token-deploy.ts | 2 ++ .../test/tasks/token-transfer-from.ts | 2 +- .../erc20-watcher/test/tasks/token-transfer.ts | 2 +- packages/graph-test-watcher/src/indexer.ts | 13 +++++++++---- packages/util/src/job-runner.ts | 9 +++++++-- packages/util/src/types.ts | 5 +++++ 30 files changed, 94 insertions(+), 46 deletions(-) diff --git a/.gitignore b/.gitignore index e62ff4c01..82792c641 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ node_modules/ dist/ out/ + +.vscode diff --git a/packages/codegen/src/checkpoint.ts b/packages/codegen/src/checkpoint.ts index 25d0bcc48..15c86eda2 100644 --- a/packages/codegen/src/checkpoint.ts +++ b/packages/codegen/src/checkpoint.ts @@ -13,9 +13,9 @@ const TEMPLATE_FILE = './templates/checkpoint-template.handlebars'; * Writes the checkpoint file generated from a template to a stream. * @param outStream A writable output stream to write the checkpoint file to. */ -export function exportCheckpoint (outStream: Writable): void { +export function exportCheckpoint (outStream: Writable, subgraphPath: string): void { const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString(); const template = Handlebars.compile(templateString); - const checkpoint = template({}); + const checkpoint = template({ subgraphPath }); outStream.write(checkpoint); } diff --git a/packages/codegen/src/export-state.ts b/packages/codegen/src/export-state.ts index 5d95f505b..74f9f3b78 100644 --- a/packages/codegen/src/export-state.ts +++ b/packages/codegen/src/export-state.ts @@ -13,9 +13,9 @@ const TEMPLATE_FILE = './templates/export-state-template.handlebars'; * Writes the export-state file generated from a template to a stream. * @param outStream A writable output stream to write the export-state file to. */ -export function exportState (outStream: Writable): void { +export function exportState (outStream: Writable, subgraphPath: string): void { const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString(); const template = Handlebars.compile(templateString); - const exportState = template({}); + const exportState = template({ subgraphPath }); outStream.write(exportState); } diff --git a/packages/codegen/src/fill.ts b/packages/codegen/src/fill.ts index 6d72107ba..049a79b93 100644 --- a/packages/codegen/src/fill.ts +++ b/packages/codegen/src/fill.ts @@ -13,9 +13,9 @@ const TEMPLATE_FILE = './templates/fill-template.handlebars'; * Writes the fill file generated from a template to a stream. * @param outStream A writable output stream to write the fill file to. */ -export function exportFill (outStream: Writable): void { +export function exportFill (outStream: Writable, subgraphPath: string): void { const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString(); const template = Handlebars.compile(templateString); - const fill = template({}); + const fill = template({ subgraphPath }); outStream.write(fill); } diff --git a/packages/codegen/src/generate-code.ts b/packages/codegen/src/generate-code.ts index 592844451..d2766a36a 100644 --- a/packages/codegen/src/generate-code.ts +++ b/packages/codegen/src/generate-code.ts @@ -188,7 +188,7 @@ function generateWatcher (visitor: Visitor, contracts: any[], config: any) { outStream = outputDir ? fs.createWriteStream(path.join(outputDir, 'src/server.ts')) : process.stdout; - exportServer(outStream); + exportServer(outStream, config.subgraphPath); outStream = outputDir ? fs.createWriteStream(path.join(outputDir, 'environments/local.toml')) @@ -228,17 +228,17 @@ function generateWatcher (visitor: Visitor, contracts: any[], config: any) { outStream = outputDir ? fs.createWriteStream(path.join(outputDir, 'src/job-runner.ts')) : process.stdout; - exportJobRunner(outStream); + exportJobRunner(outStream, config.subgraphPath); outStream = outputDir ? fs.createWriteStream(path.join(outputDir, 'src/cli/watch-contract.ts')) : process.stdout; - exportWatchContract(outStream); + exportWatchContract(outStream, config.subgraphPath); outStream = outputDir ? fs.createWriteStream(path.join(outputDir, 'src/cli/checkpoint.ts')) : process.stdout; - exportCheckpoint(outStream); + exportCheckpoint(outStream, config.subgraphPath); outStream = outputDir ? fs.createWriteStream(path.join(outputDir, 'src/hooks.ts')) @@ -248,7 +248,7 @@ function generateWatcher (visitor: Visitor, contracts: any[], config: any) { outStream = outputDir ? fs.createWriteStream(path.join(outputDir, 'src/fill.ts')) : process.stdout; - exportFill(outStream); + exportFill(outStream, config.subgraphPath); outStream = outputDir ? fs.createWriteStream(path.join(outputDir, 'src/types.ts')) @@ -284,22 +284,22 @@ function generateWatcher (visitor: Visitor, contracts: any[], config: any) { resetStateOutStream = process.stdout; } - visitor.exportReset(resetOutStream, resetJQOutStream, resetStateOutStream); + visitor.exportReset(resetOutStream, resetJQOutStream, resetStateOutStream, config.subgraphPath); outStream = outputDir ? fs.createWriteStream(path.join(outputDir, 'src/cli/export-state.ts')) : process.stdout; - exportState(outStream); + exportState(outStream, config.subgraphPath); outStream = outputDir ? fs.createWriteStream(path.join(outputDir, 'src/cli/import-state.ts')) : process.stdout; - importState(outStream); + importState(outStream, config.subgraphPath); outStream = outputDir ? fs.createWriteStream(path.join(outputDir, 'src/cli/inspect-cid.ts')) : process.stdout; - exportInspectCID(outStream); + exportInspectCID(outStream, config.subgraphPath); } function getConfig (configFile: string): any { diff --git a/packages/codegen/src/import-state.ts b/packages/codegen/src/import-state.ts index 00019e295..8d6facbb8 100644 --- a/packages/codegen/src/import-state.ts +++ b/packages/codegen/src/import-state.ts @@ -13,9 +13,9 @@ const TEMPLATE_FILE = './templates/import-state-template.handlebars'; * Writes the import-state file generated from a template to a stream. * @param outStream A writable output stream to write the import-state file to. */ -export function importState (outStream: Writable): void { +export function importState (outStream: Writable, subgraphPath: string): void { const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString(); const template = Handlebars.compile(templateString); - const importState = template({}); + const importState = template({ subgraphPath }); outStream.write(importState); } diff --git a/packages/codegen/src/inspect-cid.ts b/packages/codegen/src/inspect-cid.ts index 63083cce7..82c5e3fb7 100644 --- a/packages/codegen/src/inspect-cid.ts +++ b/packages/codegen/src/inspect-cid.ts @@ -13,9 +13,9 @@ const TEMPLATE_FILE = './templates/inspect-cid-template.handlebars'; * Writes the inspect-cid file generated from a template to a stream. * @param outStream A writable output stream to write the inspect-cid file to. */ -export function exportInspectCID (outStream: Writable): void { +export function exportInspectCID (outStream: Writable, subgraphPath: string): void { const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString(); const template = Handlebars.compile(templateString); - const inspectCid = template({}); + const inspectCid = template({ subgraphPath }); outStream.write(inspectCid); } diff --git a/packages/codegen/src/job-runner.ts b/packages/codegen/src/job-runner.ts index fc4f0a30b..63b3a1f8e 100644 --- a/packages/codegen/src/job-runner.ts +++ b/packages/codegen/src/job-runner.ts @@ -13,9 +13,9 @@ const TEMPLATE_FILE = './templates/job-runner-template.handlebars'; * Writes the job-runner file generated from a template to a stream. * @param outStream A writable output stream to write the events file to. */ -export function exportJobRunner (outStream: Writable): void { +export function exportJobRunner (outStream: Writable, subgraphPath: string): void { const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString(); const template = Handlebars.compile(templateString); - const events = template({}); + const events = template({ subgraphPath }); outStream.write(events); } diff --git a/packages/codegen/src/reset.ts b/packages/codegen/src/reset.ts index 6799c99ed..7f173e22b 100644 --- a/packages/codegen/src/reset.ts +++ b/packages/codegen/src/reset.ts @@ -75,7 +75,7 @@ export class Reset { * @param resetJQOutStream A writable output stream to write the reset job-queue file to. * @param resetStateOutStream A writable output stream to write the reset state file to. */ - exportReset (resetOutStream: Writable, resetJQOutStream: Writable, resetStateOutStream: Writable): void { + exportReset (resetOutStream: Writable, resetJQOutStream: Writable, resetStateOutStream: Writable, subgraphPath: string): void { const resetTemplate = Handlebars.compile(this._resetTemplateString); const resetString = resetTemplate({}); resetOutStream.write(resetString); @@ -86,7 +86,8 @@ export class Reset { const resetStateTemplate = Handlebars.compile(this._resetStateTemplateString); const obj = { - queries: this._queries + queries: this._queries, + subgraphPath }; const resetState = resetStateTemplate(obj); resetStateOutStream.write(resetState); diff --git a/packages/codegen/src/server.ts b/packages/codegen/src/server.ts index a15327d4f..51ebbff5d 100644 --- a/packages/codegen/src/server.ts +++ b/packages/codegen/src/server.ts @@ -13,9 +13,9 @@ const TEMPLATE_FILE = './templates/server-template.handlebars'; * Writes the server file generated from a template to a stream. * @param outStream A writable output stream to write the server file to. */ -export function exportServer (outStream: Writable): void { +export function exportServer (outStream: Writable, subgraphPath: string): void { const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString(); const template = Handlebars.compile(templateString); - const server = template({}); + const server = template({ subgraphPath }); outStream.write(server); } diff --git a/packages/codegen/src/templates/checkpoint-template.handlebars b/packages/codegen/src/templates/checkpoint-template.handlebars index eda5011b0..e77f5eedc 100644 --- a/packages/codegen/src/templates/checkpoint-template.handlebars +++ b/packages/codegen/src/templates/checkpoint-template.handlebars @@ -64,7 +64,9 @@ const main = async (): Promise => { await indexer.init(); graphWatcher.setIndexer(indexer); + {{#if subgraphPath}} await graphWatcher.init(); + {{/if}} const blockHash = await indexer.processCLICheckpoint(argv.address, argv.blockHash); diff --git a/packages/codegen/src/templates/export-state-template.handlebars b/packages/codegen/src/templates/export-state-template.handlebars index cbd90e198..7d1da2e39 100644 --- a/packages/codegen/src/templates/export-state-template.handlebars +++ b/packages/codegen/src/templates/export-state-template.handlebars @@ -61,7 +61,9 @@ const main = async (): Promise => { await indexer.init(); graphWatcher.setIndexer(indexer); + {{#if subgraphPath}} await graphWatcher.init(); + {{/if}} const exportData: any = { snapshotBlock: {}, diff --git a/packages/codegen/src/templates/fill-template.handlebars b/packages/codegen/src/templates/fill-template.handlebars index 5cbd476c3..623a81cd3 100644 --- a/packages/codegen/src/templates/fill-template.handlebars +++ b/packages/codegen/src/templates/fill-template.handlebars @@ -76,7 +76,9 @@ export const main = async (): Promise => { await indexer.init(); graphWatcher.setIndexer(indexer); + {{#if subgraphPath}} await graphWatcher.init(); + {{/if}} // 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 diff --git a/packages/codegen/src/templates/import-state-template.handlebars b/packages/codegen/src/templates/import-state-template.handlebars index 1ba4d2dc6..6668fd1bb 100644 --- a/packages/codegen/src/templates/import-state-template.handlebars +++ b/packages/codegen/src/templates/import-state-template.handlebars @@ -69,7 +69,9 @@ export const main = async (): Promise => { await indexer.init(); graphWatcher.setIndexer(indexer); + {{#if subgraphPath}} await graphWatcher.init(); + {{/if}} const eventWatcher = new EventWatcher(config.upstream, ethClient, postgraphileClient, indexer, pubsub, jobQueue); diff --git a/packages/codegen/src/templates/indexer-template.handlebars b/packages/codegen/src/templates/indexer-template.handlebars index 12a9e649b..1b74dc846 100644 --- a/packages/codegen/src/templates/indexer-template.handlebars +++ b/packages/codegen/src/templates/indexer-template.handlebars @@ -15,7 +15,7 @@ import { EthClient } from '@vulcanize/ipld-eth-client'; import { StorageLayout } from '@vulcanize/solidity-mapper'; import { IPLDIndexer as BaseIndexer, - IndexerInterface, + IPLDIndexerInterface, ValueResult, UNKNOWN_EVENT_NAME, ServerConfig, @@ -26,7 +26,8 @@ import { updateStateForMappingType, BlockHeight, IPFSClient, - StateKind + StateKind, + IpldStatus as IpldStatusInterface } from '@vulcanize/util'; import { GraphWatcher } from '@vulcanize/graph-node'; @@ -94,7 +95,7 @@ export type ResultIPLDBlock = { data: string; }; -export class Indexer implements IndexerInterface { +export class Indexer implements IPLDIndexerInterface { _db: Database _ethClient: EthClient _ethProvider: BaseProvider @@ -563,11 +564,15 @@ export class Indexer implements IndexerInterface { } async watchContract (address: string, kind: string, checkpoint: boolean, startingBlock: number): Promise { - this._baseIndexer.updateIPLDStatusMap(address, {}); + await this.updateIPLDStatusMap(address, {}); return this._baseIndexer.watchContract(address, kind, checkpoint, startingBlock); } + async updateIPLDStatusMap (address: string, ipldStatus: IpldStatusInterface): Promise { + await this._baseIndexer.updateIPLDStatusMap(address, ipldStatus); + } + cacheContract (contract: Contract): void { return this._baseIndexer.cacheContract(contract); } diff --git a/packages/codegen/src/templates/inspect-cid-template.handlebars b/packages/codegen/src/templates/inspect-cid-template.handlebars index e1d6d9ec0..bad2b88ed 100644 --- a/packages/codegen/src/templates/inspect-cid-template.handlebars +++ b/packages/codegen/src/templates/inspect-cid-template.handlebars @@ -61,7 +61,9 @@ const main = async (): Promise => { await indexer.init(); graphWatcher.setIndexer(indexer); + {{#if subgraphPath}} await graphWatcher.init(); + {{/if}} const ipldBlock = await indexer.getIPLDBlockByCid(argv.cid); assert(ipldBlock, 'IPLDBlock for the provided CID doesn\'t exist.'); diff --git a/packages/codegen/src/templates/job-runner-template.handlebars b/packages/codegen/src/templates/job-runner-template.handlebars index b0385f15d..5c2d8153a 100644 --- a/packages/codegen/src/templates/job-runner-template.handlebars +++ b/packages/codegen/src/templates/job-runner-template.handlebars @@ -271,10 +271,12 @@ export const main = async (): Promise => { await indexer.init(); graphWatcher.setIndexer(indexer); + {{#if subgraphPath}} await graphWatcher.init(); // Watching all the contracts in the subgraph. await graphWatcher.addContracts(); + {{/if}} const jobRunner = new JobRunner(jobQueueConfig, indexer, jobQueue); await jobRunner.start(); diff --git a/packages/codegen/src/templates/reset-state-template.handlebars b/packages/codegen/src/templates/reset-state-template.handlebars index a8437612a..11b4fcf78 100644 --- a/packages/codegen/src/templates/reset-state-template.handlebars +++ b/packages/codegen/src/templates/reset-state-template.handlebars @@ -57,7 +57,9 @@ export const handler = async (argv: any): Promise => { await indexer.init(); graphWatcher.setIndexer(indexer); + {{#if subgraphPath}} await graphWatcher.init(); + {{/if}} const blockProgresses = await indexer.getBlocksAtHeight(argv.blockNumber, false); assert(blockProgresses.length, `No blocks at specified block number ${argv.blockNumber}`); diff --git a/packages/codegen/src/templates/server-template.handlebars b/packages/codegen/src/templates/server-template.handlebars index 221a7e512..6d48976f8 100644 --- a/packages/codegen/src/templates/server-template.handlebars +++ b/packages/codegen/src/templates/server-template.handlebars @@ -64,7 +64,9 @@ export const main = async (): Promise => { await indexer.init(); graphWatcher.setIndexer(indexer); + {{#if subgraphPath}} await graphWatcher.init(); + {{/if}} const eventWatcher = new EventWatcher(config.upstream, ethClient, postgraphileClient, indexer, pubsub, jobQueue); diff --git a/packages/codegen/src/templates/watch-contract-template.handlebars b/packages/codegen/src/templates/watch-contract-template.handlebars index 372cc1fa0..035c16453 100644 --- a/packages/codegen/src/templates/watch-contract-template.handlebars +++ b/packages/codegen/src/templates/watch-contract-template.handlebars @@ -77,7 +77,9 @@ const main = async (): Promise => { await indexer.init(); graphWatcher.setIndexer(indexer); + {{#if subgraphPath}} await graphWatcher.init(); + {{/if}} await indexer.watchContract(argv.address, argv.kind, argv.checkpoint, argv.startingBlock); diff --git a/packages/codegen/src/visitor.ts b/packages/codegen/src/visitor.ts index 99f9b97a5..8e58750b8 100644 --- a/packages/codegen/src/visitor.ts +++ b/packages/codegen/src/visitor.ts @@ -218,8 +218,8 @@ export class Visitor { * @param resetJQOutStream A writable output stream to write the reset job-queue file to. * @param resetStateOutStream A writable output stream to write the reset state file to. */ - exportReset (resetOutStream: Writable, resetJQOutStream: Writable, resetStateOutStream: Writable): void { - this._reset.exportReset(resetOutStream, resetJQOutStream, resetStateOutStream); + exportReset (resetOutStream: Writable, resetJQOutStream: Writable, resetStateOutStream: Writable, subgraphPath: string): void { + this._reset.exportReset(resetOutStream, resetJQOutStream, resetStateOutStream, subgraphPath); } /** diff --git a/packages/codegen/src/watch-contract.ts b/packages/codegen/src/watch-contract.ts index b2ff62481..207b748cd 100644 --- a/packages/codegen/src/watch-contract.ts +++ b/packages/codegen/src/watch-contract.ts @@ -13,9 +13,9 @@ const TEMPLATE_FILE = './templates/watch-contract-template.handlebars'; * Writes the watch-contract file generated from a template to a stream. * @param outStream A writable output stream to write the watch-contract file to. */ -export function exportWatchContract (outStream: Writable): void { +export function exportWatchContract (outStream: Writable, subgraphPath: string): void { const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString(); const template = Handlebars.compile(templateString); - const events = template({}); + const events = template({ subgraphPath }); outStream.write(events); } diff --git a/packages/eden-watcher/src/indexer.ts b/packages/eden-watcher/src/indexer.ts index 651c0d175..8650da9e6 100644 --- a/packages/eden-watcher/src/indexer.ts +++ b/packages/eden-watcher/src/indexer.ts @@ -15,7 +15,6 @@ import { EthClient } from '@vulcanize/ipld-eth-client'; import { StorageLayout } from '@vulcanize/solidity-mapper'; import { IPLDIndexer as BaseIndexer, - IndexerInterface, UNKNOWN_EVENT_NAME, ServerConfig, JobQueue, @@ -23,7 +22,9 @@ import { QueryOptions, BlockHeight, IPFSClient, - StateKind + StateKind, + IPLDIndexerInterface, + IpldStatus as IpldStatusInterface } from '@vulcanize/util'; import { GraphWatcher } from '@vulcanize/graph-node'; @@ -125,7 +126,7 @@ export type ResultIPLDBlock = { data: string; }; -export class Indexer implements IndexerInterface { +export class Indexer implements IPLDIndexerInterface { _db: Database _ethClient: EthClient _ethProvider: BaseProvider @@ -899,11 +900,15 @@ export class Indexer implements IndexerInterface { } async watchContract (address: string, kind: string, checkpoint: boolean, startingBlock: number): Promise { - this._baseIndexer.updateIPLDStatusMap(address, {}); + await this.updateIPLDStatusMap(address, {}); return this._baseIndexer.watchContract(address, kind, checkpoint, startingBlock); } + async updateIPLDStatusMap (address: string, ipldStatus: IpldStatusInterface): Promise { + await this._baseIndexer.updateIPLDStatusMap(address, ipldStatus); + } + cacheContract (contract: Contract): void { return this._baseIndexer.cacheContract(contract); } diff --git a/packages/erc20-watcher/test/tasks/token-approve.ts b/packages/erc20-watcher/test/tasks/token-approve.ts index 2091b50f4..70096fd28 100644 --- a/packages/erc20-watcher/test/tasks/token-approve.ts +++ b/packages/erc20-watcher/test/tasks/token-approve.ts @@ -25,7 +25,7 @@ task('token-approve', 'Move tokens to recipient') const TransferEvent = receipt.events.find(el => el.event === 'Approval'); if (TransferEvent && TransferEvent.args) { - console.log('Approval Event'); + console.log('Approval Event at block:', receipt.blockNumber, receipt.blockHash); console.log('owner:', TransferEvent.args.owner.toString()); console.log('spender:', TransferEvent.args.spender.toString()); console.log('value:', TransferEvent.args.value.toString()); diff --git a/packages/erc20-watcher/test/tasks/token-deploy.ts b/packages/erc20-watcher/test/tasks/token-deploy.ts index 94729e8b3..28a85adb4 100644 --- a/packages/erc20-watcher/test/tasks/token-deploy.ts +++ b/packages/erc20-watcher/test/tasks/token-deploy.ts @@ -15,5 +15,7 @@ task('token-deploy', 'Deploys GLD token') const Token = await hre.ethers.getContractFactory('GLDToken'); const token = await Token.deploy(hre.ethers.BigNumber.from(initialSupply)); + const receipt = await token.deployTransaction.wait(); console.log('GLD Token deployed to:', token.address); + console.log('Deployed at block:', receipt.blockNumber, receipt.blockHash); }); diff --git a/packages/erc20-watcher/test/tasks/token-transfer-from.ts b/packages/erc20-watcher/test/tasks/token-transfer-from.ts index 09712e246..005b1c3bd 100644 --- a/packages/erc20-watcher/test/tasks/token-transfer-from.ts +++ b/packages/erc20-watcher/test/tasks/token-transfer-from.ts @@ -28,7 +28,7 @@ task('token-transfer-from', 'Send tokens as spender') const TransferEvent = receipt.events.find(el => el.event === 'Transfer'); if (TransferEvent && TransferEvent.args) { - console.log('Transfer Event'); + console.log('Transfer Event at block:', receipt.blockNumber, receipt.blockHash); console.log('from:', TransferEvent.args.from.toString()); console.log('to:', TransferEvent.args.to.toString()); console.log('value:', TransferEvent.args.value.toString()); diff --git a/packages/erc20-watcher/test/tasks/token-transfer.ts b/packages/erc20-watcher/test/tasks/token-transfer.ts index 23416a099..fb281733e 100644 --- a/packages/erc20-watcher/test/tasks/token-transfer.ts +++ b/packages/erc20-watcher/test/tasks/token-transfer.ts @@ -24,7 +24,7 @@ task('token-transfer', 'Move tokens to recipient') const TransferEvent = receipt.events.find(el => el.event === 'Transfer'); if (TransferEvent && TransferEvent.args) { - console.log('Transfer Event'); + console.log('Transfer Event at block:', receipt.blockNumber, receipt.blockHash); console.log('from:', TransferEvent.args.from.toString()); console.log('to:', TransferEvent.args.to.toString()); console.log('value:', TransferEvent.args.value.toString()); diff --git a/packages/graph-test-watcher/src/indexer.ts b/packages/graph-test-watcher/src/indexer.ts index b682f1226..3afffbb00 100644 --- a/packages/graph-test-watcher/src/indexer.ts +++ b/packages/graph-test-watcher/src/indexer.ts @@ -15,7 +15,6 @@ import { EthClient } from '@vulcanize/ipld-eth-client'; import { StorageLayout } from '@vulcanize/solidity-mapper'; import { IPLDIndexer as BaseIndexer, - IndexerInterface, ValueResult, UNKNOWN_EVENT_NAME, ServerConfig, @@ -25,7 +24,9 @@ import { QueryOptions, BlockHeight, IPFSClient, - StateKind + StateKind, + IPLDIndexerInterface, + IpldStatus as IpldStatusInterface } from '@vulcanize/util'; import { GraphWatcher } from '@vulcanize/graph-node'; @@ -92,7 +93,7 @@ export type ResultIPLDBlock = { data: string; }; -export class Indexer implements IndexerInterface { +export class Indexer implements IPLDIndexerInterface { _db: Database _ethClient: EthClient _ethProvider: BaseProvider @@ -592,11 +593,15 @@ export class Indexer implements IndexerInterface { } async watchContract (address: string, kind: string, checkpoint: boolean, startingBlock: number): Promise { - this._baseIndexer.updateIPLDStatusMap(address, {}); + await this.updateIPLDStatusMap(address, {}); return this._baseIndexer.watchContract(address, kind, checkpoint, startingBlock); } + async updateIPLDStatusMap (address: string, ipldStatus: IpldStatusInterface): Promise { + await this._baseIndexer.updateIPLDStatusMap(address, ipldStatus); + } + cacheContract (contract: Contract): void { return this._baseIndexer.cacheContract(contract); } diff --git a/packages/util/src/job-runner.ts b/packages/util/src/job-runner.ts index 4f3b7d7ee..daf6aecaa 100644 --- a/packages/util/src/job-runner.ts +++ b/packages/util/src/job-runner.ts @@ -18,7 +18,7 @@ import { QUEUE_EVENT_PROCESSING } from './constants'; import { JobQueue } from './job-queue'; -import { EventInterface, IndexerInterface, SyncStatusInterface } from './types'; +import { EventInterface, IndexerInterface, IPLDIndexerInterface, SyncStatusInterface } from './types'; import { wait } from './misc'; import { createPruningJob } from './common'; import { OrderDirection } from './database'; @@ -28,7 +28,7 @@ const DEFAULT_EVENTS_IN_BATCH = 50; const log = debug('vulcanize:job-runner'); export class JobRunner { - _indexer: IndexerInterface + _indexer: IndexerInterface | IPLDIndexerInterface _jobQueue: JobQueue _jobQueueConfig: JobQueueConfig _blockProcessStartTime?: Date @@ -331,5 +331,10 @@ export class JobRunner { assert(this._indexer.cacheContract); this._indexer.cacheContract(contract); + + const ipldIndexer = this._indexer as IPLDIndexerInterface; + if (ipldIndexer.updateIPLDStatusMap) { + ipldIndexer.updateIPLDStatusMap(contract.address, {}); + } } } diff --git a/packages/util/src/types.ts b/packages/util/src/types.ts index d31f6a067..ea82ecaa7 100644 --- a/packages/util/src/types.ts +++ b/packages/util/src/types.ts @@ -5,6 +5,7 @@ import { Connection, DeepPartial, FindConditions, FindManyOptions, QueryRunner } from 'typeorm'; import { Where, QueryOptions } from './database'; +import { IpldStatus } from './ipld-indexer'; export enum StateKind { Diff = 'diff', @@ -104,6 +105,10 @@ export interface IndexerInterface { processBlock?: (blockHash: string, blockNumber: number) => Promise } +export interface IPLDIndexerInterface extends IndexerInterface { + updateIPLDStatusMap (address: string, ipldStatus: IpldStatus): Promise +} + export interface EventWatcherInterface { getBlockProgressEventIterator (): AsyncIterator initBlockProcessingOnCompleteHandler (): Promise