1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-03 03:50:58 +00:00

firmware: use new coin definitions from trezor-common

This commit is contained in:
Pavol Rusnak 2018-05-29 17:17:29 +02:00
parent 0ae5e91fcb
commit e2275a8b83
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
9 changed files with 27 additions and 21 deletions

View File

@ -119,6 +119,6 @@ clean::
rm -f $(1).h $(3) rm -f $(1).h $(3)
endef endef
$(eval $(call GENERATE_CODE,coin_info,coins.json,coin_info.c)) $(eval $(call GENERATE_CODE,coin_info,defs,coin_info.c))
$(eval $(call GENERATE_CODE,nem_mosaics,nem_mosaics.json,nem_mosaics.c)) $(eval $(call GENERATE_CODE,nem_mosaics,defs/nem/nem_mosaics.json,nem_mosaics.c))
$(eval $(call GENERATE_CODE,bl_data,../bootloader/bootloader.bin)) $(eval $(call GENERATE_CODE,bl_data,../bootloader/bootloader.bin))

View File

@ -63,7 +63,7 @@ def format_string(value):
def format_hex(value): def format_hex(value):
if value is None: if value is None:
value = "0" value = "0"
return "0x{:08x}".format(int(value, 16)) return "0x{:08x}".format(value)
def prepend_varint(string): def prepend_varint(string):
@ -78,22 +78,22 @@ def coin_to_struct(coin):
("coin_name", format_string(coin["coin_name"])), ("coin_name", format_string(coin["coin_name"])),
("coin_shortcut", format_string(" " + coin["coin_shortcut"])), ("coin_shortcut", format_string(" " + coin["coin_shortcut"])),
("maxfee_kb", format_number(coin["maxfee_kb"])), ("maxfee_kb", format_number(coin["maxfee_kb"])),
("signed_message_header", prepend_varint(coin["signed_message_header"])), # noqa: E501 ("signed_message_header", prepend_varint(coin["signed_message_header"])), # noqa: E501
("has_address_type", format_bool(coin["address_type"] is not None)), # noqa: E501 ("has_address_type", format_bool(coin["address_type"] is not None)), # noqa: E501
("has_address_type_p2sh", format_bool(coin["address_type_p2sh"] is not None)), # noqa: E501 ("has_address_type_p2sh", format_bool(coin["address_type_p2sh"] is not None)), # noqa: E501
("has_segwit", format_bool(coin["segwit"])), ("has_segwit", format_bool(coin["segwit"])),
("has_forkid", format_bool(coin["forkid"] is not None)), ("has_fork_id", format_bool(coin["fork_id"] is not None)),
("force_bip143", format_bool(coin["force_bip143"])), ("force_bip143", format_bool(coin["force_bip143"])),
("decred", format_bool(coin["decred"])), ("decred", format_bool(coin["decred"])),
("address_type", format_number(coin["address_type"])), ("address_type", format_number(coin["address_type"])),
("address_type_p2sh", format_number(coin["address_type_p2sh"])), ("address_type_p2sh", format_number(coin["address_type_p2sh"])),
("xpub_magic", format_hex(coin["xpub_magic"])), ("xpub_magic", format_hex(coin["xpub_magic"])),
("xprv_magic", format_hex(coin["xprv_magic"])), ("xprv_magic", format_hex(coin["xprv_magic"])),
("forkid", format_number(coin["forkid"])), ("fork_id", format_number(coin["fork_id"])),
("bech32_prefix", format_string(coin["bech32_prefix"])), ("bech32_prefix", format_string(coin["bech32_prefix"])),
("cashaddr_prefix", format_string(coin["cashaddr_prefix"])), ("cashaddr_prefix", format_string(coin["cashaddr_prefix"])),
("coin_type", "({} | 0x80000000)".format(format_number(coin["bip44"]))), # noqa: E501 ("coin_type", "({} | 0x80000000)".format(format_number(coin["slip44"]))), # noqa: E501
("curve_name", "{}_NAME".format(coin["curve_name"].upper())), # noqa: E501 ("curve_name", "{}_NAME".format(coin["curve_name"].upper())), # noqa: E501
("curve", "&{}_info".format(coin["curve_name"])), ("curve", "&{}_info".format(coin["curve_name"])),
)) ))
@ -118,9 +118,16 @@ if __name__ == "__main__":
coins = collections.defaultdict(list) coins = collections.defaultdict(list)
for coin in json.load(open("coins.json")): support = json.load(open('defs/support.json', 'r'), object_pairs_hook=collections.OrderedDict)
firmware = coin["firmware"] defs = support['trezor1'].keys()
coins[firmware].append(coin)
for c in defs:
name = c.replace(' ', '_').lower()
firmware = 'debug' if name.endswith('_testnet') else 'stable'
if name == 'testnet':
name = 'bitcoin_testnet'
data = json.load(open('defs/coins/%s.json' % name, 'r'))
coins[firmware].append(data)
with open("coin_info.h", "w+") as f: with open("coin_info.h", "w+") as f:
f.write(HEADER_TEMPLATE.format(**{ f.write(HEADER_TEMPLATE.format(**{

View File

@ -34,7 +34,7 @@ typedef struct _CoinInfo {
bool has_address_type; bool has_address_type;
bool has_address_type_p2sh; bool has_address_type_p2sh;
bool has_segwit; bool has_segwit;
bool has_forkid; bool has_fork_id;
bool force_bip143; bool force_bip143;
bool decred; bool decred;
// address types > 0xFF represent a two-byte prefix in big-endian order // address types > 0xFF represent a two-byte prefix in big-endian order
@ -42,7 +42,7 @@ typedef struct _CoinInfo {
uint32_t address_type_p2sh; uint32_t address_type_p2sh;
uint32_t xpub_magic; uint32_t xpub_magic;
uint32_t xprv_magic; uint32_t xprv_magic;
uint32_t forkid; uint32_t fork_id;
const char *bech32_prefix; const char *bech32_prefix;
const char *cashaddr_prefix; const char *cashaddr_prefix;
uint32_t coin_type; uint32_t coin_type;

View File

@ -1 +0,0 @@
../vendor/trezor-common/coins.json

1
firmware/defs Symbolic link
View File

@ -0,0 +1 @@
../vendor/trezor-common/defs

View File

@ -1 +0,0 @@
../vendor/trezor-common/defs/nem/nem_mosaics.json

View File

@ -109,7 +109,7 @@ if __name__ == "__main__":
sys.path.insert(0, "protob") sys.path.insert(0, "protob")
import types_pb2 as types import types_pb2 as types
messages = json.load(open("nem_mosaics.json")) messages = json.load(open("defs/nem/nem_mosaics.json"))
with open("nem_mosaics.h", "w+") as f: with open("nem_mosaics.h", "w+") as f:
f.write(HEADER_TEMPLATE.format( f.write(HEADER_TEMPLATE.format(

View File

@ -702,8 +702,8 @@ static bool signing_check_fee(void) {
static uint32_t signing_hash_type(void) { static uint32_t signing_hash_type(void) {
uint32_t hash_type = SIGHASH_ALL; uint32_t hash_type = SIGHASH_ALL;
if (coin->has_forkid) { if (coin->has_fork_id) {
hash_type |= (coin->forkid << 8) | SIGHASH_FORKID; hash_type |= (coin->fork_id << 8) | SIGHASH_FORKID;
} }
return hash_type; return hash_type;

@ -1 +1 @@
Subproject commit 0c9d67954c871553a7d44575a7a9198cba83df88 Subproject commit a0d37a0371aba597d3e0f3f1055adf1a9683a5e4