1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-08 22:40:59 +00:00

add coins-gen.py script and generate coins.c using that script

This commit is contained in:
Pavol Rusnak 2016-10-20 15:27:34 +02:00
parent c288a0e328
commit 2daab8cf02
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 52 additions and 8 deletions

44
firmware/coins-gen.py Executable file
View File

@ -0,0 +1,44 @@
#!/usr/bin/env python3
import json
coins = json.load(open('../vendor/trezor-common/coins.json', 'r'))
fields = []
for c in coins:
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',
'true' if c['coin_shortcut'] is not None else 'false',
'"%s"' % c['coin_shortcut'] if c['coin_shortcut'] is not None else 'NULL',
'true' if c['address_type'] is not None else 'false',
'%d' % c['address_type'] if c['address_type'] is not None else '0',
'true' if c['maxfee_kb'] is not None else 'false',
'%d' % c['maxfee_kb'] if c['maxfee_kb'] is not None else '0',
'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',
'true' if c['address_type_p2wpkh'] is not None else 'false',
'%d' % c['address_type_p2wpkh'] if c['address_type_p2wpkh'] is not None else '0',
'true' if c['address_type_p2wsh'] is not None else 'false',
'%d' % c['address_type_p2wsh'] if c['address_type_p2wsh'] is not None else '0',
'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',
])
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) + ' },')

View File

@ -24,14 +24,14 @@
// filled CoinType Protobuf structure defined in https://github.com/trezor/trezor-common/blob/master/protob/types.proto#L133
// address types > 0xFF represent a two-byte prefix in big-endian order
const CoinType coins[COINS_COUNT] = {
{true, "Bitcoin", true, "BTC", true, 0, true, 100000, true, 5, true, 6, true, 10, true, "\x18" "Bitcoin Signed Message:\n"},
{true, "Testnet", true, "TEST", true, 111, true, 10000000, true, 196, true, 3, true, 40, true, "\x18" "Bitcoin Signed Message:\n"},
{true, "Namecoin", true, "NMC", true, 52, true, 10000000, true, 5, false, 0, false, 0, true, "\x19" "Namecoin Signed Message:\n"},
{true, "Litecoin", true, "LTC", true, 48, true, 1000000, true, 5, false, 0, false, 0, true, "\x19" "Litecoin Signed Message:\n"},
{true, "Dogecoin", true, "DOGE", true, 30, true, 1000000000, true, 22, false, 0, false, 0, true, "\x19" "Dogecoin Signed Message:\n"},
{true, "Dash", true, "DASH", true, 76, true, 100000, true, 16, false, 0, false, 0, true, "\x19" "DarkCoin Signed Message:\n"},
{true, "Zcash", true, "ZEC", true, 0x1CBD, true, 1000000, true, 0x1CB8, false, 0, false, 0, true, "\x16" "Zcash Signed Message:\n"},
{true, "Zcash Testnet", true, "TAZ", true, 0x1D25, true, 1000000, true, 0x1CBA, false, 0, false, 0, true, "\x16" "Zcash Signed Message:\n"},
{true, "Bitcoin", true, "BTC", true, 0, true, 100000, true, 5, true, 6, true, 10, true, "\x18" "Bitcoin Signed Message:\n", },
{true, "Testnet", true, "TEST", true, 111, true, 10000000, true, 196, true, 3, true, 40, true, "\x18" "Bitcoin Signed Message:\n", },
{true, "Namecoin", true, "NMC", true, 52, true, 10000000, true, 5, false, 0, false, 0, true, "\x19" "Namecoin Signed Message:\n", },
{true, "Litecoin", true, "LTC", true, 48, true, 1000000, true, 5, false, 0, false, 0, true, "\x19" "Litecoin Signed Message:\n", },
{true, "Dogecoin", true, "DOGE", true, 30, true, 1000000000, true, 22, false, 0, false, 0, true, "\x19" "Dogecoin Signed Message:\n", },
{true, "Dash", true, "DASH", true, 76, true, 100000, true, 16, false, 0, false, 0, true, "\x19" "DarkCoin Signed Message:\n", },
{true, "Zcash", true, "ZEC", true, 7352, true, 1000000, true, 7357, false, 0, false, 0, true, "\x16" "Zcash Signed Message:\n", },
{true, "Zcash Testnet", true, "TAZ", true, 7461, true, 10000000, true, 7354, false, 0, false, 0, true, "\x16" "Zcash Signed Message:\n", },
};
const CoinType *coinByShortcut(const char *shortcut)