Skip to content

Commit 8ea99f8

Browse files
Now handles unlimited datetimes
1 parent d7f34d1 commit 8ea99f8

2 files changed

Lines changed: 28 additions & 11 deletions

File tree

src_features/generic_tx_parser/gtp_param_datetime.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,28 @@ bool format_param_datetime(const s_param_datetime *param, const char *name) {
6969
s_parsed_value_collection collec = {0};
7070
char *buf = strings.tmp.tmp;
7171
size_t buf_size = sizeof(strings.tmp.tmp);
72-
uint8_t time_buf[sizeof(uint32_t)] = {0};
72+
uint8_t time_buf[sizeof(time_t)] = {0};
7373
time_t timestamp;
74+
// the size of the largest integer
75+
uint8_t max_int_buf[INT256_LENGTH];
7476
uint256_t block_height;
7577

7678
if ((ret = value_get(&param->value, &collec))) {
7779
for (int i = 0; i < collec.size; ++i) {
7880
if (param->type == DT_UNIX) {
79-
buf_shrink_expand(collec.value[i].ptr,
80-
collec.value[i].length,
81-
time_buf,
82-
sizeof(time_buf));
83-
timestamp = read_u32_be(time_buf, 0);
84-
if (!(ret = time_format_to_utc(&timestamp, buf, buf_size))) {
85-
break;
81+
memset(max_int_buf, 0xff, sizeof(max_int_buf));
82+
if ((collec.value[i].length >= param->value.type_size) &&
83+
(memcmp(collec.value[i].ptr, max_int_buf, collec.value[i].length) == 0)) {
84+
snprintf(buf, buf_size, "Unlimited");
85+
} else {
86+
buf_shrink_expand(collec.value[i].ptr,
87+
collec.value[i].length,
88+
time_buf,
89+
sizeof(time_buf));
90+
timestamp = read_u64_be(time_buf, 0);
91+
if (!(ret = time_format_to_utc(&timestamp, buf, buf_size))) {
92+
break;
93+
}
8694
}
8795
} else if (param->type == DT_BLOCKHEIGHT) {
8896
convertUint256BE(collec.value[i].ptr, collec.value[i].length, &block_height);

src_features/signMessageEIP712/ui_logic.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,11 +547,20 @@ static bool ui_712_format_trusted_name(const uint8_t *data, uint8_t length) {
547547
*
548548
* @param[in] data the data that needs formatting
549549
* @param[in] length its length
550+
* @param[in] field_ptr pointer to the new struct field
550551
* @return whether it was successful or not
551552
*/
552-
static bool ui_712_format_datetime(const uint8_t *data, uint8_t length) {
553-
time_t timestamp = u64_from_BE(data, length);
553+
static bool ui_712_format_datetime(const uint8_t *data, uint8_t length, const void *field_ptr) {
554+
time_t timestamp;
555+
// the size of the largest integer
556+
uint8_t buf[INT256_LENGTH];
554557

558+
memset(buf, 0xff, sizeof(buf));
559+
if ((length >= get_struct_field_typesize(field_ptr)) && (memcmp(data, buf, length) == 0)) {
560+
snprintf(strings.tmp.tmp, sizeof(strings.tmp.tmp), "Unlimited");
561+
return true;
562+
}
563+
timestamp = u64_from_BE(data, length);
555564
return time_format_to_utc(&timestamp, strings.tmp.tmp, sizeof(strings.tmp.tmp));
556565
}
557566

@@ -629,7 +638,7 @@ bool ui_712_feed_to_display(const void *field_ptr,
629638
}
630639

631640
if (ui_ctx->field_flags & UI_712_DATETIME) {
632-
if (!ui_712_format_datetime(data, length)) {
641+
if (!ui_712_format_datetime(data, length, field_ptr)) {
633642
return false;
634643
}
635644
}

0 commit comments

Comments
 (0)