Skip to content

Commit

Permalink
Ignore token uris and owners on exceptions
Browse files Browse the repository at this point in the history
- When retrieving token uris and owners for an ERC721 if a error ocurred
  if was not parsed and returned
  • Loading branch information
Uxio0 committed Jan 18, 2022
1 parent 3c6670c commit 76c4d94
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
32 changes: 17 additions & 15 deletions gnosis/eth/ethereum_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,23 +818,23 @@ 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
).functions.ownerOf(token_id)
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]]
Expand All @@ -843,18 +843,18 @@ 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
).functions.tokenURI(token_id)
for token_address, token_id in token_addresses_with_token_ids
],
raise_exception=False,
),
)
)
]


class ParityManager(EthereumClientManager):
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 76c4d94

Please sign in to comment.