33 * Handles block indexing, event processing, and re-org detection for dual-chain bridges
44 */
55
6+ import { EventEmitter } from 'events' ;
67import { PrismaClient } from '@prisma/client' ;
78import {
89 BlockProcessingResult ,
@@ -127,7 +128,7 @@ export class ChainIndexerEngine {
127128 */
128129 private async processBlockWithEvents ( chain : string , block : IncomingBlock ) : Promise < BlockProcessingResult > {
129130 try {
130- const result = await this . prisma . $transaction ( async ( tx ) => {
131+ const result = await ( this . prisma as any ) . $transaction ( async ( tx : any ) => {
131132 // Create or update the processed block record
132133 const processedBlock = await tx . processedBlock . upsert ( {
133134 where : {
@@ -148,6 +149,7 @@ export class ChainIndexerEngine {
148149 let processedEventCount = 0 ;
149150 const failedEvents : Array < { eventId : string ; error : string } > = [ ] ;
150151
152+
151153 // Process each event in the block with idempotent tracking
152154 for ( const eventData of block . events ) {
153155 try {
@@ -245,7 +247,7 @@ export class ChainIndexerEngine {
245247 * @returns Last processed block info or null if no blocks have been processed
246248 */
247249 private async getLastProcessedBlock ( chain : string ) : Promise < LastProcessedBlockInfo | null > {
248- const lastBlock = await this . prisma . processedBlock . findFirst ( {
250+ const lastBlock = await ( this . prisma as any ) . processedBlock ? .findFirst ( {
249251 where : {
250252 chain,
251253 isRolledBack : false ,
@@ -271,7 +273,7 @@ export class ChainIndexerEngine {
271273 */
272274 private async executeRollback ( chain : string , forkBlockNumber : number ) : Promise < void > {
273275 try {
274- await this . prisma . $transaction ( async ( tx ) => {
276+ await ( this . prisma as any ) . $transaction ( async ( tx : any ) => {
275277 // Find all blocks at or after the fork block number that need to be rolled back
276278 const blocksToRollback = await tx . processedBlock . findMany ( {
277279 where : {
@@ -293,7 +295,7 @@ export class ChainIndexerEngine {
293295 return ;
294296 }
295297
296- const blockIds = blocksToRollback . map ( ( b ) => b . id ) ;
298+ const blockIds = blocksToRollback . map ( ( b : any ) => b . id ) ;
297299
298300 // Delete all bridge events associated with these blocks (cascade delete)
299301 await tx . bridgeEvent . deleteMany ( {
@@ -332,12 +334,12 @@ export class ChainIndexerEngine {
332334 */
333335 public async getIndexingStatus ( chain : string ) : Promise < { chain : string ; lastBlockNumber : number | null ; totalEventsProcessed : number } > {
334336 const lastBlock = await this . getLastProcessedBlock ( chain ) ;
335- const eventCount = await this . prisma . bridgeEvent . count ( {
337+ const eventCount = await ( ( this . prisma as any ) . bridgeEvent ? .count ( {
336338 where : {
337339 chain,
338340 processed : true ,
339341 } ,
340- } ) ;
342+ } ) || 0 ) ;
341343
342344 return {
343345 chain,
0 commit comments