mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-27 01:48:17 +00:00
tokens: rewrite generator to use ethereum-lists/tokens repo as source
This commit is contained in:
parent
b9f2a1c27f
commit
389c895a71
@ -2,75 +2,66 @@
|
||||
import sys
|
||||
import requests
|
||||
|
||||
subst = {
|
||||
(1, 'AVA \U0001F434'): 'AVA',
|
||||
(1, 'BeerCoin \U0001F37A '): 'BEER',
|
||||
(1, 'CryptoCarbon'): 'CCRB',
|
||||
(1, 'DGX 1.0'): 'DGX1',
|
||||
(1, 'JetCoins'): 'JTC',
|
||||
(1, 'Unicorn \U0001F984'): 'UNCRN',
|
||||
(1, '\U00002600\U0000FE0F PLASMA'): 'PLASMA',
|
||||
(3, '\U0001F4A5 PLASMA'): 'PLASMA',
|
||||
(4, '\U0000263C PLASMA'): 'PLASMA',
|
||||
(42, '\U0001F4A5 PLASMA'): 'PLASMA',
|
||||
}
|
||||
|
||||
|
||||
def get_tokens(chain):
|
||||
URL = 'https://raw.githubusercontent.com/kvhnuke/etherwallet/mercury/app/scripts/tokens/%sTokens.json' % chain
|
||||
def get_tokens(ipfs_hash, chain):
|
||||
URL = 'https://gateway.ipfs.io/ipfs/%s/%s.json' % (ipfs_hash, chain)
|
||||
r = requests.get(URL)
|
||||
return r.json()
|
||||
|
||||
|
||||
def print_tokens(chain, chain_id, python=False):
|
||||
tokens = get_tokens(chain)
|
||||
def print_tokens(ipfs_hash, chain, chain_id, python=False):
|
||||
tokens = get_tokens(ipfs_hash, chain)
|
||||
if len(tokens) > 0:
|
||||
if python:
|
||||
print(' # %s' % chain)
|
||||
else:
|
||||
print('\t// %s' % chain)
|
||||
for t in sorted(tokens, key=lambda x: x['symbol'].upper()):
|
||||
address, symbol, decimal = t['address'], t['symbol'], int(t['decimal'])
|
||||
s = (chain_id, symbol)
|
||||
if s in subst:
|
||||
symbol = subst[s]
|
||||
address, name, symbol, decimal = t['address'], t['name'], t['symbol'], int(t['decimals'])
|
||||
address = '\\x'.join([address[i:i + 2] for i in range(0, len(address), 2)])[2:].lower()
|
||||
if python:
|
||||
print(" {'chain_id': %2d, 'address': b'%s', 'symbol': '%s', 'decimal': %d}," % (chain_id, address, symbol, decimal))
|
||||
print(" {'chain_id': %2d, 'address': b'%s', 'symbol': '%s', 'decimal': %d}, # %s " % (chain_id, address, symbol, decimal, name))
|
||||
else:
|
||||
print('\t{%2d, "%s", " %s", %d},' % (chain_id, address, symbol, decimal))
|
||||
print('\t{%2d, "%s", " %s", %d}, // %s ' % (chain_id, address, symbol, decimal, name))
|
||||
|
||||
return len(tokens)
|
||||
|
||||
|
||||
# disabled are networks with no tokens defined in ethereum-lists/tokens repo
|
||||
|
||||
networks = [
|
||||
('eth', 1),
|
||||
('exp', 2),
|
||||
('ropsten', 3),
|
||||
('rinkeby', 4),
|
||||
# ('exp', 2),
|
||||
# ('rop', 3),
|
||||
('rin', 4),
|
||||
('ubq', 8),
|
||||
('rsk', 30),
|
||||
('kovan', 42),
|
||||
# ('rsk', 30),
|
||||
('kov', 42),
|
||||
('etc', 61),
|
||||
]
|
||||
|
||||
|
||||
def generate_c():
|
||||
def generate_c(ipfs_hash):
|
||||
count = 0
|
||||
for s, i in networks:
|
||||
count += print_tokens(s, i)
|
||||
count += print_tokens(ipfs_hash, s, i)
|
||||
print('-' * 32)
|
||||
print('#define TOKENS_COUNT %d' % count)
|
||||
|
||||
|
||||
def generate_python():
|
||||
def generate_python(ipfs_hash):
|
||||
print('tokens = [')
|
||||
for s, i in networks:
|
||||
print_tokens(s, i, python=True)
|
||||
print_tokens(ipfs_hash, s, i, python=True)
|
||||
print(']')
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) > 1 and sys.argv[1] == '--python':
|
||||
generate_python()
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) < 2:
|
||||
print('Usage: ethereum_tokens-gen.py ipfs_hash [--python]')
|
||||
sys.exit(1)
|
||||
ipfs_hash = sys.argv[1]
|
||||
if len(sys.argv) > 2 and sys.argv[2] == '--python':
|
||||
generate_python(ipfs_hash)
|
||||
else:
|
||||
generate_c()
|
||||
generate_c(ipfs_hash)
|
||||
|
Loading…
Reference in New Issue
Block a user