mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-07-27 02:32:07 +00:00
Refactor watchers according to changes in util package
This commit is contained in:
parent
768a4d0818
commit
f4d16afa6c
@ -6,7 +6,7 @@ import assert from 'assert';
|
|||||||
import { Connection, ConnectionOptions, DeepPartial, FindConditions, QueryRunner, FindManyOptions } from 'typeorm';
|
import { Connection, ConnectionOptions, DeepPartial, FindConditions, QueryRunner, FindManyOptions } from 'typeorm';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
import { IPLDDatabase as BaseDatabase, IPLDDatabaseInterface } from '@vulcanize/util';
|
import { IPLDDatabase as BaseDatabase, IPLDDatabaseInterface, QueryOptions, Where } from '@vulcanize/util';
|
||||||
|
|
||||||
import { Contract } from './entity/Contract';
|
import { Contract } from './entity/Contract';
|
||||||
import { Event } from './entity/Event';
|
import { Event } from './entity/Event';
|
||||||
@ -117,13 +117,13 @@ export class Database implements IPLDDatabaseInterface {
|
|||||||
return this._baseDatabase.saveEventEntity(repo, entity);
|
return this._baseDatabase.saveEventEntity(repo, entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getBlockEvents (blockHash: string, options: FindManyOptions<Event>): Promise<Event[]> {
|
async getBlockEvents (blockHash: string, where: Where, queryOptions: QueryOptions): Promise<Event[]> {
|
||||||
const repo = this._conn.getRepository(Event);
|
const repo = this._conn.getRepository(Event);
|
||||||
|
|
||||||
return this._baseDatabase.getBlockEvents(repo, blockHash, options);
|
return this._baseDatabase.getBlockEvents(repo, blockHash, where, queryOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
async saveEvents (queryRunner: QueryRunner, block: DeepPartial<BlockProgress>, events: DeepPartial<Event>[]): Promise<void> {
|
async saveEvents (queryRunner: QueryRunner, block: DeepPartial<BlockProgress>, events: DeepPartial<Event>[]): Promise<BlockProgress> {
|
||||||
const blockRepo = queryRunner.manager.getRepository(BlockProgress);
|
const blockRepo = queryRunner.manager.getRepository(BlockProgress);
|
||||||
const eventRepo = queryRunner.manager.getRepository(Event);
|
const eventRepo = queryRunner.manager.getRepository(Event);
|
||||||
|
|
||||||
@ -183,6 +183,12 @@ export class Database implements IPLDDatabaseInterface {
|
|||||||
return this._baseDatabase.getBlockProgress(repo, blockHash);
|
return this._baseDatabase.getBlockProgress(repo, blockHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getBlockProgressEntities (where: FindConditions<BlockProgress>, options: FindManyOptions<BlockProgress>): Promise<BlockProgress[]> {
|
||||||
|
const repo = this._conn.getRepository(BlockProgress);
|
||||||
|
|
||||||
|
return this._baseDatabase.getBlockProgressEntities(repo, where, options);
|
||||||
|
}
|
||||||
|
|
||||||
async updateBlockProgress (queryRunner: QueryRunner, block: BlockProgress, lastProcessedEventIndex: number): Promise<BlockProgress> {
|
async updateBlockProgress (queryRunner: QueryRunner, block: BlockProgress, lastProcessedEventIndex: number): Promise<BlockProgress> {
|
||||||
const repo = queryRunner.manager.getRepository(BlockProgress);
|
const repo = queryRunner.manager.getRepository(BlockProgress);
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import debug from 'debug';
|
import debug from 'debug';
|
||||||
import { DeepPartial } from 'typeorm';
|
import { DeepPartial, FindConditions, FindManyOptions } from 'typeorm';
|
||||||
import JSONbig from 'json-bigint';
|
import JSONbig from 'json-bigint';
|
||||||
import { ethers } from 'ethers';
|
import { ethers } from 'ethers';
|
||||||
|
|
||||||
@ -14,12 +14,13 @@ import * as codec from '@ipld/dag-cbor';
|
|||||||
import { EthClient } from '@vulcanize/ipld-eth-client';
|
import { EthClient } from '@vulcanize/ipld-eth-client';
|
||||||
import { StorageLayout } from '@vulcanize/solidity-mapper';
|
import { StorageLayout } from '@vulcanize/solidity-mapper';
|
||||||
import {
|
import {
|
||||||
EventInterface,
|
|
||||||
IPLDIndexer as BaseIndexer,
|
IPLDIndexer as BaseIndexer,
|
||||||
IndexerInterface,
|
IndexerInterface,
|
||||||
UNKNOWN_EVENT_NAME,
|
UNKNOWN_EVENT_NAME,
|
||||||
ServerConfig,
|
ServerConfig,
|
||||||
JobQueue,
|
JobQueue,
|
||||||
|
Where,
|
||||||
|
QueryOptions,
|
||||||
BlockHeight,
|
BlockHeight,
|
||||||
IPFSClient
|
IPFSClient
|
||||||
} from '@vulcanize/util';
|
} from '@vulcanize/util';
|
||||||
@ -880,16 +881,20 @@ export class Indexer implements IndexerInterface {
|
|||||||
return this._baseIndexer.getBlockProgress(blockHash);
|
return this._baseIndexer.getBlockProgress(blockHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getBlockProgressEntities (where: FindConditions<BlockProgress>, options: FindManyOptions<BlockProgress>): Promise<BlockProgress[]> {
|
||||||
|
return this._baseIndexer.getBlockProgressEntities(where, options);
|
||||||
|
}
|
||||||
|
|
||||||
async getBlocksAtHeight (height: number, isPruned: boolean): Promise<BlockProgress[]> {
|
async getBlocksAtHeight (height: number, isPruned: boolean): Promise<BlockProgress[]> {
|
||||||
return this._baseIndexer.getBlocksAtHeight(height, isPruned);
|
return this._baseIndexer.getBlocksAtHeight(height, isPruned);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getOrFetchBlockEvents (block: DeepPartial<BlockProgress>): Promise<Array<EventInterface>> {
|
async fetchBlockEvents (block: DeepPartial<BlockProgress>): Promise<BlockProgress> {
|
||||||
return this._baseIndexer.getOrFetchBlockEvents(block, this._fetchAndSaveEvents.bind(this));
|
return this._baseIndexer.fetchBlockEvents(block, this._fetchAndSaveEvents.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
async getBlockEvents (blockHash: string): Promise<Array<Event>> {
|
async getBlockEvents (blockHash: string, where: Where, queryOptions: QueryOptions): Promise<Array<Event>> {
|
||||||
return this._baseIndexer.getBlockEvents(blockHash);
|
return this._baseIndexer.getBlockEvents(blockHash, where, queryOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
async removeUnknownEvents (block: BlockProgress): Promise<void> {
|
async removeUnknownEvents (block: BlockProgress): Promise<void> {
|
||||||
@ -1248,7 +1253,7 @@ export class Indexer implements IndexerInterface {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async _fetchAndSaveEvents ({ cid: blockCid, blockHash }: DeepPartial<BlockProgress>): Promise<void> {
|
async _fetchAndSaveEvents ({ cid: blockCid, blockHash }: DeepPartial<BlockProgress>): Promise<BlockProgress> {
|
||||||
assert(blockHash);
|
assert(blockHash);
|
||||||
|
|
||||||
const logsPromise = this._ethClient.getLogs({ blockHash });
|
const logsPromise = this._ethClient.getLogs({ blockHash });
|
||||||
@ -1344,8 +1349,10 @@ export class Indexer implements IndexerInterface {
|
|||||||
parentHash: block.parent.hash
|
parentHash: block.parent.hash
|
||||||
};
|
};
|
||||||
|
|
||||||
await this._db.saveEvents(dbTx, block, dbEvents);
|
const blockProgress = await this._db.saveEvents(dbTx, block, dbEvents);
|
||||||
await dbTx.commitTransaction();
|
await dbTx.commitTransaction();
|
||||||
|
|
||||||
|
return blockProgress;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await dbTx.rollbackTransaction();
|
await dbTx.rollbackTransaction();
|
||||||
throw error;
|
throw error;
|
||||||
|
@ -6,7 +6,7 @@ import assert from 'assert';
|
|||||||
import { Connection, ConnectionOptions, DeepPartial, FindConditions, QueryRunner, FindManyOptions } from 'typeorm';
|
import { Connection, ConnectionOptions, DeepPartial, FindConditions, QueryRunner, FindManyOptions } from 'typeorm';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
import { IPLDDatabase as BaseDatabase, IPLDDatabaseInterface } from '@vulcanize/util';
|
import { IPLDDatabase as BaseDatabase, IPLDDatabaseInterface, QueryOptions, Where } from '@vulcanize/util';
|
||||||
|
|
||||||
import { Contract } from './entity/Contract';
|
import { Contract } from './entity/Contract';
|
||||||
import { Event } from './entity/Event';
|
import { Event } from './entity/Event';
|
||||||
@ -151,13 +151,13 @@ export class Database implements IPLDDatabaseInterface {
|
|||||||
return this._baseDatabase.saveEventEntity(repo, entity);
|
return this._baseDatabase.saveEventEntity(repo, entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getBlockEvents (blockHash: string, options: FindManyOptions<Event>): Promise<Event[]> {
|
async getBlockEvents (blockHash: string, where: Where, queryOptions: QueryOptions): Promise<Event[]> {
|
||||||
const repo = this._conn.getRepository(Event);
|
const repo = this._conn.getRepository(Event);
|
||||||
|
|
||||||
return this._baseDatabase.getBlockEvents(repo, blockHash, options);
|
return this._baseDatabase.getBlockEvents(repo, blockHash, where, queryOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
async saveEvents (queryRunner: QueryRunner, block: DeepPartial<BlockProgress>, events: DeepPartial<Event>[]): Promise<void> {
|
async saveEvents (queryRunner: QueryRunner, block: DeepPartial<BlockProgress>, events: DeepPartial<Event>[]): Promise<BlockProgress> {
|
||||||
const blockRepo = queryRunner.manager.getRepository(BlockProgress);
|
const blockRepo = queryRunner.manager.getRepository(BlockProgress);
|
||||||
const eventRepo = queryRunner.manager.getRepository(Event);
|
const eventRepo = queryRunner.manager.getRepository(Event);
|
||||||
|
|
||||||
@ -217,6 +217,12 @@ export class Database implements IPLDDatabaseInterface {
|
|||||||
return this._baseDatabase.getBlockProgress(repo, blockHash);
|
return this._baseDatabase.getBlockProgress(repo, blockHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getBlockProgressEntities (where: FindConditions<BlockProgress>, options: FindManyOptions<BlockProgress>): Promise<BlockProgress[]> {
|
||||||
|
const repo = this._conn.getRepository(BlockProgress);
|
||||||
|
|
||||||
|
return this._baseDatabase.getBlockProgressEntities(repo, where, options);
|
||||||
|
}
|
||||||
|
|
||||||
async updateBlockProgress (queryRunner: QueryRunner, block: BlockProgress, lastProcessedEventIndex: number): Promise<BlockProgress> {
|
async updateBlockProgress (queryRunner: QueryRunner, block: BlockProgress, lastProcessedEventIndex: number): Promise<BlockProgress> {
|
||||||
const repo = queryRunner.manager.getRepository(BlockProgress);
|
const repo = queryRunner.manager.getRepository(BlockProgress);
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import debug from 'debug';
|
import debug from 'debug';
|
||||||
import { DeepPartial } from 'typeorm';
|
import { DeepPartial, FindConditions, FindManyOptions } from 'typeorm';
|
||||||
import JSONbig from 'json-bigint';
|
import JSONbig from 'json-bigint';
|
||||||
import { ethers } from 'ethers';
|
import { ethers } from 'ethers';
|
||||||
|
|
||||||
@ -14,7 +14,6 @@ import * as codec from '@ipld/dag-cbor';
|
|||||||
import { EthClient } from '@vulcanize/ipld-eth-client';
|
import { EthClient } from '@vulcanize/ipld-eth-client';
|
||||||
import { StorageLayout } from '@vulcanize/solidity-mapper';
|
import { StorageLayout } from '@vulcanize/solidity-mapper';
|
||||||
import {
|
import {
|
||||||
EventInterface,
|
|
||||||
IPLDIndexer as BaseIndexer,
|
IPLDIndexer as BaseIndexer,
|
||||||
IndexerInterface,
|
IndexerInterface,
|
||||||
ValueResult,
|
ValueResult,
|
||||||
@ -22,6 +21,8 @@ import {
|
|||||||
ServerConfig,
|
ServerConfig,
|
||||||
updateStateForElementaryType,
|
updateStateForElementaryType,
|
||||||
JobQueue,
|
JobQueue,
|
||||||
|
Where,
|
||||||
|
QueryOptions,
|
||||||
BlockHeight,
|
BlockHeight,
|
||||||
IPFSClient
|
IPFSClient
|
||||||
} from '@vulcanize/util';
|
} from '@vulcanize/util';
|
||||||
@ -481,16 +482,20 @@ export class Indexer implements IndexerInterface {
|
|||||||
return this._baseIndexer.getBlockProgress(blockHash);
|
return this._baseIndexer.getBlockProgress(blockHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getBlockProgressEntities (where: FindConditions<BlockProgress>, options: FindManyOptions<BlockProgress>): Promise<BlockProgress[]> {
|
||||||
|
return this._baseIndexer.getBlockProgressEntities(where, options);
|
||||||
|
}
|
||||||
|
|
||||||
async getBlocksAtHeight (height: number, isPruned: boolean): Promise<BlockProgress[]> {
|
async getBlocksAtHeight (height: number, isPruned: boolean): Promise<BlockProgress[]> {
|
||||||
return this._baseIndexer.getBlocksAtHeight(height, isPruned);
|
return this._baseIndexer.getBlocksAtHeight(height, isPruned);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getOrFetchBlockEvents (block: DeepPartial<BlockProgress>): Promise<Array<EventInterface>> {
|
async fetchBlockEvents (block: DeepPartial<BlockProgress>): Promise<BlockProgress> {
|
||||||
return this._baseIndexer.getOrFetchBlockEvents(block, this._fetchAndSaveEvents.bind(this));
|
return this._baseIndexer.fetchBlockEvents(block, this._fetchAndSaveEvents.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
async getBlockEvents (blockHash: string): Promise<Array<Event>> {
|
async getBlockEvents (blockHash: string, where: Where, queryOptions: QueryOptions): Promise<Array<Event>> {
|
||||||
return this._baseIndexer.getBlockEvents(blockHash);
|
return this._baseIndexer.getBlockEvents(blockHash, where, queryOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
async removeUnknownEvents (block: BlockProgress): Promise<void> {
|
async removeUnknownEvents (block: BlockProgress): Promise<void> {
|
||||||
@ -574,7 +579,7 @@ export class Indexer implements IndexerInterface {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async _fetchAndSaveEvents ({ cid: blockCid, blockHash }: DeepPartial<BlockProgress>): Promise<void> {
|
async _fetchAndSaveEvents ({ cid: blockCid, blockHash }: DeepPartial<BlockProgress>): Promise<BlockProgress> {
|
||||||
assert(blockHash);
|
assert(blockHash);
|
||||||
|
|
||||||
const logsPromise = this._ethClient.getLogs({ blockHash });
|
const logsPromise = this._ethClient.getLogs({ blockHash });
|
||||||
@ -670,8 +675,10 @@ export class Indexer implements IndexerInterface {
|
|||||||
parentHash: block.parent.hash
|
parentHash: block.parent.hash
|
||||||
};
|
};
|
||||||
|
|
||||||
await this._db.saveEvents(dbTx, block, dbEvents);
|
const blockProgress = await this._db.saveEvents(dbTx, block, dbEvents);
|
||||||
await dbTx.commitTransaction();
|
await dbTx.commitTransaction();
|
||||||
|
|
||||||
|
return blockProgress;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await dbTx.rollbackTransaction();
|
await dbTx.rollbackTransaction();
|
||||||
throw error;
|
throw error;
|
||||||
|
Loading…
Reference in New Issue
Block a user