Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
Revert "microtez_to_string: add ticker to string"
Browse files Browse the repository at this point in the history
This reverts commit 15227cc.
  • Loading branch information
sgliner-ledger committed Jun 2, 2023
1 parent 9cabbc9 commit 7f8aec4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
11 changes: 11 additions & 0 deletions src/swap/handle_get_printable_amount.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,16 @@ int handle_get_printable_amount(get_printable_amount_parameters_t* params) {
return 0;
}

size_t amount_len = strlen(params->printable_amount);
size_t remaining_len = sizeof(params->printable_amount) - amount_len;

// Check that we have enough space left to append ticker.
if (remaining_len < sizeof(TICKER_WITH_SPACE)) {
return 0;
}

// Append the ticker at the end of the amount.
strlcat(params->printable_amount, TICKER_WITH_SPACE, sizeof(params->printable_amount));

return 1;
}
2 changes: 2 additions & 0 deletions src/swap/swap_lib_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#define CHECK_ADDRESS 3
#define GET_PRINTABLE_AMOUNT 4

#define TICKER_WITH_SPACE " XTZ"

// structure that should be sent to specific coin application to get address
typedef struct check_address_parameters_s {
// IN
Expand Down
17 changes: 3 additions & 14 deletions src/to_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

#define TEZOS_HASH_CHECKSUM_SIZE 4

#define TICKER_WITH_SPACE " XTZ"

void pkh_to_string(char *const buff,
size_t const buff_size,
signature_type_t const signature_type,
Expand Down Expand Up @@ -268,7 +266,7 @@ void microtez_to_string_indirect(char *const dest,
uint64_t const *const number) {
check_null(dest);
check_null(number);
if (buff_size < MAX_INT_DIGITS + sizeof(TICKER_WITH_SPACE) + 1)
if (buff_size < MAX_INT_DIGITS + 1)
THROW(EXC_WRONG_LENGTH); // + terminating null + decimal point
microtez_to_string(dest, *number);
}
Expand All @@ -280,8 +278,7 @@ int microtez_to_string_indirect_no_throw(char *const dest,
if (!dest || !number) {
return (0);
}
if (buff_size <
MAX_INT_DIGITS + sizeof(TICKER_WITH_SPACE) + 1) { // + terminating null + decimal point
if (buff_size < MAX_INT_DIGITS + 1) { // + terminating null + decimal point
return (0);
}
// Can safely call `microtez_to_string` because we know dest is not NULL.
Expand Down Expand Up @@ -311,10 +308,6 @@ size_t microtez_to_string(char *const dest, uint64_t number) {
uint64_t fractional = number % TEZ_SCALE;
size_t off = number_to_string(dest, whole_tez);
if (fractional == 0) {
// Append the ticker at the end of the amount.
memcpy(dest + off, TICKER_WITH_SPACE, sizeof(TICKER_WITH_SPACE));
off += sizeof(TICKER_WITH_SPACE);

return off;
}
dest[off++] = '.';
Expand All @@ -335,11 +328,7 @@ size_t microtez_to_string(char *const dest, uint64_t number) {
size_t length = end - start;
memcpy(dest + off, start, length);
off += length;

// Append the ticker at the end of the amount.
memcpy(dest + length, TICKER_WITH_SPACE, sizeof(TICKER_WITH_SPACE));
off += sizeof(TICKER_WITH_SPACE);

dest[off] = '\0';
return off;
}

Expand Down

0 comments on commit 7f8aec4

Please sign in to comment.