From e2e629f695f10be84c0f790061e9172e253d8557 Mon Sep 17 00:00:00 2001 From: Uxio Fuentefria Date: Tue, 22 Jun 2021 14:41:24 +0200 Subject: [PATCH] Handle ValueError for erc20 transfers --- .../history/indexers/erc20_events_indexer.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/safe_transaction_service/history/indexers/erc20_events_indexer.py b/safe_transaction_service/history/indexers/erc20_events_indexer.py index 0e705d486..2e1b3fe05 100644 --- a/safe_transaction_service/history/indexers/erc20_events_indexer.py +++ b/safe_transaction_service/history/indexers/erc20_events_indexer.py @@ -6,7 +6,6 @@ from cache_memoize import cache_memoize from cachetools import cachedmethod from eth_abi.exceptions import DecodingError -from requests import RequestException from web3.exceptions import BadFunctionCallOutput from gnosis.eth import EthereumClient @@ -47,14 +46,14 @@ def __init__(self, ethereum_client: EthereumClient, *args, **kwargs) self._cache_is_erc20 = {} - @property - def database_model(self): - return SafeContract - @property def database_field(self): return 'erc20_block_number' + @property + def database_model(self): + return SafeContract + def find_relevant_elements(self, addresses: List[str], from_block_number: int, to_block_number: int, current_block_number: Optional[int] = None) -> List[Dict[str, Any]]: @@ -100,8 +99,12 @@ def _find_elements_using_transfer_topics(self, addresses: Sequence[str], from_bl return self.ethereum_client.erc20.get_total_transfer_history(addresses, from_block=from_block_number, to_block=to_block_number) - except RequestException as e: + except IOError as e: raise self.FindRelevantElementsException('Request error retrieving erc20 events') from e + except ValueError as e: + # For example, BSC returns: + # ValueError({'code': -32000, 'message': 'exceed maximum block range: 5000'}) + raise self.FindRelevantElementsException('Value error retrieving erc20 events') from e def _find_elements_without_transfer_topics(self, addresses: Sequence[str], from_block_number: int, to_block_number: int) -> List[Dict[str, Any]]: @@ -116,8 +119,12 @@ def _find_elements_without_transfer_topics(self, addresses: Sequence[str], from_ try: erc20_transfer_events = self.ethereum_client.erc20.get_total_transfer_history(from_block=from_block_number, to_block=to_block_number) - except RequestException as e: + except IOError as e: raise self.FindRelevantElementsException('Request error retrieving erc20 events') from e + except ValueError as e: + # For example, BSC returns: + # ValueError({'code': -32000, 'message': 'exceed maximum block range: 5000'}) + raise self.FindRelevantElementsException('Value error retrieving erc20 events') from e filtered_events = [] addresses_set = set(addresses) # Linear time `in` filtering