mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-28 15:22:14 +00:00
Updated scraping of ethereum based tokens
This commit is contained in:
parent
30fa1f9c6b
commit
564af04dd6
@ -4,6 +4,7 @@ import time
|
|||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
import pprint
|
import pprint
|
||||||
|
import ethereum_tokens_gen
|
||||||
|
|
||||||
COINS = {}
|
COINS = {}
|
||||||
|
|
||||||
@ -52,7 +53,6 @@ def update_marketcap(obj, shortcut):
|
|||||||
try:
|
try:
|
||||||
obj['marketcap_usd'] = int(float(coinmarketcap_info(shortcut)['quotes']['USD']['market_cap']))
|
obj['marketcap_usd'] = int(float(coinmarketcap_info(shortcut)['quotes']['USD']['market_cap']))
|
||||||
except:
|
except:
|
||||||
del obj['marketcap_usd']
|
|
||||||
print("Marketcap info not found for", shortcut)
|
print("Marketcap info not found for", shortcut)
|
||||||
|
|
||||||
def coinmarketcap_global():
|
def coinmarketcap_global():
|
||||||
@ -111,66 +111,44 @@ def update_coins(details):
|
|||||||
check_unsupported(details, 'coin:', supported)
|
check_unsupported(details, 'coin:', supported)
|
||||||
|
|
||||||
def update_erc20(details):
|
def update_erc20(details):
|
||||||
networks = [
|
networks = ['eth',
|
||||||
('eth', 1),
|
'exp',
|
||||||
# ('exp', 2),
|
# 'rop',
|
||||||
# ('rop', 3),
|
# 'rin',
|
||||||
('rin', 4),
|
'ubq',
|
||||||
('ubq', 8),
|
# 'rsk',
|
||||||
# ('rsk', 30),
|
# 'kov',
|
||||||
('kov', 42),
|
'etc',
|
||||||
('etc', 61),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# Fetch list of tokens already included in Trezor Core
|
tokens = ethereum_tokens_gen.get_tokens()
|
||||||
r = requests.get('https://raw.githubusercontent.com/trezor/trezor-core/master/src/apps/ethereum/tokens.py')
|
|
||||||
d = {}
|
|
||||||
exec(r.text, d)
|
|
||||||
|
|
||||||
# TODO 'Qmede...' can be removed after ipfs_hash is being generated into tokens.py
|
|
||||||
ipfs_hash = d.get('ipfs_hash') or 'QmedefcF1fecLVpRymJJmyJFRpJuCTiNfPYBhzUdHPUq3T'
|
|
||||||
|
|
||||||
infos = {}
|
|
||||||
for n in networks:
|
|
||||||
# print("Updating info about erc20 tokens for", n[0])
|
|
||||||
url = 'https://gateway.ipfs.io/ipfs/%s/%s.json' % (ipfs_hash, n[0])
|
|
||||||
r = requests.get(url)
|
|
||||||
infos[n[0]] = r.json()
|
|
||||||
|
|
||||||
supported = []
|
supported = []
|
||||||
for t in d['tokens']:
|
for t in tokens:
|
||||||
token = t[2]
|
print('Updating', t['symbol'])
|
||||||
# print('Updating', token)
|
|
||||||
|
|
||||||
try:
|
if t['chain'] not in networks:
|
||||||
network = [ n[0] for n in networks if n[1] == t[0] ][0]
|
print('Skipping, %s is disabled' % t['chain'])
|
||||||
except:
|
continue
|
||||||
raise Exception("Unknown network", t[0], "for erc20 token", token)
|
|
||||||
|
|
||||||
try:
|
key = "erc20:%s:%s" % (t['chain'], t['symbol'])
|
||||||
info = [ i for i in infos[network] if i['symbol'] == token ][0]
|
|
||||||
except:
|
|
||||||
raise Exception("Unknown details for erc20 token", token)
|
|
||||||
|
|
||||||
key = "erc20:%s:%s" % (network, token)
|
|
||||||
supported.append(key)
|
supported.append(key)
|
||||||
out = details['coins'].setdefault(key, {})
|
out = details['coins'].setdefault(key, {})
|
||||||
out['type'] = 'erc20'
|
out['type'] = 'erc20'
|
||||||
out['network'] = network
|
out['network'] = t['chain']
|
||||||
out['address'] = info['address']
|
out['address'] = t['address']
|
||||||
|
|
||||||
set_default(out, 'shortcut', token)
|
set_default(out, 'shortcut', t['symbol'])
|
||||||
set_default(out, 'name', info['name'])
|
set_default(out, 'name', t['name'])
|
||||||
set_default(out, 't1_enabled', 'yes')
|
set_default(out, 't1_enabled', 'yes')
|
||||||
set_default(out, 't2_enabled', 'yes')
|
set_default(out, 't2_enabled', 'yes')
|
||||||
set_default(out, 'links', {})
|
set_default(out, 'links', {})
|
||||||
|
|
||||||
if info['website']:
|
if t['website']:
|
||||||
out['links']['Homepage'] = info['website']
|
out['links']['Homepage'] = t['website']
|
||||||
if info.get('social', {}).get('github', None):
|
if t.get('social', {}).get('github', None):
|
||||||
out['links']['Github'] = info['social']['github']
|
out['links']['Github'] = t['social']['github']
|
||||||
|
|
||||||
update_marketcap(out, out.get('coinmarketcap_alias', token))
|
update_marketcap(out, out.get('coinmarketcap_alias', t['symbol']))
|
||||||
|
|
||||||
check_unsupported(details, 'erc20:', supported)
|
check_unsupported(details, 'erc20:', supported)
|
||||||
|
|
||||||
@ -274,7 +252,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
coinmarketcap_init()
|
coinmarketcap_init()
|
||||||
update_coins(details)
|
update_coins(details)
|
||||||
#update_erc20(details)
|
update_erc20(details)
|
||||||
update_ethereum(details)
|
update_ethereum(details)
|
||||||
update_mosaics(details)
|
update_mosaics(details)
|
||||||
update_info(details)
|
update_info(details)
|
||||||
|
@ -12,6 +12,10 @@ def get_tokens():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
for f in files:
|
for f in files:
|
||||||
|
if not f.path.endswith('.json'):
|
||||||
|
continue
|
||||||
|
|
||||||
|
print('Processing', f.path)
|
||||||
data = json.load(open(f.path, 'r'))
|
data = json.load(open(f.path, 'r'))
|
||||||
data['chain'] = s
|
data['chain'] = s
|
||||||
data['chain_id'] = i
|
data['chain_id'] = i
|
||||||
|
Loading…
Reference in New Issue
Block a user