diff --git a/tools/coins_details.py b/tools/coins_details.py index 841b5f9589..c481b65251 100755 --- a/tools/coins_details.py +++ b/tools/coins_details.py @@ -3,12 +3,12 @@ import time import json import requests -import pprint import ethereum_tokens_gen import build_coins COINS = {} + def coinmarketcap_init(): global COINS @@ -44,11 +44,12 @@ def coinmarketcap_info(shortcut): for _id in COINS: coin = COINS[_id] - #print(shortcut, coin['website_slug']) + # print(shortcut, coin['website_slug']) if shortcut == coin['website_slug']: - #print(coin) + # print(coin) return coin + def update_marketcap(obj, shortcut): try: obj['marketcap_usd'] = int(float(coinmarketcap_info(shortcut)['quotes']['USD']['market_cap'])) @@ -56,15 +57,18 @@ def update_marketcap(obj, shortcut): pass # print("Marketcap info not found for", shortcut) + def coinmarketcap_global(): url = 'https://api.coinmarketcap.com/v2/global' ret = requests.get(url) data = ret.json() return data + def set_default(obj, key, default_value): obj[key] = obj.setdefault(key, default_value) + def update_info(details): details['info']['updated_at'] = int(time.time()) details['info']['updated_at_readable'] = time.asctime() @@ -83,6 +87,7 @@ def update_info(details): marketcap += details['coins'][k].setdefault('marketcap_usd', 0) details['info']['marketcap_usd'] = marketcap + def check_unsupported(details, prefix, supported): for k in details['coins'].keys(): if not k.startswith(prefix): @@ -90,6 +95,7 @@ def check_unsupported(details, prefix, supported): if k not in supported: print("%s not supported by Trezor? (Possible manual entry)" % k) + def update_coins(details): (coins, _) = build_coins.process(None) firmware = json.load(open('../defs/support.json', 'r')) @@ -116,16 +122,9 @@ def update_coins(details): check_unsupported(details, 'coin:', supported) + def update_erc20(details): - networks = ['eth', - 'exp', - # 'rop', - # 'rin', - 'ubq', - # 'rsk', - # 'kov', - 'etc', - ] + networks = [x[0] for x in ethereum_tokens_gen.networks] LATEST_T1 = 'https://raw.githubusercontent.com/trezor/trezor-mcu/v1.6.1/firmware/ethereum_tokens.c' LATEST_T2 = 'https://raw.githubusercontent.com/trezor/trezor-core/v2.0.6/src/apps/ethereum/tokens.py' @@ -175,6 +174,7 @@ def update_erc20(details): check_unsupported(details, 'erc20:', supported) + def update_ethereum(details): out = details['coins'].setdefault('coin2:ETH', {}) out['type'] = 'coin' @@ -248,6 +248,7 @@ def update_ethereum(details): set_default(out, 't2_enabled', 'yes') update_marketcap(out, 'eosc') + def update_mosaics(details): d = json.load(open('../defs/nem/nem_mosaics.json')) supported = [] @@ -267,6 +268,7 @@ def update_mosaics(details): check_unsupported(details, 'mosaic:', supported) + def check_missing_details(details): for k in details['coins'].keys(): coin = details['coins'][k] @@ -288,7 +290,7 @@ def check_missing_details(details): print("%s: Strange URL for Trezor Wallet" % k) hide = True - for w in [ x.lower() for x in coin.get('links', {}).keys() ]: + for w in [x.lower() for x in coin.get('links', {}).keys()]: if 'wallet' in w or 'electrum' in w: break else: @@ -312,6 +314,7 @@ def check_missing_details(details): if details['coins'][k].get('hidden') == 1: print("%s: Coin is hidden" % k) + if __name__ == '__main__': try: details = json.load(open('../defs/coins_details.json', 'r')) diff --git a/tools/ethereum_tokens_gen.py b/tools/ethereum_tokens_gen.py index 5a288a8493..0021d5d31f 100755 --- a/tools/ethereum_tokens_gen.py +++ b/tools/ethereum_tokens_gen.py @@ -2,6 +2,8 @@ import sys import os import json +import re + def get_tokens(): tokens = [] @@ -25,28 +27,31 @@ def get_tokens(): def print_tokens(tokens, python=False): + count = 0 for t in sorted(tokens, key=lambda x: x['chain'] + x['symbol'].upper()): - address, name, symbol, decimal, chain, chain_id = t['address'], t['name'], t['symbol'], int(t['decimals']), t['chain'], t['chain_id'] - address = '\\x'.join([address[i:i + 2] for i in range(0, len(address), 2)])[2:].lower() + address, name, symbol, decimal, chain, chain_id = t['address'], t['name'], t['symbol'], int(t['decimals']), t['chain'], t['chain_id'] # noqa:E501 + address = '\\x'.join([address[i:i + 2] for i in range(0, len(address), 2)])[2:].lower() # noqa:E501 + ascii_only = re.match(r'^[ -\x7F]+$', symbol) is not None + if not ascii_only: # skip Unicode symbols, they are stupid + continue + count += 1 if python: - print(" (%d, b'%s', '%s', %d), # %s / %s" % (chain_id, address, symbol, decimal, chain, name)) + print(" (%d, b'%s', '%s', %d), # %s / %s" % (chain_id, address, symbol, decimal, chain, name)) # noqa:E501 else: - print('\t{%2d, "%s", " %s", %d}, // %s / %s' % (chain_id, address, symbol, decimal, chain, name)) - - return len(tokens) + print('\t{%2d, "%s", " %s", %d}, // %s / %s' % (chain_id, address, symbol, decimal, chain, name)) # noqa:E501 + return count # disabled are networks with no tokens defined in ethereum-lists/tokens repo networks = [ - ('eth', 1), - ('exp', 2), - # ('rop', 3), - # ('rin', 4), - ('ubq', 8), - # ('rsk', 30), - # ('kov', 42), + ('ella', 64), ('etc', 61), + ('eth', 1), + ('kov', 42), + ('rin', 4), + ('rop', 3), + ('ubq', 8), ]