From 8444b3e7311f123ff24355f4146bc3bd8797c2d2 Mon Sep 17 00:00:00 2001 From: Alexis Pentori Date: Thu, 30 Nov 2023 18:01:15 +0100 Subject: [PATCH] fixing invalid token problems Token where the smartcontract was destroyed have invalid balance breaking dbt tranformation. Signed-off-by: Alexis Pentori --- source_wallet_fetcher/schemas/token.json | 4 ++-- source_wallet_fetcher/source.py | 5 ++++- source_wallet_fetcher/utils.py | 12 ++++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/source_wallet_fetcher/schemas/token.json b/source_wallet_fetcher/schemas/token.json index 0092e2c..91e86c1 100644 --- a/source_wallet_fetcher/schemas/token.json +++ b/source_wallet_fetcher/schemas/token.json @@ -35,13 +35,13 @@ "balance": { "type": [ "null", - "numeric" + "number" ] }, "decimal": { "type": [ "null", - "integer" + "number" ] } } diff --git a/source_wallet_fetcher/source.py b/source_wallet_fetcher/source.py index 4ef6878..32b6937 100644 --- a/source_wallet_fetcher/source.py +++ b/source_wallet_fetcher/source.py @@ -55,7 +55,10 @@ class Token(HttpStream): logging.info("Fetching Tokens balance information") tokens_data=response.json()['tokens'] for t in tokens_data: - yield extract_token(t) + try: + yield extract_token(t) + except Exception as e: + logger.error('Dropping token not valid %s' % t ) # Source class SourceWalletFetcher(AbstractSource): def check_connection(self, logger, config) -> Tuple[bool, any]: diff --git a/source_wallet_fetcher/utils.py b/source_wallet_fetcher/utils.py index f8ef1ad..061db15 100644 --- a/source_wallet_fetcher/utils.py +++ b/source_wallet_fetcher/utils.py @@ -3,22 +3,22 @@ import json def extract_token(token_data): - name= 'No Name' if 'name' not in token_data['tokenInfo'] else token_data['tokenInfo']['name'] description= 'No description available' if 'description' not in token_data['tokenInfo'] else token_data['tokenInfo']['description'] symbol= 'No Symbol' if 'symbol' not in token_data['tokenInfo'] else token_data['tokenInfo']['symbol'] try: + if token_data['tokenInfo']['decimals'] == '22270923681254677845691103109158760375340177724800803888364822332811285364736': + # The data is not valid, droping it. + raise Exception('Not a valid token') token = { - "name": name, + "name": token_data['tokenInfo']['name'], "symbol": symbol, "description": description, "address":token_data['tokenInfo']['address'], "chain": "Ethereum", - "balance": token_data['rawBalance'], + "balance": token_data['balance'], "decimal": token_data['tokenInfo']['decimals'] } return token except KeyError: - logging.error("Error when trying to extract data from token %s" % tokens_data) - return None - + raise Exception('Not a valid token')