1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 23:48:12 +00:00

Improved backwards compatibility of GetFeatures

Set all CoinType fields except signed_message_header.
Move static assert into the function where it is needed.
This commit is contained in:
Jochen Hoenicke 2017-10-31 18:32:08 +01:00 committed by Pavol Rusnak
parent b5fa8a266a
commit 1566631023

View File

@ -208,8 +208,6 @@ void fsm_msgInitialize(Initialize *msg)
fsm_msgGetFeatures(0); fsm_msgGetFeatures(0);
} }
_Static_assert(pb_arraysize(Features, coins) >= COINS_COUNT, "Features.coins max_count not large enough");
void fsm_msgGetFeatures(GetFeatures *msg) void fsm_msgGetFeatures(GetFeatures *msg)
{ {
(void)msg; (void)msg;
@ -234,12 +232,32 @@ void fsm_msgGetFeatures(GetFeatures *msg)
resp->has_label = true; resp->has_label = true;
strlcpy(resp->label, storage.label, sizeof(resp->label)); strlcpy(resp->label, storage.label, sizeof(resp->label));
} }
_Static_assert(pb_arraysize(Features, coins) >= COINS_COUNT, "Features.coins max_count not large enough");
resp->coins_count = COINS_COUNT; resp->coins_count = COINS_COUNT;
for (int i = 0; i < COINS_COUNT; i++) { for (int i = 0; i < COINS_COUNT; i++) {
resp->coins[i].has_coin_name = true; if (coins[i].coin_name) {
strlcpy(resp->coins[i].coin_name, coins[i].coin_name, sizeof(resp->coins[i].coin_name)); resp->coins[i].has_coin_name = true;
strlcpy(resp->coins[i].coin_name, coins[i].coin_name, sizeof(resp->coins[i].coin_name));
}
if (coins[i].coin_shortcut) {
resp->coins[i].has_coin_shortcut = true;
strlcpy(resp->coins[i].coin_shortcut, coins[i].coin_shortcut, sizeof(resp->coins[i].coin_shortcut));
}
resp->coins[i].has_address_type = coins[i].has_address_type;
resp->coins[i].address_type = coins[i].address_type;
resp->coins[i].has_maxfee_kb = true; resp->coins[i].has_maxfee_kb = true;
resp->coins[i].maxfee_kb = coins[i].maxfee_kb; resp->coins[i].maxfee_kb = coins[i].maxfee_kb;
resp->coins[i].has_address_type_p2sh = coins[i].has_address_type_p2sh;
resp->coins[i].address_type_p2sh = coins[i].address_type_p2sh;
resp->coins[i].has_xpub_magic = coins[i].xpub_magic != 0;
resp->coins[i].xpub_magic = coins[i].xpub_magic;
resp->coins[i].has_xprv_magic = coins[i].xprv_magic != 0;
resp->coins[i].xprv_magic = coins[i].xprv_magic;
resp->coins[i].has_segwit = true;
resp->coins[i].segwit = coins[i].has_segwit;
resp->coins[i].has_forkid = coins[i].has_forkid;
resp->coins[i].forkid = coins[i].forkid;
} }
resp->has_initialized = true; resp->initialized = storage_isInitialized(); resp->has_initialized = true; resp->initialized = storage_isInitialized();
resp->has_imported = true; resp->imported = storage.has_imported && storage.imported; resp->has_imported = true; resp->imported = storage.has_imported && storage.imported;