1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 04:18:10 +00:00
trezor-firmware/firmware/coins-gen.py

52 lines
2.0 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import json
coins = json.load(open('../vendor/trezor-common/coins.json', 'r'))
fields = []
for c in coins:
2017-07-30 21:17:44 +00:00
if c['firmware']:
fields.append([
'true' if c['coin_name'] is not None else 'false',
'"%s"' % c['coin_name'] if c['coin_name'] is not None else 'NULL',
2017-07-30 21:17:44 +00:00
'true' if c['coin_shortcut'] is not None else 'false',
'" %s"' % c['coin_shortcut'] if c['coin_shortcut'] is not None else 'NULL',
2017-07-30 21:17:44 +00:00
'true' if c['address_type'] is not None else 'false',
'%d' % c['address_type'] if c['address_type'] is not None else '0',
2017-07-30 21:17:44 +00:00
'true' if c['maxfee_kb'] is not None else 'false',
'%d' % c['maxfee_kb'] if c['maxfee_kb'] is not None else '0',
2017-07-30 21:17:44 +00:00
'true' if c['address_type_p2sh'] is not None else 'false',
'%d' % c['address_type_p2sh'] if c['address_type_p2sh'] is not None else '0',
2017-07-30 21:17:44 +00:00
'true' if c['signed_message_header'] is not None else 'false',
'"\\x%02x" "%s"' % (len(c['signed_message_header']), c['signed_message_header'].replace('\n', '\\n')) if c['signed_message_header'] is not None else 'NULL',
2017-07-30 21:17:44 +00:00
'true' if c['xpub_magic'] is not None else 'false',
'0x%s' % c['xpub_magic'] if c['xpub_magic'] is not None else '00000000',
2017-07-30 21:17:44 +00:00
'true' if c['xprv_magic'] is not None else 'false',
'0x%s' % c['xprv_magic'] if c['xprv_magic'] is not None else '00000000',
2017-07-30 21:17:44 +00:00
'true' if c['segwit'] is not None else 'false',
'true' if c['segwit'] else 'false',
2017-07-25 14:23:10 +00:00
2017-07-30 21:17:44 +00:00
'true' if c['forkid'] is not None else 'false',
'%d' % c['forkid'] if c['forkid'] else '0'
])
for j in range(len(fields[0])):
l = max([len(x[j]) for x in fields]) + 1
for i in range(len(fields)):
if fields[i][j][0] in '0123456789':
fields[i][j] = (fields[i][j] + ',').rjust(l)
else:
fields[i][j] = (fields[i][j] + ',').ljust(l)
for row in fields:
print('\t{' + ' '.join(row) + ' },')