Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore ERC721 token uris and owners on exceptions #176

Merged
merged 1 commit into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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