1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-24 07:18:09 +00:00
trezor-firmware/firmware/ethereum_tokens-gen.py

42 lines
1.0 KiB
Python
Raw Normal View History

2017-05-16 12:00:55 +00:00
#!/usr/bin/env python3
import requests
2017-05-19 12:25:58 +00:00
subst = {
(1, 'AVA \U0001F434'): 'AVA',
(1, 'BeerCoin \U0001F37A '): 'BEER',
(1, 'CryptoCarbon'): 'CCRB',
(1, 'DGX 1.0'): 'DGX1',
(1, 'JetCoins'): 'JTC',
(1, 'Unicorn \U0001F984 '): 'UNCRN',
2017-05-19 12:25:58 +00:00
}
2017-05-19 12:25:58 +00:00
def get_tokens(chain):
URL = 'https://raw.githubusercontent.com/kvhnuke/etherwallet/mercury/app/scripts/tokens/%sTokens.json' % chain
2017-05-16 12:00:55 +00:00
r = requests.get(URL)
return r.json()
2017-05-19 12:25:58 +00:00
def print_tokens(chain, chain_id):
tokens = get_tokens(chain)
2017-05-16 12:00:55 +00:00
2017-07-03 11:13:07 +00:00
for t in sorted(tokens, key=lambda x: x['symbol'].upper()):
2017-05-19 12:25:58 +00:00
address, symbol, decimal = t['address'], t['symbol'], t['decimal']
s = (chain_id, symbol)
if s in subst:
symbol = subst[s]
address = '\\x'.join([address[i:i + 2] for i in range(0, len(address), 2)])[2:].lower()
print('\t{%2d, "%s", " %s", %d},' % (chain_id, address, symbol, decimal))
2017-05-16 12:00:55 +00:00
2017-06-27 11:51:45 +00:00
return len(tokens)
2017-06-27 11:51:45 +00:00
count = 0
count += print_tokens('eth', 1)
count += print_tokens('etc', 61)
print('-' * 32)
2017-06-27 11:51:45 +00:00
print('#define TOKENS_COUNT %d' % count)