Skip to content

Commit

Permalink
handle the print of possible empty values on BecomeValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
chcmedeiros committed Jan 14, 2025
1 parent 794d316 commit 9e65ff0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 31 deletions.
10 changes: 5 additions & 5 deletions app/src/parser_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,19 @@ parser_error_t getNumItems(const parser_context_t *ctx, uint8_t *numItems) {

case BecomeValidator: {
*numItems = (app_mode_expert() ? BECOME_VALIDATOR_EXPERT_PARAMS : BECOME_VALIDATOR_NORMAL_PARAMS);
if(ctx->tx_obj->becomeValidator.name.ptr) {
if(ctx->tx_obj->becomeValidator.has_name) {
(*numItems)++;
}
if(ctx->tx_obj->becomeValidator.description.ptr) {
if(ctx->tx_obj->becomeValidator.has_description) {
(*numItems)++;
}
if(ctx->tx_obj->becomeValidator.discord_handle.ptr) {
if(ctx->tx_obj->becomeValidator.has_discord_handle) {
(*numItems)++;
}
if(ctx->tx_obj->becomeValidator.website.ptr) {
if(ctx->tx_obj->becomeValidator.has_website) {
(*numItems)++;
}
if(ctx->tx_obj->becomeValidator.avatar.ptr) {
if(ctx->tx_obj->becomeValidator.has_avatar) {
(*numItems)++;
}
break;
Expand Down
31 changes: 21 additions & 10 deletions app/src/parser_print_txn.c
Original file line number Diff line number Diff line change
Expand Up @@ -916,19 +916,19 @@ static parser_error_t printBecomeValidatorTxn( const parser_context_t *ctx,
char *outVal, uint16_t outValLen,
uint8_t pageIdx, uint8_t *pageCount) {

if(displayIdx >= 9 && ctx->tx_obj->becomeValidator.name.ptr == NULL) {
if(displayIdx >= 9 && ctx->tx_obj->becomeValidator.has_name) {
displayIdx++;
}
if(displayIdx >= 10 && ctx->tx_obj->becomeValidator.description.ptr == NULL) {
if(displayIdx >= 10 && ctx->tx_obj->becomeValidator.has_description) {
displayIdx++;
}
if(displayIdx >= 11 && ctx->tx_obj->becomeValidator.website.ptr == NULL) {
if(displayIdx >= 11 && ctx->tx_obj->becomeValidator.has_website) {
displayIdx++;
}
if(displayIdx >= 12 && ctx->tx_obj->becomeValidator.discord_handle.ptr == NULL) {
if(displayIdx >= 12 && ctx->tx_obj->becomeValidator.has_discord_handle) {
displayIdx++;
}
if(displayIdx >= 13 && ctx->tx_obj->becomeValidator.avatar.ptr == NULL) {
if(displayIdx >= 13 && ctx->tx_obj->becomeValidator.has_avatar) {
displayIdx++;
}

Expand Down Expand Up @@ -995,12 +995,14 @@ static parser_error_t printBecomeValidatorTxn( const parser_context_t *ctx,
}
case 9: {
snprintf(outKey, outKeyLen, "Name");
pageStringExt(outVal, outValLen, (const char*)ctx->tx_obj->becomeValidator.name.ptr, ctx->tx_obj->becomeValidator.name.len, pageIdx, pageCount);
snprintf(outVal, outValLen, "");
if (ctx->tx_obj->becomeValidator.name.len > 0) {
pageStringExt(outVal, outValLen, (const char*)ctx->tx_obj->becomeValidator.name.ptr, ctx->tx_obj->becomeValidator.name.len, pageIdx, pageCount);
}
break;
}
case 10: {
snprintf(outKey, outKeyLen, "Description");
// snprintf(outVal, outValLen, "(none)");
snprintf(outVal, outValLen, "");
if (ctx->tx_obj->becomeValidator.description.len > 0) {
pageStringExt(outVal, outValLen, (const char*)ctx->tx_obj->becomeValidator.description.ptr, ctx->tx_obj->becomeValidator.description.len, pageIdx, pageCount);
Expand All @@ -1009,17 +1011,26 @@ static parser_error_t printBecomeValidatorTxn( const parser_context_t *ctx,
}
case 11: {
snprintf(outKey, outKeyLen, "Website");
pageStringExt(outVal, outValLen, (const char*)ctx->tx_obj->becomeValidator.website.ptr, ctx->tx_obj->becomeValidator.website.len, pageIdx, pageCount);
snprintf(outVal, outValLen, "");
if (ctx->tx_obj->becomeValidator.website.len > 0) {
pageStringExt(outVal, outValLen, (const char*)ctx->tx_obj->becomeValidator.website.ptr, ctx->tx_obj->becomeValidator.website.len, pageIdx, pageCount);
}
break;
}
case 12: {
snprintf(outKey, outKeyLen, "Discord handle");
pageStringExt(outVal, outValLen, (const char*)ctx->tx_obj->becomeValidator.discord_handle.ptr, ctx->tx_obj->becomeValidator.discord_handle.len, pageIdx, pageCount);
snprintf(outVal, outValLen, "");
if (ctx->tx_obj->becomeValidator.discord_handle.len > 0) {
pageStringExt(outVal, outValLen, (const char*)ctx->tx_obj->becomeValidator.discord_handle.ptr, ctx->tx_obj->becomeValidator.discord_handle.len, pageIdx, pageCount);
}
break;
}
case 13: {
snprintf(outKey, outKeyLen, "Avatar");
pageStringExt(outVal, outValLen, (const char*)ctx->tx_obj->becomeValidator.avatar.ptr, ctx->tx_obj->becomeValidator.avatar.len, pageIdx, pageCount);
snprintf(outVal, outValLen, "");
if (ctx->tx_obj->becomeValidator.avatar.len > 0) {
pageStringExt(outVal, outValLen, (const char*)ctx->tx_obj->becomeValidator.avatar.ptr, ctx->tx_obj->becomeValidator.avatar.len, pageIdx, pageCount);
}
break;
}
case 14:
Expand Down
5 changes: 5 additions & 0 deletions app/src/parser_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,15 @@ typedef struct {
bytes_t max_commission_rate_change;
bytes_t email;
bytes_t description;
uint8_t has_description;
bytes_t website;
uint8_t has_website;
bytes_t discord_handle;
uint8_t has_discord_handle;
bytes_t avatar;
uint8_t has_avatar;
bytes_t name;
uint8_t has_name;
} tx_become_validator_t;

typedef struct {
Expand Down
27 changes: 11 additions & 16 deletions app/src/txn_validator.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ parser_error_t readBecomeValidator(const bytes_t *data, const section_t *extra_d
/// The validator description
v->becomeValidator.description.ptr = NULL;
v->becomeValidator.description.len = 0;
uint8_t has_description = 0;
CHECK_ERROR(readByte(&ctx, &has_description))
if (has_description != 0 && has_description != 1) {
CHECK_ERROR(readByte(&ctx, &v->becomeValidator.has_description))
if (v->becomeValidator.has_description != 0 && v->becomeValidator.has_description != 1) {
return parser_value_out_of_range;
}

if (has_description) {
if (v->becomeValidator.has_description) {
CHECK_ERROR(readUint32(&ctx, &tmpValue));
if (tmpValue > UINT16_MAX) {
return parser_value_out_of_range;
Expand All @@ -74,9 +73,8 @@ parser_error_t readBecomeValidator(const bytes_t *data, const section_t *extra_d
/// The validator website
v->becomeValidator.website.ptr = NULL;
v->becomeValidator.website.len = 0;
uint8_t has_website;
CHECK_ERROR(readByte(&ctx, &has_website))
if (has_website) {
CHECK_ERROR(readByte(&ctx, &v->becomeValidator.has_website))
if (v->becomeValidator.has_website) {
CHECK_ERROR(readUint32(&ctx, &tmpValue));
if (tmpValue > UINT16_MAX) {
return parser_value_out_of_range;
Expand All @@ -88,9 +86,8 @@ parser_error_t readBecomeValidator(const bytes_t *data, const section_t *extra_d
/// The validator's discord handle
v->becomeValidator.discord_handle.ptr = NULL;
v->becomeValidator.discord_handle.len = 0;
uint8_t has_discord_handle;
CHECK_ERROR(readByte(&ctx, &has_discord_handle))
if (has_discord_handle) {
CHECK_ERROR(readByte(&ctx, &v->becomeValidator.has_discord_handle))
if (v->becomeValidator.has_discord_handle) {
CHECK_ERROR(readUint32(&ctx, &tmpValue));
if (tmpValue > UINT16_MAX) {
return parser_value_out_of_range;
Expand All @@ -102,9 +99,8 @@ parser_error_t readBecomeValidator(const bytes_t *data, const section_t *extra_d
/// The validator's avatar
v->becomeValidator.avatar.ptr = NULL;
v->becomeValidator.avatar.len = 0;
uint8_t has_avatar;
CHECK_ERROR(readByte(&ctx, &has_avatar))
if (has_avatar) {
CHECK_ERROR(readByte(&ctx, &v->becomeValidator.has_avatar))
if (v->becomeValidator.has_avatar) {
CHECK_ERROR(readUint32(&ctx, &tmpValue));
if (tmpValue > UINT16_MAX) {
return parser_value_out_of_range;
Expand All @@ -116,9 +112,8 @@ parser_error_t readBecomeValidator(const bytes_t *data, const section_t *extra_d
/// The validator's name
v->becomeValidator.name.ptr = NULL;
v->becomeValidator.name.len = 0;
uint8_t has_name;
CHECK_ERROR(readByte(&ctx, &has_name))
if (has_name) {
CHECK_ERROR(readByte(&ctx, &v->becomeValidator.has_name))
if (v->becomeValidator.has_name) {
CHECK_ERROR(readUint32(&ctx, &tmpValue));
if (tmpValue > UINT16_MAX) {
return parser_value_out_of_range;
Expand Down

0 comments on commit 9e65ff0

Please sign in to comment.