Skip to content

Commit 7bb0eea

Browse files
Now handles unlimited datetimes
1 parent dbba2fb commit 7bb0eea

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src_features/generic_tx_parser/gtp_param_datetime.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,25 @@ 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;
7474
uint256_t block_height;
7575

7676
if ((ret = value_get(&param->value, &collec))) {
7777
for (int i = 0; i < collec.size; ++i) {
7878
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;
79+
if ((collec.value[i].length >= param->value.type_size) &&
80+
ismaxint((uint8_t *) collec.value[i].ptr, collec.value[i].length)) {
81+
snprintf(buf, buf_size, "Unlimited");
82+
} else {
83+
buf_shrink_expand(collec.value[i].ptr,
84+
collec.value[i].length,
85+
time_buf,
86+
sizeof(time_buf));
87+
timestamp = read_u64_be(time_buf, 0);
88+
if (!(ret = time_format_to_utc(&timestamp, buf, buf_size))) {
89+
break;
90+
}
8691
}
8792
} else if (param->type == DT_BLOCKHEIGHT) {
8893
convertUint256BE(collec.value[i].ptr, collec.value[i].length, &block_height);

src_features/signMessageEIP712/ui_logic.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,11 +547,17 @@ 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;
554555

556+
if ((length >= get_struct_field_typesize(field_ptr)) && ismaxint((uint8_t *) data, length)) {
557+
snprintf(strings.tmp.tmp, sizeof(strings.tmp.tmp), "Unlimited");
558+
return true;
559+
}
560+
timestamp = u64_from_BE(data, length);
555561
return time_format_to_utc(&timestamp, strings.tmp.tmp, sizeof(strings.tmp.tmp));
556562
}
557563

@@ -629,7 +635,7 @@ bool ui_712_feed_to_display(const void *field_ptr,
629635
}
630636

631637
if (ui_ctx->field_flags & UI_712_DATETIME) {
632-
if (!ui_712_format_datetime(data, length)) {
638+
if (!ui_712_format_datetime(data, length, field_ptr)) {
633639
return false;
634640
}
635641
}

0 commit comments

Comments
 (0)