Include txHash in event sent to GQL subscribers. (#129)

This commit is contained in:
Ashwin Phatak 2021-07-09 17:01:36 +05:30 committed by GitHub
parent 61f211f2d5
commit 69c68b365f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 7 deletions

View File

@ -55,6 +55,7 @@ subscription SubscriptionReceipt {
topic3S
contract
ethTransactionCidByTxId {
txHash
ethHeaderCidByHeaderId {
blockHash
blockNumber

View File

@ -37,12 +37,12 @@ export class EventWatcher {
const contractAddress = logContracts[logIndex];
const uniContract = await this._indexer.isUniswapContract(contractAddress);
if (uniContract) {
const { ethTransactionCidByTxId: { ethHeaderCidByHeaderId: { blockHash, blockNumber } } } = receipt;
const { ethTransactionCidByTxId: { txHash, ethHeaderCidByHeaderId: { blockHash, blockNumber } } } = receipt;
const events = await this._indexer.getEvents(blockHash, contractAddress, null);
const event = events[logIndex];
// Trigger other indexer methods based on event topic.
await this._indexer.processEvent(blockHash, blockNumber, uniContract, receipt, event);
await this._indexer.processEvent(blockHash, blockNumber, uniContract, txHash, receipt, event);
}
}
}

View File

@ -104,7 +104,7 @@ export class Indexer {
}
}
async publishEventToSubscribers (blockHash: string, blockNumber: number, contract: string, event: EventResult): Promise<void> {
async publishEventToSubscribers (blockHash: string, blockNumber: number, contract: string, txHash: string, event: EventResult): Promise<void> {
log(`pushing event to GQL subscribers: ${event.event.__typename}`);
// Publishing the event here will result in pushing the payload to GQL subscribers for `onEvent`.
@ -113,6 +113,7 @@ export class Indexer {
blockHash,
blockNumber,
contract,
txHash,
event
}
});
@ -122,12 +123,12 @@ export class Indexer {
return this._db.getContract(ethers.utils.getAddress(address));
}
async processEvent (blockHash: string, blockNumber: number, contract: Contract, receipt: any, event: EventResult): Promise<void> {
async processEvent (blockHash: string, blockNumber: number, contract: Contract, txHash: string, receipt: any, event: EventResult): Promise<void> {
// Trigger indexing of data based on the event.
await this.triggerIndexingOnEvent(blockNumber, event);
// Also trigger downstream event watcher subscriptions.
await this.publishEventToSubscribers(blockHash, blockNumber, contract.address, event);
await this.publishEventToSubscribers(blockHash, blockNumber, contract.address, txHash, event);
}
async _fetchAndSaveEvents ({ blockHash, contract, uniContract }: { blockHash: string, contract: string, uniContract: Contract }): Promise<void> {

View File

@ -113,7 +113,7 @@ type CollectEvent {
}
# All events emitted by the NonfungiblePositionManager contract.
union NonFungiblePositionManagerEvent = IncreaseLiquidityEvent | DecreaseLiquidityEvent
union NonFungiblePositionManagerEvent = IncreaseLiquidityEvent | DecreaseLiquidityEvent | CollectEvent
# Pool Events
@ -160,7 +160,7 @@ union PoolEvent = InitializeEvent | MintEvent | BurnEvent | SwapEvent
# All events emitted by the watcher.
union Event = TransferEvent | PoolCreatedEvent | IncreaseLiquidityEvent | DecreaseLiquidityEvent | InitializeEvent | MintEvent | BurnEvent | SwapEvent
union Event = TransferEvent | PoolCreatedEvent | IncreaseLiquidityEvent | DecreaseLiquidityEvent | CollectEvent | InitializeEvent | MintEvent | BurnEvent | SwapEvent
# Result type, with proof, for event return values.
type ResultEvent {
@ -175,6 +175,7 @@ type WatchedEvent {
blockHash: String!
blockNumber: Int!
contract: String!
txHash: String!
event: ResultEvent!
}