Include block number in GQL event. (#121)

This commit is contained in:
Ashwin Phatak 2021-07-06 11:04:08 +05:30 committed by GitHub
parent 8d2a4c6b14
commit 0b6a33561b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 6 deletions

View File

@ -31,4 +31,4 @@
deleteOnStart = false
[contracts]
factory = "0xF3eeD405056b4BB1ce100761325f82F2b6Da2D82"
factory = "0xECfCae19742EE4644b209d75cF15ee6D02A726Ff"

View File

@ -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);
}
}
}

View File

@ -90,7 +90,7 @@ export class Indexer {
}
/* eslint-enable */
async publishEventToSubscribers (blockHash: string, contract: string, logIndex: number): Promise<void> {
async publishEventToSubscribers (blockHash: string, blockNumber: number, contract: string, logIndex: number): Promise<void> {
// 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<void> {
async processEvent (blockHash: string, blockNumber: number, contract: string, receipt: any, logIndex: number): Promise<void> {
// 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<void> {

View File

@ -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!