Skip to content

Commit 3f90ef7

Browse files
committed
add more test cases and make some fixes
1 parent de33b47 commit 3f90ef7

5 files changed

Lines changed: 395 additions & 113 deletions

File tree

app/src/parser.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ static parser_error_t checkSanity(uint8_t numItems, uint8_t displayIdx) {
8787
return parser_ok;
8888
}
8989

90-
parser_error_t page_title(char *outKey, uint16_t outKeyLen, const char *inValue) {
90+
parser_error_t page_title(const parser_tx_t *txObj, char *outKey, uint16_t outKeyLen, const char *title,
91+
primitive_t *primitive, parser_context_t *data_context) {
9192
CHECK_INPUT(outKey);
92-
CHECK_INPUT(inValue);
93+
CHECK_INPUT(title);
9394

9495
if (outKeyLen == 0) {
9596
return parser_ui_buffer_too_small;
@@ -99,19 +100,24 @@ parser_error_t page_title(char *outKey, uint16_t outKeyLen, const char *inValue)
99100
MEMZERO(outKey, outKeyLen);
100101

101102
clear_item_title_buffer();
102-
init_item_title_buffer(inValue);
103-
104-
uint8_t items_qty = 0;
105-
CHECK_ERROR(get_title_item_qty(&items_qty))
103+
if (strlen(title) > 0) {
104+
init_item_title_buffer(title);
105+
uint8_t items_qty = 0;
106+
CHECK_ERROR(get_title_item_qty(&items_qty))
106107

107-
if (items_qty == 0) {
108-
return parser_ui_item_title_empty;
109-
}
108+
if (items_qty == 0) {
109+
return parser_ui_item_title_empty;
110+
}
110111

111-
CHECK_ERROR(create_item_title(items_qty - 1, items_qty, outKey, outKeyLen));
112-
if (strlen(outKey) <= 1 && items_qty > 1) {
113-
MEMZERO(outKey, outKeyLen);
114-
CHECK_ERROR(create_item_title(items_qty - 2, items_qty, outKey, outKeyLen));
112+
CHECK_ERROR(create_item_title(items_qty - 1, items_qty, outKey, outKeyLen));
113+
if (strlen(outKey) <= 1 && items_qty > 1) {
114+
MEMZERO(outKey, outKeyLen);
115+
CHECK_ERROR(create_item_title(items_qty - 2, items_qty, outKey, outKeyLen));
116+
}
117+
} else {
118+
char ui_data_buffer[200] = {0};
119+
CHECK_ERROR(render_primitive(data_context, txObj, primitive, ui_data_buffer, sizeof(ui_data_buffer)));
120+
strncpy(outKey, ui_data_buffer, outKeyLen);
115121
}
116122

117123
return parser_ok;
@@ -194,7 +200,9 @@ parser_error_t parser_getItem(const parser_tx_t *txObj, uint8_t displayIdx, char
194200
CHECK_ERROR(checkSanity(numItems, displayIdx))
195201
cleanOutput(outKey, outKeyLen, outVal, outValLen);
196202

197-
CHECK_ERROR(page_title(outKey, outKeyLen, txObj->ui_items_new.items[displayIdx].title))
203+
CHECK_ERROR(page_title(txObj, outKey, outKeyLen, txObj->ui_items_new.items[displayIdx].title,
204+
&txObj->ui_items_new.items[displayIdx].primitive,
205+
&txObj->ui_items_new.items[displayIdx].data_context))
198206
CHECK_ERROR(page_item(txObj, outVal, outValLen, txObj->ui_items_new.items[displayIdx].title,
199207
&txObj->ui_items_new.items[displayIdx].primitive,
200208
&txObj->ui_items_new.items[displayIdx].data_context, pageIdx, pageCount))

app/src/parser_impl.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
parser_error_t _read(parser_context_t *c, parser_tx_t *v) {
2626
checkStack();
27-
ZEMU_LOGF(50, "ANDYYYYYY!\n")
2827

2928
CHECK_ERROR(schema_merkle_proofs_read(c, v));
3029
CHECK_ERROR(schema_extra_data_read(c, v));

app/src/render.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,10 @@ parser_error_t render_byte_array(parser_context_t *ctx, parser_tx_t *txObj, prim
166166

167167
if (byte_array->has_name_registry) {
168168
// check if name registry exist
169-
CHECK_ERROR(find_name_registry(txObj, &byte_array->name_registry, &array, outValue, outValueLen));
170-
return parser_ok;
169+
parser_error_t err = find_name_registry(txObj, &byte_array->name_registry, &array, outValue, outValueLen);
170+
if (err == parser_ok || err != parser_name_registry_not_found) {
171+
return err;
172+
}
171173
}
172174

173175
if (byte_array->len > MAX_INPUT_CHUNK) {
@@ -188,7 +190,8 @@ parser_error_t render_byte_array(parser_context_t *ctx, parser_tx_t *txObj, prim
188190
print_string("render_byte_array IMPLEMENT ME 2");
189191
return parser_unexpected_type;
190192
case BYTE_DISPLAY_BECH32M: {
191-
const char *hrp = (char *)byte_array->display.bech32m.prefix.prefix.ptr;
193+
char hrp[MAX_HRP_LEN + 1] = {0};
194+
MEMCPY(hrp, byte_array->display.bech32m.prefix.prefix.ptr, byte_array->display.bech32m.prefix.prefix.len);
192195
MEMZERO(outValue, outValueLen);
193196
MAP_ZXERR_TO_PARSER_ERR(
194197
bech32EncodeFromBytes(outValue, outValueLen, hrp, array.ptr, array.len, 1, BECH32_ENCODING_BECH32M));

app/src/schema_display.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,7 @@ parser_error_t schema_display_primitive(parser_context_t *ctx, parser_tx_t *txOb
184184
return parser_unexpected_type;
185185
}
186186

187-
if (is_enable_push_item()) {
188-
CHECK_ERROR(push_item(txObj, primitive, &ctx_to_push));
189-
}
187+
CHECK_ERROR(push_item(txObj, primitive, &ctx_to_push));
190188
return parser_ok;
191189
}
192190

@@ -226,9 +224,9 @@ parser_error_t schema_display_enum(parser_context_t *ctx, parser_tx_t *txObj) {
226224
ctx_bytes.buffer = variant.name;
227225
primitive_t primitive = {0};
228226
primitive.type = PRIMITIVE_STRING;
229-
if (is_enable_push_item()) {
230-
CHECK_ERROR(push_item_string(txObj, variant.name.ptr, variant.name.len));
231-
}
227+
set_enable_push_item(true);
228+
CHECK_ERROR(push_item_string(txObj, (const char *)variant.name.ptr, variant.name.len));
229+
set_enable_push_item(false);
232230
}
233231

234232
return parser_ok;
@@ -342,9 +340,7 @@ parser_error_t schema_display_option(parser_context_t *ctx, parser_tx_t *txObj)
342340
uint8_t discriminant = 0;
343341
CHECK_ERROR(read_u8(ctx, &discriminant));
344342
if (discriminant == 0) {
345-
if (is_enable_push_item()) {
346-
CHECK_ERROR(push_item_string(txObj, NONE_STRING, strlen(NONE_STRING)));
347-
}
343+
CHECK_ERROR(push_item_string(txObj, NONE_STRING, strlen(NONE_STRING)));
348344
CHECK_ERROR(schema_reset_leaf_offset(&txObj->merkle_proofs.leaves));
349345
return parser_ok;
350346
}
@@ -406,10 +402,10 @@ parser_error_t schema_display_vec(parser_context_t *ctx, parser_tx_t *txObj) {
406402

407403
schema_vec_t vec_type = {0};
408404
vec_type.len = vec_len;
405+
CHECK_ERROR(read_link(&txObj->merkle_proofs.leaves.data, &vec_type.value));
406+
CHECK_ERROR(schema_reset_leaf_offset(&txObj->merkle_proofs.leaves));
409407

410408
for (uint32_t i = 0; i < vec_len; i++) {
411-
CHECK_ERROR(read_link(&txObj->merkle_proofs.leaves.data, &vec_type.value));
412-
CHECK_ERROR(schema_reset_leaf_offset(&txObj->merkle_proofs.leaves));
413409
CHECK_ERROR(append_item_title_index(i));
414410
switch (vec_type.value.tag) {
415411
case LINK_BY_INDEX:

0 commit comments

Comments
 (0)