From 839bd211d6edf6d5bdcfc58055c4800e80c1cecc Mon Sep 17 00:00:00 2001 From: Lev Gorodetskiy Date: Wed, 30 Oct 2024 15:43:44 -0300 Subject: [PATCH] notes --- src/dipdup/codegen/substrate.py | 2 +- src/dipdup/config/substrate_node.py | 2 +- src/dipdup/datasources/__init__.py | 1 + src/dipdup/datasources/substrate_subscan.py | 1 + src/dipdup/fields.py | 7 ++++++- src/dipdup/indexes/substrate_events/index.py | 3 ++- src/dipdup/models/substrate.py | 1 + src/dipdup/runtimes.py | 5 +++-- 8 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/dipdup/codegen/substrate.py b/src/dipdup/codegen/substrate.py index 0a12a3aa9..db597c710 100644 --- a/src/dipdup/codegen/substrate.py +++ b/src/dipdup/codegen/substrate.py @@ -84,7 +84,7 @@ def event_metadata_to_jsonschema( description = '\n'.join(metadata['docs']).replace(r'\[', '[').replace(r'\]', ']') args_name = [a for a in metadata.get('args_name', ()) if a] if not args_name: - args_name = extract_args_name(description) + args_name = extract_args_name(description) # type: ignore[assignment] schema = { '$schema': 'http://json-schema.org/draft-07/schema#', 'title': metadata['name'], diff --git a/src/dipdup/config/substrate_node.py b/src/dipdup/config/substrate_node.py index 6555e87f4..706267de2 100644 --- a/src/dipdup/config/substrate_node.py +++ b/src/dipdup/config/substrate_node.py @@ -32,5 +32,5 @@ def merge_subscriptions(self) -> bool: @property def rollback_depth(self) -> int: - # FIXME: + # FIXME: detect from node or/and document how to set it return 0 diff --git a/src/dipdup/datasources/__init__.py b/src/dipdup/datasources/__init__.py index c5a3a8de3..69a776537 100644 --- a/src/dipdup/datasources/__init__.py +++ b/src/dipdup/datasources/__init__.py @@ -60,6 +60,7 @@ class AbiDatasource(Datasource[DatasourceConfigT], Generic[DatasourceConfigT]): async def get_abi(self, address: str) -> dict[str, Any]: ... +# FIXME: inconsistent usage class IndexDatasource(Datasource[DatasourceConfigT], Generic[DatasourceConfigT]): def __init__( self, diff --git a/src/dipdup/datasources/substrate_subscan.py b/src/dipdup/datasources/substrate_subscan.py index acd92c6de..3344ee9b0 100644 --- a/src/dipdup/datasources/substrate_subscan.py +++ b/src/dipdup/datasources/substrate_subscan.py @@ -6,6 +6,7 @@ class SubstrateSubscanDatasource(AbiDatasource[SubstrateSubscanDatasourceConfig]): + # FIXME: not used in codegen async def get_abi(self, address: str) -> dict[str, Any]: raise NotImplementedError diff --git a/src/dipdup/fields.py b/src/dipdup/fields.py index 7fe16af0f..429d02858 100644 --- a/src/dipdup/fields.py +++ b/src/dipdup/fields.py @@ -58,7 +58,12 @@ _EnumFieldT = TypeVar('_EnumFieldT', bound=Enum) -JSONField = partial(_JSONField, encoder=partial(json_dumps, option=None), decoder=orjson.loads) # type: ignore +# TODO: changelog +JSONField = partial( + _JSONField, + encoder=partial(json_dumps, option=None), # type: ignore[arg-type] + decoder=orjson.loads, +) class EnumField(Field[_EnumFieldT]): diff --git a/src/dipdup/indexes/substrate_events/index.py b/src/dipdup/indexes/substrate_events/index.py index 535dd3cc7..3e3e33143 100644 --- a/src/dipdup/indexes/substrate_events/index.py +++ b/src/dipdup/indexes/substrate_events/index.py @@ -5,6 +5,7 @@ from dipdup.config.substrate_events import SubstrateEventsHandlerConfig from dipdup.config.substrate_events import SubstrateEventsIndexConfig +from dipdup.datasources.substrate_node import SubstrateNodeDatasource from dipdup.datasources.substrate_subsquid import SubstrateSubsquidDatasource from dipdup.indexes.substrate import SubstrateDatasource from dipdup.indexes.substrate import SubstrateIndex @@ -34,8 +35,8 @@ def __init__( ) -> None: super().__init__(ctx, config, datasources) self._names = tuple(c.name for c in self._config.handlers) - # FIXME: it's not EVM index self.subsquid_datasources = tuple(d for d in datasources if isinstance(d, SubstrateSubsquidDatasource)) + self.node_datasources = tuple(d for d in datasources if isinstance(d, SubstrateNodeDatasource)) async def _synchronize_subsquid(self, sync_level: int) -> None: first_level = self.state.level + 1 diff --git a/src/dipdup/models/substrate.py b/src/dipdup/models/substrate.py index 5b7f54ffe..1cb244b90 100644 --- a/src/dipdup/models/substrate.py +++ b/src/dipdup/models/substrate.py @@ -50,6 +50,7 @@ class SubstrateEvent(Generic[PayloadT]): data: SubstrateEventData runtime: SubstrateRuntime + # TODO: could be used in other models with typed payload @cached_property def payload(self) -> PayloadT: return cast( diff --git a/src/dipdup/runtimes.py b/src/dipdup/runtimes.py index eaa0d4a3f..3c653d392 100644 --- a/src/dipdup/runtimes.py +++ b/src/dipdup/runtimes.py @@ -19,7 +19,8 @@ _logger = logging.getLogger(__name__) -def extract_args_name(description: str) -> list[str]: +@cache +def extract_args_name(description: str) -> tuple[str, ...]: pattern = r'\((.*?)\)|\[(.*?)\]' match = re.search(pattern, description) @@ -27,7 +28,7 @@ def extract_args_name(description: str) -> list[str]: raise ValueError('No valid bracket pairs found in the description') args_str = match.group(1) or match.group(2) - return [arg.strip('\\') for arg in args_str.split(', ')] + return tuple(arg.strip('\\') for arg in args_str.split(', ')) @cache