1+ import { EventEmitter } from "events" ;
12import logger from '../logger' ;
23import { StorageService } from './storage' ;
34import { LoggifyClass } from '../decorators/Loggify' ;
45import { EventStorage , IEvent , EventModel } from '../models/events' ;
5- import { PassThrough } from 'stream' ;
66import { Storage } from './storage' ;
77import { Config , ConfigService } from './config' ;
88
99@LoggifyClass
1010export class EventService {
11- txStream = new PassThrough ( { objectMode : true } ) ;
12- blockStream = new PassThrough ( { objectMode : true } ) ;
13- addressCoinStream = new PassThrough ( { objectMode : true } ) ;
11+ txEvent = new EventEmitter ( ) ;
12+ blockEvent = new EventEmitter ( ) ;
13+ addressCoinEvent = new EventEmitter ( ) ;
1414 storageService : StorageService ;
1515 configService : ConfigService ;
1616 eventModel : EventModel ;
@@ -57,7 +57,7 @@ export class EventService {
5757 const txEvent = await txCursor . next ( ) ;
5858 if ( txEvent ) {
5959 const tx = < IEvent . TxEvent > txEvent . payload ;
60- this . txStream . write ( tx ) ;
60+ this . txEvent . emit ( 'tx' , tx ) ;
6161 lastTxUpdate = new Date ( ) ;
6262 }
6363 }
@@ -73,7 +73,7 @@ export class EventService {
7373 const blockEvent = await blockCursor . next ( ) ;
7474 if ( blockEvent ) {
7575 const block = < IEvent . BlockEvent > blockEvent . payload ;
76- this . blockStream . write ( block ) ;
76+ this . blockEvent . emit ( 'block' , block ) ;
7777 lastBlockUpdate = new Date ( ) ;
7878 }
7979 }
@@ -89,7 +89,7 @@ export class EventService {
8989 const addressTx = await addressTxCursor . next ( ) ;
9090 if ( addressTx ) {
9191 const addressCoin = < IEvent . CoinEvent > addressTx . payload ;
92- this . addressCoinStream . write ( addressCoin ) ;
92+ this . addressCoinEvent . emit ( 'coin' , addressCoin ) ;
9393 lastAddressTxUpdate = new Date ( ) ;
9494 }
9595 }
0 commit comments