Skip to content

Commit

Permalink
Catch all exceptions to avoid non ERC20 token errors when pulling exc…
Browse files Browse the repository at this point in the history
…hange data
  • Loading branch information
conlan committed Dec 25, 2018
1 parent 2c41ceb commit f23a05f
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions tools/pull_exchanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
raw_exchanges = {}
sorted_exchanges = {} #python 3.7 preserves key insertion order into objects

print("Pulling exchange details...");
print("Pulling exchange details into " + fname);

with open(fname) as json_file:
data = json.load(json_file)
Expand All @@ -52,27 +52,30 @@
continue;

try:
symbol = erc20.functions.symbol().call();
except OverflowError:
#print("Overflow... trying DSToken ABI");

#some tokens specify their symbol as bytes32 instead of string
erc20 = w3.eth.contract(address=token, abi=DSTOKEN_ABI)

symbol = erc20.functions.symbol().call();
symbol = symbol.hex().rstrip("0")

if (len(symbol) % 2 != 0):
symbol = symbol + '0'
symbol = bytes.fromhex(symbol).decode('utf8')
try:
symbol = erc20.functions.symbol().call();
except OverflowError:
#print("Overflow... trying DSToken ABI");

#some tokens specify their symbol as bytes32 instead of string
erc20 = w3.eth.contract(address=token, abi=DSTOKEN_ABI)

symbol = erc20.functions.symbol().call();
symbol = symbol.hex().rstrip("0")

if (len(symbol) % 2 != 0):
symbol = symbol + '0'
symbol = bytes.fromhex(symbol).decode('utf8')

raw_exchanges[symbol] = {
"address" : exchange,
"tokenAddress" : token,
"decimals" : decimals
}
except Exception as e:
print("Unexpected exception! Skipping... " + str(e));

# print(str(token) + "\n" + str(exchange) + "\n" + str(symbol) + "\n" + str(decimals));

raw_exchanges[symbol] = {
"address" : exchange,
"tokenAddress" : token,
"decimals" : decimals
}

print() #newline

Expand Down

0 comments on commit f23a05f

Please sign in to comment.