From 8e6369e1ba8e7c59a061f804b392893961d6f77b Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Mon, 22 Oct 2018 15:15:15 +0200 Subject: [PATCH] layout: treat address as accounts for EthereumGetAddress dialogs --- firmware/fsm.c | 4 ++-- firmware/fsm_msg_coin.h | 2 +- firmware/fsm_msg_ethereum.h | 2 +- firmware/fsm_msg_lisk.h | 2 +- firmware/fsm_msg_nem.h | 2 +- firmware/layout2.c | 10 +++++----- firmware/layout2.h | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/firmware/fsm.c b/firmware/fsm.c index bc249de1b..2e379e56b 100644 --- a/firmware/fsm.c +++ b/firmware/fsm.c @@ -222,7 +222,7 @@ static HDNode *fsm_getDerivedNode(const char *curve, const uint32_t *address_n, return &node; } -static bool fsm_layoutAddress(const char *address, const char *desc, bool ignorecase, size_t prefixlen, const uint32_t *address_n, size_t address_n_count) +static bool fsm_layoutAddress(const char *address, const char *desc, bool ignorecase, size_t prefixlen, const uint32_t *address_n, size_t address_n_count, bool address_is_account) { bool qrcode = false; for (;;) { @@ -230,7 +230,7 @@ static bool fsm_layoutAddress(const char *address, const char *desc, bool ignore if (prefixlen && !qrcode) { display_addr += prefixlen; } - layoutAddress(display_addr, desc, qrcode, ignorecase, address_n, address_n_count); + layoutAddress(display_addr, desc, qrcode, ignorecase, address_n, address_n_count, address_is_account); if (protectButton(ButtonRequestType_ButtonRequest_Address, false)) { return true; } diff --git a/firmware/fsm_msg_coin.h b/firmware/fsm_msg_coin.h index d6ff406ad..7b559d5c3 100644 --- a/firmware/fsm_msg_coin.h +++ b/firmware/fsm_msg_coin.h @@ -232,7 +232,7 @@ void fsm_msgGetAddress(const GetAddress *msg) bool is_cashaddr = coin->cashaddr_prefix != NULL; bool is_bech32 = msg->script_type == InputScriptType_SPENDWITNESS; - if (!fsm_layoutAddress(address, desc, is_cashaddr || is_bech32, is_cashaddr ? strlen(coin->cashaddr_prefix) + 1 : 0, msg->address_n, msg->address_n_count)) { + if (!fsm_layoutAddress(address, desc, is_cashaddr || is_bech32, is_cashaddr ? strlen(coin->cashaddr_prefix) + 1 : 0, msg->address_n, msg->address_n_count, false)) { return; } } diff --git a/firmware/fsm_msg_ethereum.h b/firmware/fsm_msg_ethereum.h index c3270da0e..7f67de088 100644 --- a/firmware/fsm_msg_ethereum.h +++ b/firmware/fsm_msg_ethereum.h @@ -66,7 +66,7 @@ void fsm_msgEthereumGetAddress(const EthereumGetAddress *msg) char address[43] = { '0', 'x' }; ethereum_address_checksum(resp->address.bytes, address + 2, rskip60, chain_id); - if (!fsm_layoutAddress(address, desc, false, 0, msg->address_n, msg->address_n_count)) { + if (!fsm_layoutAddress(address, desc, false, 0, msg->address_n, msg->address_n_count, true)) { return; } } diff --git a/firmware/fsm_msg_lisk.h b/firmware/fsm_msg_lisk.h index e3ad8963b..c8c37540e 100644 --- a/firmware/fsm_msg_lisk.h +++ b/firmware/fsm_msg_lisk.h @@ -33,7 +33,7 @@ void fsm_msgLiskGetAddress(const LiskGetAddress *msg) lisk_get_address_from_public_key(&node->public_key[1], resp->address); if (msg->has_show_display && msg->show_display) { - if (!fsm_layoutAddress(resp->address, _("Address:"), true, 0, msg->address_n, msg->address_n_count)) { + if (!fsm_layoutAddress(resp->address, _("Address:"), true, 0, msg->address_n, msg->address_n_count, false)) { return; } } diff --git a/firmware/fsm_msg_nem.h b/firmware/fsm_msg_nem.h index 878b6829b..04c3a63d8 100644 --- a/firmware/fsm_msg_nem.h +++ b/firmware/fsm_msg_nem.h @@ -42,7 +42,7 @@ void fsm_msgNEMGetAddress(NEMGetAddress *msg) strlcpy(desc, network, sizeof(desc)); strlcat(desc, ":", sizeof(desc)); - if (!fsm_layoutAddress(resp->address, desc, true, 0, msg->address_n, msg->address_n_count)) { + if (!fsm_layoutAddress(resp->address, desc, true, 0, msg->address_n, msg->address_n_count, false)) { return; } } diff --git a/firmware/layout2.c b/firmware/layout2.c index bc56f1785..e18416ef0 100644 --- a/firmware/layout2.c +++ b/firmware/layout2.c @@ -55,7 +55,7 @@ static const char *slip44_extras(uint32_t coin_type) #define BIP32_MAX_LAST_ELEMENT 1000000 -static const char *address_n_str(const uint32_t *address_n, size_t address_n_count) +static const char *address_n_str(const uint32_t *address_n, size_t address_n_count, bool address_is_account) { if (address_n_count > 8) { return _("Unknown long path"); @@ -96,7 +96,7 @@ static const char *address_n_str(const uint32_t *address_n, size_t address_n_cou abbr = slip44_extras(address_n[1]); } } - uint32_t accnum = (address_n[2] & 0x7fffffff) + 1; + const uint32_t accnum = address_is_account ? ((address_n[4] & 0x7fffffff) + 1) : (address_n[2] & 0x7fffffff) + 1; if (abbr && accnum < 100) { memset(path, 0, sizeof(path)); strlcpy(path, abbr, sizeof(path)); @@ -312,7 +312,7 @@ void layoutConfirmOutput(const CoinInfo *coin, const TxOutputType *out) bn_format_uint64(out->amount, NULL, coin->coin_shortcut, BITCOIN_DIVISIBILITY, 0, false, str_out, sizeof(str_out) - 3); strlcat(str_out, " to", sizeof(str_out)); const char *address = out->address; - const char *extra_line = (out->address_n_count > 0) ? address_n_str(out->address_n, out->address_n_count) : 0; + const char *extra_line = (out->address_n_count > 0) ? address_n_str(out->address_n, out->address_n_count, false) : 0; render_address_dialog(coin, address, _("Confirm sending"), str_out, extra_line); } @@ -496,7 +496,7 @@ void layoutResetWord(const char *word, int pass, int word_pos, bool last) oledRefresh(); } -void layoutAddress(const char *address, const char *desc, bool qrcode, bool ignorecase, const uint32_t *address_n, size_t address_n_count) +void layoutAddress(const char *address, const char *desc, bool qrcode, bool ignorecase, const uint32_t *address_n, size_t address_n_count, bool address_is_account) { if (layoutLast != layoutAddress) { layoutSwipe(); @@ -550,7 +550,7 @@ void layoutAddress(const char *address, const char *desc, bool qrcode, bool igno for (int i = 0; i < 4; i++) { oledDrawString(0, (i + 1) * 9 + 4, str[i], FONT_FIXED); } - oledDrawString(0, 42, address_n_str(address_n, address_n_count), FONT_STANDARD); + oledDrawString(0, 42, address_n_str(address_n, address_n_count, address_is_account), FONT_STANDARD); } if (!qrcode) { diff --git a/firmware/layout2.h b/firmware/layout2.h index 283922a7a..cfeec1e1b 100644 --- a/firmware/layout2.h +++ b/firmware/layout2.h @@ -54,7 +54,7 @@ void layoutCipherKeyValue(bool encrypt, const char *key); void layoutEncryptMessage(const uint8_t *msg, uint32_t len, bool signing); void layoutDecryptMessage(const uint8_t *msg, uint32_t len, const char *address); void layoutResetWord(const char *word, int pass, int word_pos, bool last); -void layoutAddress(const char *address, const char *desc, bool qrcode, bool ignorecase, const uint32_t *address_n, size_t address_n_count); +void layoutAddress(const char *address, const char *desc, bool qrcode, bool ignorecase, const uint32_t *address_n, size_t address_n_count, bool address_is_account); void layoutPublicKey(const uint8_t *pubkey); void layoutSignIdentity(const IdentityType *identity, const char *challenge); void layoutDecryptIdentity(const IdentityType *identity);