mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-09-12 18:47:30 +00:00
Rename variables and fix comments (#243)
* Rename entity to entityType * Rename variables and fix comments
This commit is contained in:
@@ -30,7 +30,7 @@ export interface PrefetchedBlock {
|
||||
* @param jobQueue
|
||||
* @param blockNumber
|
||||
*/
|
||||
export const processBlockByNumberWithCache = async (
|
||||
export const processBlockByNumber = async (
|
||||
jobQueue: JobQueue,
|
||||
blockNumber: number
|
||||
): Promise<void> => {
|
||||
@@ -247,11 +247,9 @@ export const processBatchEvents = async (indexer: IndexerInterface, block: Block
|
||||
|
||||
console.time('time:common#processBatchEvents-processing_events_batch');
|
||||
|
||||
// Process events in loop
|
||||
for (let event of events) {
|
||||
// Process events in loop
|
||||
|
||||
const eventIndex = event.index;
|
||||
// log(`Processing event ${event.id} index ${eventIndex}`);
|
||||
|
||||
// Check that events are processed in order.
|
||||
if (eventIndex <= block.lastProcessedEventIndex) {
|
||||
@@ -269,14 +267,7 @@ export const processBatchEvents = async (indexer: IndexerInterface, block: Block
|
||||
}
|
||||
}
|
||||
|
||||
let watchedContract;
|
||||
|
||||
if (!indexer.isWatchedContract) {
|
||||
// uni-info-watcher indexer doesn't have watched contracts implementation.
|
||||
watchedContract = true;
|
||||
} else {
|
||||
watchedContract = indexer.isWatchedContract(event.contract);
|
||||
}
|
||||
const watchedContract = indexer.isWatchedContract(event.contract);
|
||||
|
||||
if (watchedContract) {
|
||||
// We might not have parsed this event yet. This can happen if the contract was added
|
||||
|
||||
@@ -11,10 +11,9 @@ import { EthClient } from '@cerc-io/ipld-eth-client';
|
||||
import { JobQueue } from './job-queue';
|
||||
import { BlockProgressInterface, EventInterface, IndexerInterface } from './types';
|
||||
import { MAX_REORG_DEPTH, JOB_KIND_PRUNE, JOB_KIND_INDEX, UNKNOWN_EVENT_NAME, JOB_KIND_EVENTS, QUEUE_BLOCK_PROCESSING, QUEUE_EVENT_PROCESSING } from './constants';
|
||||
import { createPruningJob, processBlockByNumberWithCache } from './common';
|
||||
import { createPruningJob, processBlockByNumber } from './common';
|
||||
import { UpstreamConfig } from './config';
|
||||
import { OrderDirection } from './database';
|
||||
import { getResultEvent } from './misc';
|
||||
|
||||
const EVENT = 'event';
|
||||
|
||||
@@ -65,8 +64,7 @@ export class EventWatcher {
|
||||
startBlockNumber = syncStatus.chainHeadBlockNumber + 1;
|
||||
}
|
||||
|
||||
// Wait for block processing as blockProgress event might process the same block.
|
||||
await processBlockByNumberWithCache(this._jobQueue, startBlockNumber);
|
||||
await processBlockByNumber(this._jobQueue, startBlockNumber);
|
||||
|
||||
// Creating an AsyncIterable from AsyncIterator to iterate over the values.
|
||||
// https://www.codementor.io/@tiagolopesferreira/asynchronous-iterators-in-javascript-jl1yg8la1#for-wait-of
|
||||
@@ -81,7 +79,7 @@ export class EventWatcher {
|
||||
const { onBlockProgressEvent: { blockNumber, isComplete } } = data;
|
||||
|
||||
if (isComplete) {
|
||||
await processBlockByNumberWithCache(this._jobQueue, blockNumber + 1);
|
||||
await processBlockByNumber(this._jobQueue, blockNumber + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -181,7 +179,7 @@ export class EventWatcher {
|
||||
|
||||
async publishEventToSubscribers (dbEvent: EventInterface, timeElapsedInSeconds: number): Promise<void> {
|
||||
if (dbEvent && dbEvent.eventName !== UNKNOWN_EVENT_NAME) {
|
||||
const resultEvent = getResultEvent(dbEvent);
|
||||
const resultEvent = this._indexer.getResultEvent(dbEvent);
|
||||
|
||||
log(`pushing event to GQL subscribers (${timeElapsedInSeconds}s elapsed): ${resultEvent.event.__typename}`);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import debug from 'debug';
|
||||
import { JobQueue } from './job-queue';
|
||||
import { EventWatcherInterface, IndexerInterface } from './types';
|
||||
import { wait } from './misc';
|
||||
import { processBlockByNumberWithCache } from './common';
|
||||
import { processBlockByNumber } from './common';
|
||||
import { DEFAULT_PREFETCH_BATCH_SIZE } from './constants';
|
||||
|
||||
const log = debug('vulcanize:fill');
|
||||
@@ -58,7 +58,7 @@ export const fillBlocks = async (
|
||||
|
||||
const numberOfBlocks = endBlock - startBlock + 1;
|
||||
|
||||
processBlockByNumberWithCache(jobQueue, startBlock);
|
||||
processBlockByNumber(jobQueue, startBlock);
|
||||
|
||||
// Creating an AsyncIterable from AsyncIterator to iterate over the values.
|
||||
// https://www.codementor.io/@tiagolopesferreira/asynchronous-iterators-in-javascript-jl1yg8la1#for-wait-of
|
||||
@@ -79,7 +79,7 @@ export const fillBlocks = async (
|
||||
const completePercentage = Math.round(blocksProcessed / numberOfBlocks * 100);
|
||||
log(`Processed ${blocksProcessed} of ${numberOfBlocks} blocks (${completePercentage}%)`);
|
||||
|
||||
await processBlockByNumberWithCache(jobQueue, blockNumber + 1);
|
||||
await processBlockByNumber(jobQueue, blockNumber + 1);
|
||||
|
||||
if (blockNumber + 1 >= endBlock) {
|
||||
// Break the async loop when blockProgress event is for the endBlock and processing is complete.
|
||||
|
||||
@@ -121,6 +121,7 @@ export interface IndexerInterface {
|
||||
updateStateStatusMap (address: string, stateStatus: StateStatus): void
|
||||
getStateData (state: StateInterface): any
|
||||
resetWatcherToBlock (blockNumber: number): Promise<void>
|
||||
getResultEvent (event: EventInterface): any
|
||||
}
|
||||
|
||||
export interface EventWatcherInterface {
|
||||
|
||||
Reference in New Issue
Block a user