mirror of
https://github.com/cerc-io/watcher-ts
synced 2024-11-19 20:36:19 +00:00
Include block number in GQL event. (#121)
This commit is contained in:
parent
8d2a4c6b14
commit
0b6a33561b
@ -31,4 +31,4 @@
|
||||
deleteOnStart = false
|
||||
|
||||
[contracts]
|
||||
factory = "0xF3eeD405056b4BB1ce100761325f82F2b6Da2D82"
|
||||
factory = "0xECfCae19742EE4644b209d75cF15ee6D02A726Ff"
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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> {
|
||||
|
@ -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!
|
||||
|
Loading…
Reference in New Issue
Block a user