diff --git a/src/dipdup/codegen/substrate.py b/src/dipdup/codegen/substrate.py index 1f7377837..d5cc2d5f6 100644 --- a/src/dipdup/codegen/substrate.py +++ b/src/dipdup/codegen/substrate.py @@ -83,9 +83,10 @@ def event_metadata_to_jsonschema( metadata: dict[str, Any], ) -> dict[str, Any]: description = '\n'.join(metadata['docs']).replace(r'\[', '[').replace(r'\]', ']') - args_name = [a for a in metadata.get('args_name', ()) if a] + args_name = tuple(a for a in metadata.get('args_name', ()) if a) if not args_name: - args_name = extract_args_name(description) # type: ignore[assignment] + args_name = extract_args_name(tuple(metadata['docs'])) + schema = { '$schema': 'http://json-schema.org/draft-07/schema#', 'title': metadata['name'], diff --git a/src/dipdup/runtimes.py b/src/dipdup/runtimes.py index ce4d3f6f6..d4e288a40 100644 --- a/src/dipdup/runtimes.py +++ b/src/dipdup/runtimes.py @@ -1,5 +1,4 @@ import logging -import re from contextlib import suppress from copy import copy from functools import cache @@ -24,13 +23,13 @@ @cache -def extract_args_name(docs: list[str]) -> tuple[str, ...]: +def extract_args_name(docs: tuple[str, ...]) -> tuple[str, ...]: docs_str = ''.join(docs).replace('\\n', '').replace('\n', '') # find the last bracket pair, [] or () open_bracket = max(docs_str.rfind('['), docs_str.rfind('(')) close_bracket = max(docs_str.rfind(']'), docs_str.rfind(')')) - slice = docs_str[open_bracket + 1:close_bracket] + slice = docs_str[open_bracket + 1 : close_bracket] return tuple(arg.strip('\\ ') for arg in slice.split(',')) @@ -74,7 +73,8 @@ def get_event_abi(self, qualname: str) -> dict[str, Any]: continue self._events[qualname] = event found = True - else: + + if not found: raise FrameworkException(f'Event `{qualname}` not found in `{self._name}` spec') return self._events[qualname] @@ -86,7 +86,7 @@ def get_event_arg_names(event_abi: dict[str, Any]) -> tuple[str, ...]: # NOTE: Old metadata if not arg_names: - arg_names = extract_args_name(event_abi['docs']) + arg_names = extract_args_name(tuple(event_abi['docs'])) return tuple(arg_names) @@ -175,7 +175,6 @@ def decode_event_args( args = dict(zip(arg_names, args, strict=True)) - payload = {} for (key, value), type_ in zip(args.items(), arg_types, strict=True): if isinstance(value, int):