Skip to content

Commit

Permalink
Show chain ID aliases in setup prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
3noch committed Feb 1, 2019
1 parent b8b7f94 commit 04aae4a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/apdu_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ __attribute__((noreturn)) static void prompt_setup(

SET_STATIC_UI_VALUE(TYPE_INDEX, "Baking?");
register_ui_callback(ADDRESS_INDEX, pubkey_to_string, &G.public_key);
register_ui_callback(CHAIN_INDEX, chain_id_to_string, &G.main_chain_id);
register_ui_callback(CHAIN_INDEX, chain_id_to_string_with_aliases, &G.main_chain_id);
register_ui_callback(MAIN_HWM_INDEX, number_to_string_indirect32, &G.hwm.main);
register_ui_callback(TEST_HWM_INDEX, number_to_string_indirect32, &G.hwm.test);

Expand Down
17 changes: 17 additions & 0 deletions src/to_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,23 @@ void chain_id_to_string(char *const buff, size_t const buff_size, chain_id_t con
if (!b58enc(buff, &out_size, &data, sizeof(data))) THROW(EXC_WRONG_LENGTH);
}

#define STRCPY_OR_THROW(buff, size, x, exc) \
({ \
if (size < sizeof(x)) THROW(exc); \
strcpy(buff, x); \
})

void chain_id_to_string_with_aliases(char *const out, size_t const out_size, chain_id_t const *const chain_id) {
check_null(chain_id);
if (chain_id->v == 0) {
STRCPY_OR_THROW(out, out_size, "any", EXC_WRONG_LENGTH);
} else if (chain_id->v == mainnet_chain_id.v) {
STRCPY_OR_THROW(out, out_size, "mainnet", EXC_WRONG_LENGTH);
} else {
chain_id_to_string(out, out_size, *chain_id);
}
}

// These functions do not output terminating null bytes.

// This function fills digits, potentially with all leading zeroes, from the end of the buffer backwards
Expand Down
1 change: 1 addition & 0 deletions src/to_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ void pubkey_to_pkh_string(char *buff, uint32_t buff_size, cx_curve_t curve,
void protocol_hash_to_string(char *buff, const size_t buff_size, const uint8_t hash[PROTOCOL_HASH_SIZE]);
void parsed_contract_to_string(char *buff, uint32_t buff_size, const struct parsed_contract *contract);
void chain_id_to_string(char *buff, size_t const buff_size, chain_id_t const chain_id);
void chain_id_to_string_with_aliases(char *const out, size_t const out_size, chain_id_t const *const chain_id);

// dest must be at least MAX_INT_DIGITS
size_t number_to_string(char *dest, uint64_t number);
Expand Down
8 changes: 1 addition & 7 deletions src/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,7 @@ static void update_baking_idle_screens(void) {
N_data.curve, pubkey);
}

if (N_data.main_chain_id.v == 0) {
STRCPY(G.baking_idle_screens.chain, "any");
} else if (N_data.main_chain_id.v == mainnet_chain_id.v) {
STRCPY(G.baking_idle_screens.chain, "mainnet");
} else {
chain_id_to_string(G.baking_idle_screens.chain, sizeof(G.baking_idle_screens.chain), N_data.main_chain_id);
}
chain_id_to_string_with_aliases(G.baking_idle_screens.chain, sizeof(G.baking_idle_screens.chain), &N_data.main_chain_id);
}

static void ui_idle(void) {
Expand Down

0 comments on commit 04aae4a

Please sign in to comment.