From 691a633300f3a506e924e0f6b6ced96ec82fa5f7 Mon Sep 17 00:00:00 2001 From: Alexis Pentori Date: Thu, 25 Jan 2024 18:22:34 +0100 Subject: [PATCH] wallet-fetcher: fix error fetching erc-20 tokens Signed-off-by: Alexis Pentori --- wallet-fetcher/metadata.yaml | 2 +- wallet-fetcher/source_wallet_fetcher/source.py | 1 - wallet-fetcher/source_wallet_fetcher/stream.py | 7 +++++-- wallet-fetcher/source_wallet_fetcher/utils.py | 9 +++++---- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/wallet-fetcher/metadata.yaml b/wallet-fetcher/metadata.yaml index 0b9d8cb..ee49592 100644 --- a/wallet-fetcher/metadata.yaml +++ b/wallet-fetcher/metadata.yaml @@ -10,7 +10,7 @@ data: connectorSubtype: api connectorType: source definitionId: 1e55cfe0-f591-4281-9a20-18d89d45f685 - dockerImageTag: 0.5.0 + dockerImageTag: 0.7.0 dockerRepository: harbor.status.im/status-im/airbyte/wallet-fetcher githubIssueLabel: source-wallet-fetcher icon: icon.svg diff --git a/wallet-fetcher/source_wallet_fetcher/source.py b/wallet-fetcher/source_wallet_fetcher/source.py index 6fd6f9c..4d8160f 100644 --- a/wallet-fetcher/source_wallet_fetcher/source.py +++ b/wallet-fetcher/source_wallet_fetcher/source.py @@ -1,5 +1,4 @@ from typing import Any, Iterable, List, Mapping, MutableMapping, Optional, Tuple -from .utils import extract_token from .stream import BitcoinToken, EthereumToken import logging import requests diff --git a/wallet-fetcher/source_wallet_fetcher/stream.py b/wallet-fetcher/source_wallet_fetcher/stream.py index 6c785f6..3cf76a8 100644 --- a/wallet-fetcher/source_wallet_fetcher/stream.py +++ b/wallet-fetcher/source_wallet_fetcher/stream.py @@ -4,7 +4,7 @@ import logging import requests import json import time - +from .utils import extract_token logger = logging.getLogger("airbyte") @@ -100,6 +100,9 @@ class EthereumToken(BlockchainStream): try: yield extract_token(stream_slice['name'], t) except Exception as e: - logger.debug('Dropping token not valid %s' % t ) + name = t + if 'name' in t: + name= t['name'] + logger.warning('Dropping token %s not valid %s',name, e ) # Delaying calls - Not great but that works time.sleep(2) diff --git a/wallet-fetcher/source_wallet_fetcher/utils.py b/wallet-fetcher/source_wallet_fetcher/utils.py index ff16663..f32204c 100644 --- a/wallet-fetcher/source_wallet_fetcher/utils.py +++ b/wallet-fetcher/source_wallet_fetcher/utils.py @@ -8,7 +8,9 @@ def extract_token(wallet_name, token_data): try: if token_data['tokenInfo']['decimals'] == '22270923681254677845691103109158760375340177724800803888364822332811285364736': # The data is not valid, droping it. - raise Exception('Not a valid token') + raise Exception('Invalid token: decimal fields not valid: %s', token_data) + if token_data['tokenInfo']['owner'] == '0x0000000000000000000000000000000000000000': + raise Exception('Invalid token, owner is the void address: %s', token_data) token = { "wallet_name": wallet_name, "name": token_data['tokenInfo']['name'], @@ -20,6 +22,5 @@ def extract_token(wallet_name, token_data): "decimal": token_data['tokenInfo']['decimals'] } return token - except KeyError: - raise Exception('Not a valid token') - + except KeyError as err: + raise Exception('Invalid ERC-20 Token: %s', err)