diff --git a/src/dipdup/datasources/substrate_node.py b/src/dipdup/datasources/substrate_node.py index 3a4bf9b78..cc32d67df 100644 --- a/src/dipdup/datasources/substrate_node.py +++ b/src/dipdup/datasources/substrate_node.py @@ -223,6 +223,7 @@ async def get_block_hash(self, height: int) -> str: async def get_block_header(self, hash: str) -> BlockHeader: response = await self._jsonrpc_request('chain_getHeader', [hash]) + # FIXME: missing fields return { 'hash': hash, 'number': int(response['number'], 16), @@ -242,16 +243,16 @@ async def get_metadata_header(self, height: int) -> MetadataHeader: async def get_metadata_header_batch(self, heights: list[int]) -> list[MetadataHeader]: return await asyncio.gather(*[self.get_metadata_header(h) for h in heights]) - async def get_full_block(self, hash: str) -> dict: + async def get_full_block(self, hash: str) -> dict[str, Any]: return await self._jsonrpc_request('chain_getBlock', [hash]) async def get_events(self, block_hash: str) -> tuple[SubstrateEventDataDict, ...]: events = await self._interface.get_events(block_hash) - res_events: list[SubstrateEventDataDict] = [] - for event in events: - event: dict = event.decode() - res_events.append( + result: list[SubstrateEventDataDict] = [] + for raw_event in events: + event: dict[str, Any] = raw_event.decode() + result.append( { 'name': f'{event['module_id']}.{event['event_id']}', 'index': event['event_index'], @@ -262,7 +263,7 @@ async def get_events(self, block_hash: str) -> tuple[SubstrateEventDataDict, ... } ) - return tuple(res_events) + return tuple(result) async def find_metadata_versions( self, diff --git a/src/dipdup/dipdup.py b/src/dipdup/dipdup.py index e12588e28..bdfe22b39 100644 --- a/src/dipdup/dipdup.py +++ b/src/dipdup/dipdup.py @@ -335,7 +335,7 @@ def _log_status(self) -> None: # NOTE: Resulting message is about 80 chars with the current logging format msg += ' ' * (48 - len(msg)) - def fmt(speed): + def fmt(speed: float) -> str: return ' 0' if speed < 0.1 else f'{speed:5.{0 if speed >= 1 else 1}f}' msg += f' {fmt(levels_speed)} L {fmt(objects_speed)} O' @@ -557,13 +557,19 @@ async def _on_tzkt_events(self, datasource: TezosTzktDatasource, events: tuple[T index.push_realtime_message(events) # TODO: fix data typing - async def _on_substrate_head(self, datasource: SubstrateNodeDatasource, head: HeadBlock) -> None: + async def _on_substrate_head( + self, + datasource: SubstrateNodeDatasource, + head: HeadBlock, + ) -> None: # TODO: any head updates here? pass # TODO: fix data typing async def _on_substrate_events( - self, datasource: SubstrateNodeDatasource, events: tuple[dict[str, Any], ...] + self, + datasource: SubstrateNodeDatasource, + events: tuple[dict[str, Any], ...], ) -> None: for index in self._indexes.values(): if isinstance(index, SubstrateEventsIndex) and datasource in index.datasources: diff --git a/src/dipdup/indexes/_subsquid.py b/src/dipdup/indexes/_subsquid.py index 1ed6c017d..9c93883e9 100644 --- a/src/dipdup/indexes/_subsquid.py +++ b/src/dipdup/indexes/_subsquid.py @@ -39,7 +39,7 @@ async def _get_node_sync_level( self, subsquid_level: int, index_level: int, - node: JsonRpcDatasource | None = None, + node: JsonRpcDatasource[Any] | None = None, ) -> int | None: if not self.node_datasources: return None diff --git a/src/dipdup/models/substrate.py b/src/dipdup/models/substrate.py index cda0ab581..6073e8c9c 100644 --- a/src/dipdup/models/substrate.py +++ b/src/dipdup/models/substrate.py @@ -33,7 +33,8 @@ class SubstrateEventDataDict(TypedDict): index: int extrinsicIndex: int callAddress: list[str] - args: list[Any] + args: list[Any] | None + decoded_args: dict[str, Any] | None @dataclass(frozen=True, kw_only=True) @@ -73,7 +74,11 @@ class SubstrateEvent(Generic[PayloadT]): # TODO: could be used in other models with typed payload @cached_property def payload(self) -> PayloadT: - return self.data.decoded_args or cast( + if self.data.decoded_args is not None: + return self.data.decoded_args + + assert self.data.args is not None + return cast( PayloadT, self.runtime.decode_event_args( name=self.name,