fixing invalid token problems

Token where the smartcontract was destroyed have invalid balance
  breaking dbt tranformation.

Signed-off-by: Alexis Pentori <alexis@status.im>
This commit is contained in:
Alexis Pentori 2023-11-30 18:01:15 +01:00
parent 967db04e30
commit 8444b3e731
No known key found for this signature in database
GPG Key ID: 65250D2801E47A10
3 changed files with 12 additions and 9 deletions

View File

@ -35,13 +35,13 @@
"balance": {
"type": [
"null",
"numeric"
"number"
]
},
"decimal": {
"type": [
"null",
"integer"
"number"
]
}
}

View File

@ -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]:

View File

@ -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')