2017-09-30 09:09:11 +00:00
|
|
|
#!/usr/bin/env python2
|
|
|
|
from __future__ import print_function
|
|
|
|
import json, sys
|
2016-10-20 13:27:34 +00:00
|
|
|
|
2017-09-30 09:09:11 +00:00
|
|
|
coins_json = json.load(open('coins.json', 'r'))
|
2016-10-20 13:27:34 +00:00
|
|
|
|
2017-08-13 19:11:23 +00:00
|
|
|
coins_stable, coins_debug = [], []
|
2016-10-20 13:27:34 +00:00
|
|
|
|
2017-09-30 09:09:11 +00:00
|
|
|
if len(sys.argv) != 2 or sys.argv[1] not in ("count", "array"):
|
|
|
|
print("usage: coins-gen.py [count|array]\n", file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2016-10-20 13:27:34 +00:00
|
|
|
|
2017-08-13 19:11:23 +00:00
|
|
|
def get_fields(coin):
|
|
|
|
return [
|
|
|
|
'"%s"' % coin['coin_name'] if coin['coin_name'] is not None else 'NULL',
|
|
|
|
'" %s"' % coin['coin_shortcut'] if coin['coin_shortcut'] is not None else 'NULL',
|
|
|
|
'%d' % coin['maxfee_kb'] if coin['maxfee_kb'] is not None else '0',
|
2017-10-30 21:13:09 +00:00
|
|
|
'"\\x%02x" "%s"' % (len(coin['signed_message_header']), coin['signed_message_header'].replace('\n', '\\n')) if coin['signed_message_header'] is not None else 'NULL',
|
|
|
|
'true' if coin['address_type'] is not None else 'false',
|
2017-08-13 19:11:23 +00:00
|
|
|
'true' if coin['address_type_p2sh'] is not None else 'false',
|
2017-10-30 21:13:09 +00:00
|
|
|
'true' if coin['segwit'] else 'false',
|
|
|
|
'true' if coin['forkid'] is not None else 'false',
|
2017-10-31 20:55:15 +00:00
|
|
|
'true' if coin['force_bip143'] else 'false',
|
2017-10-30 21:13:09 +00:00
|
|
|
'%d' % coin['address_type'] if coin['address_type'] is not None else '0',
|
2017-08-13 19:11:23 +00:00
|
|
|
'%d' % coin['address_type_p2sh'] if coin['address_type_p2sh'] is not None else '0',
|
2017-09-08 13:29:55 +00:00
|
|
|
'0x%s' % coin['xpub_magic'] if coin['xpub_magic'] is not None else '0x00000000',
|
|
|
|
'0x%s' % coin['xprv_magic'] if coin['xprv_magic'] is not None else '0x00000000',
|
|
|
|
'%d' % coin['forkid'] if coin['forkid'] else '0',
|
2017-11-16 17:34:50 +00:00
|
|
|
'"%s"' % coin['bech32_prefix'] if coin.get('bech32_prefix') is not None else 'NULL',
|
|
|
|
'0x%08x' % (0x80000000 + coin['bip44']),
|
2017-12-09 18:35:37 +00:00
|
|
|
'%s_NAME' % 'secp256k1'.upper(),
|
2017-12-09 18:28:53 +00:00
|
|
|
'&%s_info' % 'secp256k1',
|
2017-08-13 19:11:23 +00:00
|
|
|
]
|
2016-10-20 13:27:34 +00:00
|
|
|
|
2017-08-13 19:11:23 +00:00
|
|
|
|
|
|
|
def justify_width(coins):
|
|
|
|
for j in range(len(coins[0])):
|
|
|
|
l = max([len(x[j]) for x in coins]) + 1
|
|
|
|
for i in range(len(coins)):
|
|
|
|
if coins[i][j][0] in '0123456789':
|
|
|
|
coins[i][j] = (coins[i][j] + ',').rjust(l)
|
|
|
|
else:
|
|
|
|
coins[i][j] = (coins[i][j] + ',').ljust(l)
|
|
|
|
|
|
|
|
|
|
|
|
for coin in coins_json:
|
|
|
|
if coin['firmware'] == 'stable':
|
|
|
|
coins_stable.append(get_fields(coin))
|
|
|
|
if coin['firmware'] == 'debug':
|
|
|
|
coins_debug.append(get_fields(coin))
|
|
|
|
|
|
|
|
justify_width(coins_stable)
|
|
|
|
justify_width(coins_debug)
|
|
|
|
|
2017-09-30 09:09:11 +00:00
|
|
|
print("// THIS IS A GENERATED FILE - DO NOT HAND EDIT\n\n")
|
|
|
|
|
|
|
|
if sys.argv[1] == "array":
|
|
|
|
for row in coins_stable:
|
|
|
|
print('\t{' + ' '.join(row) + ' },')
|
2017-08-13 19:11:23 +00:00
|
|
|
|
2017-09-30 09:09:11 +00:00
|
|
|
print('#if DEBUG_LINK')
|
2017-08-13 19:11:23 +00:00
|
|
|
|
2017-09-30 09:09:11 +00:00
|
|
|
for row in coins_debug:
|
|
|
|
print('\t{' + ' '.join(row) + ' },')
|
2017-08-13 19:11:23 +00:00
|
|
|
|
2017-09-30 09:09:11 +00:00
|
|
|
print('#endif')
|
2017-08-13 19:11:23 +00:00
|
|
|
|
|
|
|
|
2017-09-30 09:09:11 +00:00
|
|
|
if sys.argv[1] == "count":
|
|
|
|
print('#if DEBUG_LINK')
|
|
|
|
print('#define COINS_COUNT %d' % (len(coins_stable) + len(coins_debug)))
|
|
|
|
print('#else')
|
|
|
|
print('#define COINS_COUNT %d' % (len(coins_stable)))
|
|
|
|
print('#endif')
|