mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-10 15:30:55 +00:00
cashaddr: Don't show coin prefix on the display.
While technically part of the address, the coin prefix, e.g., bitcoincash: is implicit and doesn't need to be checked by the user. We still include it in the QR-code though. Also set case-insensitive flag for QR-code.
This commit is contained in:
parent
1e91f92271
commit
059555039c
@ -217,11 +217,15 @@ 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, 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 qrcode = false;
|
||||
for (;;) {
|
||||
layoutAddress(address, desc, qrcode, ignorecase, address_n, address_n_count);
|
||||
const char* display_addr = address;
|
||||
if (prefixlen && !qrcode) {
|
||||
display_addr += prefixlen;
|
||||
}
|
||||
layoutAddress(display_addr, desc, qrcode, ignorecase, address_n, address_n_count);
|
||||
if (protectButton(ButtonRequestType_ButtonRequest_Address, false)) {
|
||||
return true;
|
||||
}
|
||||
@ -835,7 +839,9 @@ void fsm_msgGetAddress(GetAddress *msg)
|
||||
}
|
||||
}
|
||||
|
||||
if (!fsm_layoutAddress(address, desc, msg->script_type == InputScriptType_SPENDWITNESS, msg->address_n, msg->address_n_count)) {
|
||||
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)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -868,7 +874,7 @@ void fsm_msgEthereumGetAddress(EthereumGetAddress *msg)
|
||||
char address[43] = { '0', 'x' };
|
||||
ethereum_address_checksum(resp->address.bytes, address + 2);
|
||||
|
||||
if (!fsm_layoutAddress(address, desc, false, msg->address_n, msg->address_n_count)) {
|
||||
if (!fsm_layoutAddress(address, desc, false, 0, msg->address_n, msg->address_n_count)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -1293,7 +1299,7 @@ void fsm_msgNEMGetAddress(NEMGetAddress *msg)
|
||||
strlcpy(desc, network, sizeof(desc));
|
||||
strlcat(desc, ":", sizeof(desc));
|
||||
|
||||
if (!fsm_layoutAddress(resp->address, desc, true, msg->address_n, msg->address_n_count)) {
|
||||
if (!fsm_layoutAddress(resp->address, desc, true, 0, msg->address_n, msg->address_n_count)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -250,6 +250,16 @@ 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 *addr = out->address;
|
||||
if (coin->cashaddr_prefix) {
|
||||
/* If this is a cashaddr address, remove the prefix from the
|
||||
* string presented to the user
|
||||
*/
|
||||
int prefix_len = strlen(coin->cashaddr_prefix);
|
||||
if (strncmp(addr, coin->cashaddr_prefix, prefix_len) == 0
|
||||
&& addr[prefix_len] == ':') {
|
||||
addr += prefix_len + 1;
|
||||
}
|
||||
}
|
||||
int addrlen = strlen(addr);
|
||||
int numlines = addrlen <= 42 ? 2 : 3;
|
||||
int linelen = (addrlen - 1) / numlines + 1;
|
||||
|
Loading…
Reference in New Issue
Block a user