77from aiosignalrcore .hub_connection_builder import HubConnectionBuilder # type: ignore
88from aiosignalrcore .messages .completion_message import CompletionMessage # type: ignore
99from aiosignalrcore .transport .websockets .connection import ConnectionState # type: ignore
10- from pyee import AsyncIOEventEmitter # type: ignore
1110
1211from dipdup .config import (
1312 BigMapIndexConfig ,
1615 OperationHandlerOriginationPatternConfig ,
1716 OperationIndexConfig ,
1817)
18+ from dipdup .datasources .datasource import IndexDatasource
1919from dipdup .datasources .proxy import DatasourceRequestProxy
2020from dipdup .datasources .tzkt .enums import TzktMessageType
2121from dipdup .models import BigMapAction , BigMapData , OperationData
@@ -254,7 +254,7 @@ async def fetch_big_maps_by_level(self) -> AsyncGenerator[Tuple[int, List[BigMap
254254 yield big_maps [0 ].level , big_maps [: i + 1 ]
255255
256256
257- class TzktDatasource (AsyncIOEventEmitter ):
257+ class TzktDatasource (IndexDatasource ):
258258 """Bridge between REST/WS TzKT endpoints and DipDup.
259259
260260 * Converts raw API data to models
@@ -452,7 +452,7 @@ async def add_index(self, index_config: IndexConfigTemplateT) -> None:
452452 else :
453453 raise NotImplementedError (f'Index kind `{ index_config .kind } ` is not supported' )
454454
455- await self .on_connect ()
455+ await self ._on_connect ()
456456
457457 def _get_client (self ) -> BaseHubConnection :
458458 """Create SignalR client, register message callbacks"""
@@ -471,10 +471,10 @@ def _get_client(self) -> BaseHubConnection:
471471 )
472472 ).build ()
473473
474- self ._client .on_open (self .on_connect )
475- self ._client .on_error (self .on_error )
476- self ._client .on ('operations' , self .on_operation_message )
477- self ._client .on ('bigmaps' , self .on_big_map_message )
474+ self ._client .on_open (self ._on_connect )
475+ self ._client .on_error (self ._on_error )
476+ self ._client .on ('operations' , self ._on_operation_message )
477+ self ._client .on ('bigmaps' , self ._on_big_map_message )
478478
479479 return self ._client
480480
@@ -485,7 +485,7 @@ async def run(self) -> None:
485485 self ._logger .info ('Starting websocket client' )
486486 await self ._get_client ().start ()
487487
488- async def on_connect (self ) -> None :
488+ async def _on_connect (self ) -> None :
489489 """Subscribe to all required channels on established WS connection"""
490490 if self ._get_client ().transport .state != ConnectionState .connected :
491491 return
@@ -499,7 +499,7 @@ async def on_connect(self) -> None:
499499 for address , paths in self ._big_map_subscriptions .items ():
500500 await self .subscribe_to_big_maps (address , paths )
501501
502- def on_error (self , message : CompletionMessage ) -> NoReturn :
502+ def _on_error (self , message : CompletionMessage ) -> NoReturn :
503503 """Raise exception from WS server's error message"""
504504 raise Exception (message .error )
505505
@@ -554,7 +554,7 @@ async def subscribe_to_big_maps(self, address: str, paths: List[str]) -> None:
554554 ],
555555 )
556556
557- async def on_operation_message (
557+ async def _on_operation_message (
558558 self ,
559559 message : List [Dict [str , Any ]],
560560 ) -> None :
@@ -577,18 +577,19 @@ async def on_operation_message(
577577 if operation .status != 'applied' :
578578 continue
579579 operations .append (operation )
580- self .emit ( "operations" , operations )
580+ self .emit_operations ( operations )
581581
582582 elif message_type == TzktMessageType .REORG :
583- self .emit ("rollback" , self .level , current_level )
583+ if self .level is None :
584+ raise RuntimeError
585+ self .emit_rollback (self .level , current_level )
584586
585587 else :
586588 raise NotImplementedError
587589
588- async def on_big_map_message (
590+ async def _on_big_map_message (
589591 self ,
590592 message : List [Dict [str , Any ]],
591- sync = False ,
592593 ) -> None :
593594 """Parse and emit raw big map diffs from WS"""
594595 for item in message :
@@ -606,10 +607,12 @@ async def on_big_map_message(
606607 for big_map_json in item ['data' ]:
607608 big_map = self .convert_big_map (big_map_json )
608609 big_maps .append (big_map )
609- self .emit ( "big_maps" , big_maps )
610+ self .emit_big_maps ( big_maps )
610611
611612 elif message_type == TzktMessageType .REORG :
612- self .emit ("rollback" , self .level , current_level )
613+ if self .level is None :
614+ raise RuntimeError
615+ self .emit_rollback (self .level , current_level )
613616
614617 else :
615618 raise NotImplementedError
0 commit comments