mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-17 10:02:03 +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 sys
|
||||||
import requests
|
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(ipfs_hash, chain):
|
||||||
def get_tokens(chain):
|
URL = 'https://gateway.ipfs.io/ipfs/%s/%s.json' % (ipfs_hash, chain)
|
||||||
URL = 'https://raw.githubusercontent.com/kvhnuke/etherwallet/mercury/app/scripts/tokens/%sTokens.json' % chain
|
|
||||||
r = requests.get(URL)
|
r = requests.get(URL)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
def print_tokens(chain, chain_id, python=False):
|
def print_tokens(ipfs_hash, chain, chain_id, python=False):
|
||||||
tokens = get_tokens(chain)
|
tokens = get_tokens(ipfs_hash, chain)
|
||||||
if len(tokens) > 0:
|
if len(tokens) > 0:
|
||||||
if python:
|
if python:
|
||||||
print(' # %s' % chain)
|
print(' # %s' % chain)
|
||||||
else:
|
else:
|
||||||
print('\t// %s' % chain)
|
print('\t// %s' % chain)
|
||||||
for t in sorted(tokens, key=lambda x: x['symbol'].upper()):
|
for t in sorted(tokens, key=lambda x: x['symbol'].upper()):
|
||||||
address, symbol, decimal = t['address'], t['symbol'], int(t['decimal'])
|
address, name, symbol, decimal = t['address'], t['name'], t['symbol'], int(t['decimals'])
|
||||||
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()
|
address = '\\x'.join([address[i:i + 2] for i in range(0, len(address), 2)])[2:].lower()
|
||||||
if python:
|
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:
|
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)
|
return len(tokens)
|
||||||
|
|
||||||
|
|
||||||
|
# disabled are networks with no tokens defined in ethereum-lists/tokens repo
|
||||||
|
|
||||||
networks = [
|
networks = [
|
||||||
('eth', 1),
|
('eth', 1),
|
||||||
('exp', 2),
|
# ('exp', 2),
|
||||||
('ropsten', 3),
|
# ('rop', 3),
|
||||||
('rinkeby', 4),
|
('rin', 4),
|
||||||
('ubq', 8),
|
('ubq', 8),
|
||||||
('rsk', 30),
|
# ('rsk', 30),
|
||||||
('kovan', 42),
|
('kov', 42),
|
||||||
('etc', 61),
|
('etc', 61),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def generate_c():
|
def generate_c(ipfs_hash):
|
||||||
count = 0
|
count = 0
|
||||||
for s, i in networks:
|
for s, i in networks:
|
||||||
count += print_tokens(s, i)
|
count += print_tokens(ipfs_hash, s, i)
|
||||||
print('-' * 32)
|
print('-' * 32)
|
||||||
print('#define TOKENS_COUNT %d' % count)
|
print('#define TOKENS_COUNT %d' % count)
|
||||||
|
|
||||||
|
|
||||||
def generate_python():
|
def generate_python(ipfs_hash):
|
||||||
print('tokens = [')
|
print('tokens = [')
|
||||||
for s, i in networks:
|
for s, i in networks:
|
||||||
print_tokens(s, i, python=True)
|
print_tokens(ipfs_hash, s, i, python=True)
|
||||||
print(']')
|
print(']')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
if len(sys.argv) > 1 and sys.argv[1] == '--python':
|
if __name__ == '__main__':
|
||||||
generate_python()
|
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:
|
else:
|
||||||
generate_c()
|
generate_c(ipfs_hash)
|
||||||
|
Loading…
Reference in New Issue
Block a user