From 76c4d943fd6b8857990c206f07ad26d75ab51754 Mon Sep 17 00:00:00 2001 From: Uxio Fuentefria Date: Tue, 18 Jan 2022 12:27:32 +0100 Subject: [PATCH] Ignore token uris and owners on exceptions - When retrieving token uris and owners for an ERC721 if a error ocurred if was not parsed and returned --- gnosis/eth/ethereum_client.py | 32 +++++++++++++++++--------------- setup.py | 2 +- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/gnosis/eth/ethereum_client.py b/gnosis/eth/ethereum_client.py index 5b999d8e8..f177dbea3 100644 --- a/gnosis/eth/ethereum_client.py +++ b/gnosis/eth/ethereum_client.py @@ -818,14 +818,14 @@ def get_info(self, token_address: str) -> Erc721Info: def get_owners( self, token_addresses_with_token_ids: Sequence[Tuple[str, int]] - ) -> List[Optional[str]]: + ) -> List[Optional[ChecksumAddress]]: """ :param token_addresses_with_token_ids: Tuple(token_address: str, token_id: int) :return: List of owner addresses, `None` if not found """ - return cast( - List[Optional[str]], - self.ethereum_client.batch_call( + return [ + ChecksumAddress(owner) if isinstance(owner, str) else None + for owner in self.ethereum_client.batch_call( [ get_erc721_contract( self.ethereum_client.w3, token_address @@ -833,8 +833,8 @@ def get_owners( for token_address, token_id in token_addresses_with_token_ids ], raise_exception=False, - ), - ) + ) + ] def get_token_uris( self, token_addresses_with_token_ids: Sequence[Tuple[str, int]] @@ -843,9 +843,9 @@ def get_token_uris( :param token_addresses_with_token_ids: Tuple(token_address: str, token_id: int) :return: List of token_uris, `None` if not found """ - return cast( - List[Optional[str]], - self.ethereum_client.batch_call( + return [ + token_uri if isinstance(token_uri, str) else None + for token_uri in self.ethereum_client.batch_call( [ get_erc721_contract( self.ethereum_client.w3, token_address @@ -853,8 +853,8 @@ def get_token_uris( for token_address, token_id in token_addresses_with_token_ids ], raise_exception=False, - ), - ) + ) + ] class ParityManager(EthereumClientManager): @@ -1342,7 +1342,7 @@ def batch_call( raise_exception: bool = True, force_batch_call: bool = False, block_identifier: Optional[BlockIdentifier] = "latest", - ) -> List[Optional[Any]]: + ) -> List[Optional[Union[bytes, Any]]]: """ Call multiple functions. Multicall contract by MakerDAO will be used by default if available @@ -1352,7 +1352,8 @@ def batch_call( :param force_batch_call: If ``True``, ignore multicall and always use batch calls to get the result (less optimal). If ``False``, more optimal way will be tried. :param block_identifier: - :return: + :return: List of elements decoded to their types, ``None`` if they cannot be decoded and + bytes if a revert error is returned and ``raise_exception=False`` :raises: BatchCallException """ if self.multicall and not force_batch_call: # Multicall is more optimal @@ -1380,7 +1381,7 @@ def batch_call_same_function( raise_exception: bool = True, force_batch_call: bool = False, block_identifier: Optional[BlockIdentifier] = "latest", - ) -> List[Optional[Any]]: + ) -> List[Optional[Union[bytes, Any]]]: """ Call the same function in multiple contracts. Way more optimal than using `batch_call` generating multiple ``ContractFunction`` objects. @@ -1392,7 +1393,8 @@ def batch_call_same_function( :param force_batch_call: If ``True``, ignore multicall and always use batch calls to get the result (less optimal). If ``False``, more optimal way will be tried. :param block_identifier: - :return: + :return: List of elements decoded to the same type, ``None`` if they cannot be decoded and + bytes if a revert error is returned and ``raise_exception=False`` :raises: BatchCallException """ if self.multicall and not force_batch_call: # Multicall is more optimal diff --git a/setup.py b/setup.py index 36426b38c..30e4e4b5a 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ setup( name="gnosis-py", - version="3.7.6", + version="3.7.7", packages=find_packages(), package_data={"gnosis": ["py.typed"]}, install_requires=requirements,