mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-06-23 16:38:46 +00:00
tools: small nitpicks, fix flake8 warnings
This commit is contained in:
parent
c61a933650
commit
a18de043b0
@ -3,12 +3,12 @@
|
|||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
import pprint
|
|
||||||
import ethereum_tokens_gen
|
import ethereum_tokens_gen
|
||||||
import build_coins
|
import build_coins
|
||||||
|
|
||||||
COINS = {}
|
COINS = {}
|
||||||
|
|
||||||
|
|
||||||
def coinmarketcap_init():
|
def coinmarketcap_init():
|
||||||
global COINS
|
global COINS
|
||||||
|
|
||||||
@ -44,11 +44,12 @@ def coinmarketcap_info(shortcut):
|
|||||||
|
|
||||||
for _id in COINS:
|
for _id in COINS:
|
||||||
coin = COINS[_id]
|
coin = COINS[_id]
|
||||||
#print(shortcut, coin['website_slug'])
|
# print(shortcut, coin['website_slug'])
|
||||||
if shortcut == coin['website_slug']:
|
if shortcut == coin['website_slug']:
|
||||||
#print(coin)
|
# print(coin)
|
||||||
return coin
|
return coin
|
||||||
|
|
||||||
|
|
||||||
def update_marketcap(obj, shortcut):
|
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']))
|
||||||
@ -56,15 +57,18 @@ def update_marketcap(obj, shortcut):
|
|||||||
pass
|
pass
|
||||||
# print("Marketcap info not found for", shortcut)
|
# print("Marketcap info not found for", shortcut)
|
||||||
|
|
||||||
|
|
||||||
def coinmarketcap_global():
|
def coinmarketcap_global():
|
||||||
url = 'https://api.coinmarketcap.com/v2/global'
|
url = 'https://api.coinmarketcap.com/v2/global'
|
||||||
ret = requests.get(url)
|
ret = requests.get(url)
|
||||||
data = ret.json()
|
data = ret.json()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def set_default(obj, key, default_value):
|
def set_default(obj, key, default_value):
|
||||||
obj[key] = obj.setdefault(key, default_value)
|
obj[key] = obj.setdefault(key, default_value)
|
||||||
|
|
||||||
|
|
||||||
def update_info(details):
|
def update_info(details):
|
||||||
details['info']['updated_at'] = int(time.time())
|
details['info']['updated_at'] = int(time.time())
|
||||||
details['info']['updated_at_readable'] = time.asctime()
|
details['info']['updated_at_readable'] = time.asctime()
|
||||||
@ -83,6 +87,7 @@ def update_info(details):
|
|||||||
marketcap += details['coins'][k].setdefault('marketcap_usd', 0)
|
marketcap += details['coins'][k].setdefault('marketcap_usd', 0)
|
||||||
details['info']['marketcap_usd'] = marketcap
|
details['info']['marketcap_usd'] = marketcap
|
||||||
|
|
||||||
|
|
||||||
def check_unsupported(details, prefix, supported):
|
def check_unsupported(details, prefix, supported):
|
||||||
for k in details['coins'].keys():
|
for k in details['coins'].keys():
|
||||||
if not k.startswith(prefix):
|
if not k.startswith(prefix):
|
||||||
@ -90,6 +95,7 @@ def check_unsupported(details, prefix, supported):
|
|||||||
if k not in supported:
|
if k not in supported:
|
||||||
print("%s not supported by Trezor? (Possible manual entry)" % k)
|
print("%s not supported by Trezor? (Possible manual entry)" % k)
|
||||||
|
|
||||||
|
|
||||||
def update_coins(details):
|
def update_coins(details):
|
||||||
(coins, _) = build_coins.process(None)
|
(coins, _) = build_coins.process(None)
|
||||||
firmware = json.load(open('../defs/support.json', 'r'))
|
firmware = json.load(open('../defs/support.json', 'r'))
|
||||||
@ -116,16 +122,9 @@ def update_coins(details):
|
|||||||
|
|
||||||
check_unsupported(details, 'coin:', supported)
|
check_unsupported(details, 'coin:', supported)
|
||||||
|
|
||||||
|
|
||||||
def update_erc20(details):
|
def update_erc20(details):
|
||||||
networks = ['eth',
|
networks = [x[0] for x in ethereum_tokens_gen.networks]
|
||||||
'exp',
|
|
||||||
# 'rop',
|
|
||||||
# 'rin',
|
|
||||||
'ubq',
|
|
||||||
# 'rsk',
|
|
||||||
# 'kov',
|
|
||||||
'etc',
|
|
||||||
]
|
|
||||||
|
|
||||||
LATEST_T1 = 'https://raw.githubusercontent.com/trezor/trezor-mcu/v1.6.1/firmware/ethereum_tokens.c'
|
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'
|
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)
|
check_unsupported(details, 'erc20:', supported)
|
||||||
|
|
||||||
|
|
||||||
def update_ethereum(details):
|
def update_ethereum(details):
|
||||||
out = details['coins'].setdefault('coin2:ETH', {})
|
out = details['coins'].setdefault('coin2:ETH', {})
|
||||||
out['type'] = 'coin'
|
out['type'] = 'coin'
|
||||||
@ -248,6 +248,7 @@ def update_ethereum(details):
|
|||||||
set_default(out, 't2_enabled', 'yes')
|
set_default(out, 't2_enabled', 'yes')
|
||||||
update_marketcap(out, 'eosc')
|
update_marketcap(out, 'eosc')
|
||||||
|
|
||||||
|
|
||||||
def update_mosaics(details):
|
def update_mosaics(details):
|
||||||
d = json.load(open('../defs/nem/nem_mosaics.json'))
|
d = json.load(open('../defs/nem/nem_mosaics.json'))
|
||||||
supported = []
|
supported = []
|
||||||
@ -267,6 +268,7 @@ def update_mosaics(details):
|
|||||||
|
|
||||||
check_unsupported(details, 'mosaic:', supported)
|
check_unsupported(details, 'mosaic:', supported)
|
||||||
|
|
||||||
|
|
||||||
def check_missing_details(details):
|
def check_missing_details(details):
|
||||||
for k in details['coins'].keys():
|
for k in details['coins'].keys():
|
||||||
coin = details['coins'][k]
|
coin = details['coins'][k]
|
||||||
@ -288,7 +290,7 @@ def check_missing_details(details):
|
|||||||
print("%s: Strange URL for Trezor Wallet" % k)
|
print("%s: Strange URL for Trezor Wallet" % k)
|
||||||
hide = True
|
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:
|
if 'wallet' in w or 'electrum' in w:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
@ -312,6 +314,7 @@ def check_missing_details(details):
|
|||||||
if details['coins'][k].get('hidden') == 1:
|
if details['coins'][k].get('hidden') == 1:
|
||||||
print("%s: Coin is hidden" % k)
|
print("%s: Coin is hidden" % k)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
try:
|
try:
|
||||||
details = json.load(open('../defs/coins_details.json', 'r'))
|
details = json.load(open('../defs/coins_details.json', 'r'))
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
def get_tokens():
|
def get_tokens():
|
||||||
tokens = []
|
tokens = []
|
||||||
@ -25,28 +27,31 @@ def get_tokens():
|
|||||||
|
|
||||||
|
|
||||||
def print_tokens(tokens, python=False):
|
def print_tokens(tokens, python=False):
|
||||||
|
count = 0
|
||||||
for t in sorted(tokens, key=lambda x: x['chain'] + x['symbol'].upper()):
|
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, 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()
|
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:
|
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:
|
else:
|
||||||
print('\t{%2d, "%s", " %s", %d}, // %s / %s' % (chain_id, address, symbol, decimal, chain, name))
|
print('\t{%2d, "%s", " %s", %d}, // %s / %s' % (chain_id, address, symbol, decimal, chain, name)) # noqa:E501
|
||||||
|
return count
|
||||||
return len(tokens)
|
|
||||||
|
|
||||||
|
|
||||||
# disabled are networks with no tokens defined in ethereum-lists/tokens repo
|
# disabled are networks with no tokens defined in ethereum-lists/tokens repo
|
||||||
|
|
||||||
networks = [
|
networks = [
|
||||||
('eth', 1),
|
('ella', 64),
|
||||||
('exp', 2),
|
|
||||||
# ('rop', 3),
|
|
||||||
# ('rin', 4),
|
|
||||||
('ubq', 8),
|
|
||||||
# ('rsk', 30),
|
|
||||||
# ('kov', 42),
|
|
||||||
('etc', 61),
|
('etc', 61),
|
||||||
|
('eth', 1),
|
||||||
|
('kov', 42),
|
||||||
|
('rin', 4),
|
||||||
|
('rop', 3),
|
||||||
|
('ubq', 8),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user