Skip to content

Commit

Permalink
fix bool returns and argument validation
Browse files Browse the repository at this point in the history
  • Loading branch information
chcmedeiros committed Sep 14, 2023
1 parent 09dd6bc commit 8d6b588
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
34 changes: 19 additions & 15 deletions app/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,61 +92,65 @@ parser_error_t parser_getNumItems(const parser_context_t *ctx, uint8_t *num_item

__Z_INLINE bool_t parser_areEqual(uint16_t tokenIdx, const char *expected) {
if (parser_tx_obj.tx_json.json.tokens[tokenIdx].type != JSMN_STRING) {
return bool_false;
return false;
}

int32_t len = parser_tx_obj.tx_json.json.tokens[tokenIdx].end - parser_tx_obj.tx_json.json.tokens[tokenIdx].start;
if (len < 0) {
return bool_false;
return false;
}

if (strlen(expected) != (size_t) len) {
return bool_false;
return false;
}

const char *p = parser_tx_obj.tx_json.tx + parser_tx_obj.tx_json.json.tokens[tokenIdx].start;
for (int32_t i = 0; i < len; i++) {
if (expected[i] != *(p + i)) {
return bool_false;
return false;
}
}

return bool_true;
return true;
}

__Z_INLINE bool_t parser_isAmount(char *key) {
if (strcmp(key, "fee/amount") == 0) {
return bool_true;
return true;
}

if (strcmp(key, "msgs/inputs/coins") == 0) {
return bool_true;
return true;
}

if (strcmp(key, "msgs/outputs/coins") == 0) {
return bool_true;
return true;
}

if (strcmp(key, "msgs/value/inputs/coins") == 0) {
return bool_true;
return true;
}

if (strcmp(key, "msgs/value/outputs/coins") == 0) {
return bool_true;
return true;
}

if (strcmp(key, "msgs/value/amount") == 0) {
return bool_true;
return true;
}

if (strcmp(key, "tip/amount") == 0) {
return bool_true;
return true;
}

return bool_false;
return false;
}

__Z_INLINE parser_error_t is_default_denom_base(const char *denom, uint8_t denom_len, bool *is_default) {
if (is_default == NULL) {
return parser_unexpected_value;
}

bool is_expert_or_default = false;
CHECK_PARSER_ERR(tx_is_expert_mode_or_not_default_chainid(&is_expert_or_default))
if (is_expert_or_default) {
Expand All @@ -155,12 +159,12 @@ __Z_INLINE parser_error_t is_default_denom_base(const char *denom, uint8_t denom
}

if (strlen(COIN_DEFAULT_DENOM_BASE) != denom_len) {
*is_default = bool_false;
*is_default = false;
return parser_ok;
}

if (memcmp(denom, COIN_DEFAULT_DENOM_BASE, denom_len) == 0) {
*is_default = bool_true;
*is_default = true;
return parser_ok;
}

Expand Down
12 changes: 12 additions & 0 deletions app/src/tx_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,21 @@ parser_error_t tx_indexRootFields() {
}

__Z_INLINE parser_error_t is_default_chainid(bool *is_default) {
if (is_default == NULL) {
return parser_unexpected_value;
}

CHECK_PARSER_ERR(tx_indexRootFields())
*is_default = display_cache.is_default_chain;

return parser_ok;
}

parser_error_t tx_is_expert_mode_or_not_default_chainid(bool *expert_or_default) {
if (expert_or_default == NULL) {
return parser_unexpected_value;
}

bool is_default = false;
CHECK_PARSER_ERR(is_default_chainid(&is_default))
*expert_or_default = app_mode_expert() || !is_default;
Expand All @@ -335,6 +343,10 @@ parser_error_t tx_is_expert_mode_or_not_default_chainid(bool *expert_or_default)
}

__Z_INLINE parser_error_t get_subitem_count(root_item_e root_item, uint8_t *num_items) {
if (num_items == NULL) {
return parser_unexpected_value;
}

CHECK_PARSER_ERR(tx_indexRootFields())
if (display_cache.total_item_count == 0) {
*num_items = 0;
Expand Down

0 comments on commit 8d6b588

Please sign in to comment.