99from typing import DefaultDict
1010from typing import Deque
1111from typing import Dict
12+ from typing import Generic
1213from typing import Iterable
1314from typing import Iterator
1415from typing import List
1516from typing import Optional
1617from typing import Sequence
1718from typing import Set
1819from typing import Tuple
20+ from typing import TypeVar
1921from typing import Union
2022from typing import cast
2123
3638from dipdup .config import OperationHandlerTransactionPatternConfig
3739from dipdup .config import OperationIndexConfig
3840from dipdup .config import OperationType
41+ from dipdup .config import OperationUnfilteredIndexConfig
3942from dipdup .config import ResolvedIndexConfigT
4043from dipdup .config import SkipHistory
4144from dipdup .config import TokenTransferHandlerConfig
7174
7275_logger = logging .getLogger (__name__ )
7376
77+ ConfigT = TypeVar ('ConfigT' , bound = ResolvedIndexConfigT )
78+
7479
7580@dataclass (frozen = True )
7681class OperationSubgroup :
@@ -108,14 +113,10 @@ def extract_operation_subgroups(
108113 for _operation_index , operation in enumerate (operations ):
109114 # NOTE: Filtering out operations that are not part of any index
110115 if operation .type == 'transaction' :
111- if operation .entrypoint not in entrypoints and len ( entrypoints ) != 0 :
116+ if entrypoints and operation .entrypoint not in entrypoints :
112117 filtered += 1
113118 continue
114- if (
115- operation .sender_address not in addresses
116- and operation .target_address not in addresses
117- and len (addresses ) != 0
118- ):
119+ if addresses and operation .sender_address not in addresses and operation .target_address not in addresses :
119120 filtered += 1
120121 continue
121122
@@ -146,7 +147,7 @@ def extract_operation_subgroups(
146147 )
147148
148149
149- class Index :
150+ class Index ( Generic [ ConfigT ]) :
150151 """Base class for index implementations
151152
152153 Provides common interface for managing index state and switching between sync and realtime modes.
@@ -155,7 +156,7 @@ class Index:
155156 message_type : MessageType
156157 _queue : Deque
157158
158- def __init__ (self , ctx : DipDupContext , config : ResolvedIndexConfigT , datasource : TzktDatasource ) -> None :
159+ def __init__ (self , ctx : DipDupContext , config : ConfigT , datasource : TzktDatasource ) -> None :
159160 self ._ctx = ctx
160161 self ._config = config
161162 self ._datasource = datasource
@@ -298,9 +299,8 @@ def _extract_level(
298299 return batch_levels .pop ()
299300
300301
301- class OperationIndex (Index ):
302+ class OperationIndex (Index [ OperationIndexConfig ] ):
302303 message_type = MessageType .operation
303- _config : OperationIndexConfig
304304
305305 def __init__ (self , ctx : DipDupContext , config : OperationIndexConfig , datasource : TzktDatasource ) -> None :
306306 super ().__init__ (ctx , config , datasource )
@@ -611,7 +611,6 @@ async def _get_contract_hashes(self, address: str) -> Tuple[int, int]:
611611
612612class BigMapIndex (Index ):
613613 message_type = MessageType .big_map
614- _config : BigMapIndexConfig
615614
616615 def __init__ (self , ctx : DipDupContext , config : BigMapIndexConfig , datasource : TzktDatasource ) -> None :
617616 super ().__init__ (ctx , config , datasource )
@@ -838,7 +837,6 @@ def _get_big_map_pairs(self) -> Set[Tuple[str, str]]:
838837
839838class HeadIndex (Index ):
840839 message_type : MessageType = MessageType .head
841- _config : HeadIndexConfig
842840
843841 def __init__ (self , ctx : DipDupContext , config : HeadIndexConfig , datasource : TzktDatasource ) -> None :
844842 super ().__init__ (ctx , config , datasource )
@@ -887,7 +885,6 @@ def push_head(self, head: HeadBlockData) -> None:
887885
888886class TokenTransferIndex (Index ):
889887 message_type = MessageType .token_transfer
890- _config : TokenTransferIndexConfig
891888
892889 def __init__ (self , ctx : DipDupContext , config : TokenTransferIndexConfig , datasource : TzktDatasource ) -> None :
893890 super ().__init__ (ctx , config , datasource )
@@ -1026,10 +1023,10 @@ def _get_token_ids(self) -> Set[int]:
10261023
10271024class OperationUnfilteredIndex (OperationIndex ):
10281025 message_type = MessageType .operation
1029- _config : OperationIndexConfig
10301026
1031- def __init__ (self , ctx : DipDupContext , config : OperationIndexConfig , datasource : TzktDatasource ) -> None :
1032- super ().__init__ (ctx , config , datasource )
1027+ def __init__ (self , ctx : DipDupContext , config : OperationUnfilteredIndexConfig , datasource : TzktDatasource ) -> None :
1028+ # FIXME: Ugly inheritance hack
1029+ Index .__init__ (self , ctx , config , datasource ) # type: ignore
10331030 self ._queue : Deque [Tuple [OperationSubgroup , ...]] = deque ()
10341031 self ._contract_hashes : Dict [str , Tuple [int , int ]] = {}
10351032
@@ -1071,7 +1068,6 @@ async def _match_operation_subgroup(self, operation_subgroup: OperationSubgroup)
10711068
10721069class EventIndex (Index ):
10731070 message_type = MessageType .event
1074- _config : EventIndexConfig
10751071
10761072 def __init__ (self , ctx : DipDupContext , config : EventIndexConfig , datasource : TzktDatasource ) -> None :
10771073 super ().__init__ (ctx , config , datasource )
0 commit comments