From bfe027489faaa90c455758809acf1f31e5d409dc Mon Sep 17 00:00:00 2001 From: Lev Gorodetskiy Date: Wed, 8 Jan 2025 23:16:27 -0300 Subject: [PATCH] lint and fixes --- CHANGELOG.md | 5 +++-- docs/9.release-notes/_8.0_changelog.md | 3 +++ docs/config.rst | 2 -- src/dipdup/abi/evm.py | 4 ++-- src/dipdup/indexes/evm_transactions/matcher.py | 2 +- src/dipdup/utils.py | 10 +++++++--- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b16bdb13..d9ff043f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,8 +10,9 @@ Releases prior to 7.0 has been removed from this file to declutter search result ### Fixed -- subsquid: Fixed float type for `timestamp` field on event / transaction deserialization. -- subsquid: Fixed empty field base conversion on event deserialization. +- evm: Fixed parsing tuple types in ABI. +- evm.subsquid: Fixed type of `timestamp` field of event/transaction models. +- evm.subsquid: Fixed empty field base conversion on event deserialization. ## [8.1.3] - 2024-12-20 diff --git a/docs/9.release-notes/_8.0_changelog.md b/docs/9.release-notes/_8.0_changelog.md index f20cb17da..0fe8b88d0 100644 --- a/docs/9.release-notes/_8.0_changelog.md +++ b/docs/9.release-notes/_8.0_changelog.md @@ -36,8 +36,11 @@ - database: Fixed concurrency issue when using `get_or_create` method. - evm.events: Fixed matching logs when filtering by topic0. - evm.events: Improve fetching event batches from node. +- evm.subsquid: Fixed empty field base conversion on event deserialization. +- evm.subsquid: Fixed type of `timestamp` field of event/transaction models. - evm.subsquid: Fixed typo in `iter_events` method name. - evm: Fixed crash when contract ABI contains overloaded methods. +- evm: Fixed parsing tuple types in ABI. - install: Fixed reinstalling package when `--force` flag is used. - models: Fixed `CachedModel` preloading. - models: Fixed setting default value for `Meta.maxsize`. diff --git a/docs/config.rst b/docs/config.rst index 552bde5ef..269b2d28b 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -2,13 +2,11 @@ .. autoclass:: dipdup.config.DipDupConfig -.. autoclass:: dipdup.config.AbiDatasourceConfig .. autoclass:: dipdup.config.abi_etherscan.AbiEtherscanDatasourceConfig .. autoclass:: dipdup.config.AdvancedConfig .. autoclass:: dipdup.config.ApiConfig .. autoclass:: dipdup.config.coinbase.CoinbaseDatasourceConfig .. autoclass:: dipdup.config.ContractConfig -.. autoclass:: dipdup.config.DatasourceConfig .. autoclass:: dipdup.config.evm.EvmContractConfig .. autoclass:: dipdup.config.evm_node.EvmNodeDatasourceConfig .. autoclass:: dipdup.config.evm_events.EvmEventsHandlerConfig diff --git a/src/dipdup/abi/evm.py b/src/dipdup/abi/evm.py index ae7c6afb4..21f66fc2e 100644 --- a/src/dipdup/abi/evm.py +++ b/src/dipdup/abi/evm.py @@ -129,7 +129,7 @@ def _convert_abi(abi_path: Path) -> EvmAbi: EvmEventAbi( name=abi_item['name'], topic0=topic0_from_abi(abi_item), - inputs=inputs, + inputs=tuple(inputs), topic_count=len([i for i in inputs if i[1]]), ) ) @@ -195,7 +195,7 @@ def topic0_from_abi(event: dict[str, Any]) -> str: raise FrameworkException(f'`{event["name"]}` is not an event') types = [] - from web3._utils.abi import collapse_if_tuple + from eth_utils.abi import collapse_if_tuple for input in event['inputs']: types.append(collapse_if_tuple(input)) diff --git a/src/dipdup/indexes/evm_transactions/matcher.py b/src/dipdup/indexes/evm_transactions/matcher.py index 5bfd89271..ddfa953a7 100644 --- a/src/dipdup/indexes/evm_transactions/matcher.py +++ b/src/dipdup/indexes/evm_transactions/matcher.py @@ -49,7 +49,7 @@ def prepare_transaction_handler_args( name=handler_config.method, signature=handler_config.signature, )['inputs'] - from web3._utils.abi import collapse_if_tuple + from eth_utils.abi import collapse_if_tuple data = decode_abi( types=tuple(collapse_if_tuple(input) for input in inputs), diff --git a/src/dipdup/utils.py b/src/dipdup/utils.py index 9e0dc3c0c..a46f2ddfc 100644 --- a/src/dipdup/utils.py +++ b/src/dipdup/utils.py @@ -211,9 +211,13 @@ def parse_object( if nested: for k, v in model_dict.items(): - if isinstance(v, Sequence): - nested_type = type_.model_fields[k].annotation - model_dict[k] = parse_object(nested_type, v, plain=True) + if not isinstance(v, list | tuple): + continue + + # NOTE: Might be `from_` or other reserved keyword + field_k = '{k}_ ' if k not in type_.model_fields else k + nested_type = type_.model_fields[field_k].annotation # type: ignore[arg-type] + model_dict[k] = parse_object(nested_type, v, plain=True) return type_(**model_dict) except ValidationError as e: