From 0b6a33561b714b89348d168f2420e2f75ec233ed Mon Sep 17 00:00:00 2001 From: Ashwin Phatak Date: Tue, 6 Jul 2021 11:04:08 +0530 Subject: [PATCH] Include block number in GQL event. (#121) --- packages/uni-watcher/environments/local.toml | 2 +- packages/uni-watcher/src/events.ts | 4 ++-- packages/uni-watcher/src/indexer.ts | 7 ++++--- packages/uni-watcher/src/schema.ts | 1 + 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/uni-watcher/environments/local.toml b/packages/uni-watcher/environments/local.toml index 35f6ad18..3649dc84 100644 --- a/packages/uni-watcher/environments/local.toml +++ b/packages/uni-watcher/environments/local.toml @@ -31,4 +31,4 @@ deleteOnStart = false [contracts] - factory = "0xF3eeD405056b4BB1ce100761325f82F2b6Da2D82" + factory = "0xECfCae19742EE4644b209d75cF15ee6D02A726Ff" diff --git a/packages/uni-watcher/src/events.ts b/packages/uni-watcher/src/events.ts index e492d285..05e840c4 100644 --- a/packages/uni-watcher/src/events.ts +++ b/packages/uni-watcher/src/events.ts @@ -39,11 +39,11 @@ export class EventWatcher { if (isWatchedContract) { // TODO: Move processing to background task runner. - const { ethTransactionCidByTxId: { ethHeaderCidByHeaderId: { blockHash } } } = receipt; + const { ethTransactionCidByTxId: { ethHeaderCidByHeaderId: { blockHash, blockNumber } } } = receipt; await this._indexer.getEvents(blockHash, contractAddress, null); // Trigger other indexer methods based on event topic. - await this._indexer.processEvent(blockHash, contractAddress, receipt, logIndex); + await this._indexer.processEvent(blockHash, blockNumber, contractAddress, receipt, logIndex); } } } diff --git a/packages/uni-watcher/src/indexer.ts b/packages/uni-watcher/src/indexer.ts index 1140da66..b833e9df 100644 --- a/packages/uni-watcher/src/indexer.ts +++ b/packages/uni-watcher/src/indexer.ts @@ -90,7 +90,7 @@ export class Indexer { } /* eslint-enable */ - async publishEventToSubscribers (blockHash: string, contract: string, logIndex: number): Promise { + async publishEventToSubscribers (blockHash: string, blockNumber: number, contract: string, logIndex: number): Promise { // TODO: Optimize this fetching of events. const events = await this.getEvents(blockHash, contract, null); @@ -105,6 +105,7 @@ export class Indexer { await this._pubsub.publish('event', { onEvent: { blockHash, + blockNumber, contract, event } @@ -116,12 +117,12 @@ export class Indexer { return address != null; } - async processEvent (blockHash: string, contract: string, receipt: any, logIndex: number): Promise { + async processEvent (blockHash: string, blockNumber: number, contract: string, receipt: any, logIndex: number): Promise { // Trigger indexing of data based on the event. await this.triggerIndexingOnEvent(blockHash, contract, receipt, logIndex); // Also trigger downstream event watcher subscriptions. - await this.publishEventToSubscribers(blockHash, contract, logIndex); + await this.publishEventToSubscribers(blockHash, blockNumber, contract, logIndex); } async _fetchAndSaveEvents ({ blockHash, contract }: { blockHash: string, contract: string }): Promise { diff --git a/packages/uni-watcher/src/schema.ts b/packages/uni-watcher/src/schema.ts index 3a09f094..45b1597b 100644 --- a/packages/uni-watcher/src/schema.ts +++ b/packages/uni-watcher/src/schema.ts @@ -173,6 +173,7 @@ type ResultEvent { # Watched event, include additional context over and above the event data. type WatchedEvent { blockHash: String! + blockNumber: Int! contract: String! event: ResultEvent!