2017-12-18 17:34:11 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
|
|
import requests
|
|
|
|
|
|
|
|
|
2018-02-16 21:46:57 +00:00
|
|
|
def get_tokens(ipfs_hash, chain):
|
|
|
|
URL = 'https://gateway.ipfs.io/ipfs/%s/%s.json' % (ipfs_hash, chain)
|
2017-12-18 17:34:11 +00:00
|
|
|
r = requests.get(URL)
|
|
|
|
return r.json()
|
|
|
|
|
|
|
|
|
2018-02-16 21:46:57 +00:00
|
|
|
def print_tokens(ipfs_hash, chain, chain_id, python=False):
|
|
|
|
tokens = get_tokens(ipfs_hash, chain)
|
2017-12-18 17:34:11 +00:00
|
|
|
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()):
|
2018-02-16 21:46:57 +00:00
|
|
|
address, name, symbol, decimal = t['address'], t['name'], t['symbol'], int(t['decimals'])
|
2017-12-18 17:34:11 +00:00
|
|
|
address = '\\x'.join([address[i:i + 2] for i in range(0, len(address), 2)])[2:].lower()
|
|
|
|
if python:
|
2018-02-28 21:47:59 +00:00
|
|
|
print(" (%d, b'%s', '%s', %d), # %s" % (chain_id, address, symbol, decimal, name))
|
2017-12-18 17:34:11 +00:00
|
|
|
else:
|
2018-02-28 21:47:59 +00:00
|
|
|
print('\t{%2d, "%s", " %s", %d}, // %s' % (chain_id, address, symbol, decimal, name))
|
2017-12-18 17:34:11 +00:00
|
|
|
|
|
|
|
return len(tokens)
|
|
|
|
|
|
|
|
|
2018-02-16 21:46:57 +00:00
|
|
|
# disabled are networks with no tokens defined in ethereum-lists/tokens repo
|
|
|
|
|
2017-12-18 17:34:11 +00:00
|
|
|
networks = [
|
|
|
|
('eth', 1),
|
2018-02-16 21:46:57 +00:00
|
|
|
# ('exp', 2),
|
|
|
|
# ('rop', 3),
|
|
|
|
('rin', 4),
|
2017-12-18 17:34:11 +00:00
|
|
|
('ubq', 8),
|
2018-02-16 21:46:57 +00:00
|
|
|
# ('rsk', 30),
|
|
|
|
('kov', 42),
|
2017-12-18 17:34:11 +00:00
|
|
|
('etc', 61),
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2018-02-16 21:46:57 +00:00
|
|
|
def generate_c(ipfs_hash):
|
2017-12-18 17:34:11 +00:00
|
|
|
count = 0
|
|
|
|
for s, i in networks:
|
2018-02-16 21:46:57 +00:00
|
|
|
count += print_tokens(ipfs_hash, s, i)
|
2017-12-18 17:34:11 +00:00
|
|
|
print('-' * 32)
|
|
|
|
print('#define TOKENS_COUNT %d' % count)
|
|
|
|
|
|
|
|
|
2018-02-16 21:46:57 +00:00
|
|
|
def generate_python(ipfs_hash):
|
2018-04-06 20:48:32 +00:00
|
|
|
print('ipfs_hash = "%s"' % ipfs_hash)
|
2017-12-18 17:34:11 +00:00
|
|
|
print('tokens = [')
|
|
|
|
for s, i in networks:
|
2018-02-16 21:46:57 +00:00
|
|
|
print_tokens(ipfs_hash, s, i, python=True)
|
2017-12-18 17:34:11 +00:00
|
|
|
print(']')
|
|
|
|
|
2018-02-16 21:46:57 +00:00
|
|
|
|
|
|
|
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)
|
2017-12-18 17:34:11 +00:00
|
|
|
else:
|
2018-02-16 21:46:57 +00:00
|
|
|
generate_c(ipfs_hash)
|