Skip to content

Commit

Permalink
fix change metadata printing
Browse files Browse the repository at this point in the history
  • Loading branch information
chcmedeiros committed Jul 25, 2024
1 parent 1b31cb7 commit c9ad9a6
Show file tree
Hide file tree
Showing 4 changed files with 519 additions and 468 deletions.
2 changes: 1 addition & 1 deletion app/src/crypto_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ bool check_diversifier(const uint8_t d[DIVERSIFIER_LENGTH]) {

// Derive the asset type corresponding to the given asset data
parser_error_t derive_asset_type(const masp_asset_data_t *asset_data, uint8_t *identifier, uint8_t *nonce) {
if(asset_data == NULL) {
if(asset_data == NULL || nonce == NULL) {
return parser_unexpected_error;
}

Expand Down
3 changes: 3 additions & 0 deletions app/src/parser_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ parser_error_t getNumItems(const parser_context_t *ctx, uint8_t *numItems) {
case ChangeValidatorMetadata: {
*numItems = app_mode_expert() ? CHANGE_VALIDATOR_METADATA_EXPERT_PARAMS : CHANGE_VALIDATOR_METADATA_NORMAL_PARAMS;

if (ctx->tx_obj->metadataChange.name.ptr != NULL) {
(*numItems)++;
}
if (ctx->tx_obj->metadataChange.email.ptr != NULL) {
(*numItems)++;
}
Expand Down
48 changes: 28 additions & 20 deletions app/src/parser_print_txn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1232,9 +1232,9 @@ static parser_error_t printIBCTxn( const parser_context_t *ctx,
if (uint64_to_str(tmpBuffer, sizeof(tmpBuffer), ibc->revision_number) != NULL) {
return parser_unexpected_error;
}
const uint8_t tmpOffset = strnlen(tmpBuffer, sizeof(tmpBuffer));
tmpBuffer[tmpOffset] = '-';
if (uint64_to_str(tmpBuffer + tmpOffset + 1, sizeof(tmpBuffer) - tmpOffset - 1, ibc->revision_height) != NULL) {
uint8_t tmpOffset = strnlen(tmpBuffer, sizeof(tmpBuffer));
tmpBuffer[tmpOffset++] = '-';
if (uint64_to_str(tmpBuffer + tmpOffset, sizeof(tmpBuffer) - tmpOffset, ibc->revision_height) != NULL) {
return parser_unexpected_error;
}
pageString(outVal, outValLen, tmpBuffer, pageIdx, pageCount);
Expand Down Expand Up @@ -1555,9 +1555,9 @@ static parser_error_t printNFTIBCTxn( const parser_context_t *ctx,
if (uint64_to_str(tmpBuffer, sizeof(tmpBuffer), ibc->revision_number) != NULL) {
return parser_unexpected_error;
}
const uint8_t tmpOffset = strnlen(tmpBuffer, sizeof(tmpBuffer));
tmpBuffer[tmpOffset] = '-';
if (uint64_to_str(tmpBuffer + tmpOffset + 1, sizeof(tmpBuffer) - tmpOffset - 1, ibc->revision_height) != NULL) {
uint8_t tmpOffset = strnlen(tmpBuffer, sizeof(tmpBuffer));
tmpBuffer[tmpOffset++] = '-';
if (uint64_to_str(tmpBuffer + tmpOffset, sizeof(tmpBuffer) - tmpOffset, ibc->revision_height) != NULL) {
return parser_unexpected_error;
}
pageString(outVal, outValLen, tmpBuffer, pageIdx, pageCount);
Expand Down Expand Up @@ -1760,27 +1760,30 @@ static parser_error_t printChangeValidatorMetadata( const parser_context_t *ctx

const tx_metadata_change_t *metadataChange = &ctx->tx_obj->metadataChange;

if(displayIdx >= 2 && metadataChange->email.ptr == NULL) {
if(displayIdx >= 2 && metadataChange->name.ptr == NULL) {
displayIdx++;
}
if(displayIdx >= 3 && metadataChange->description.ptr == NULL) {
if(displayIdx >= 3 && metadataChange->email.ptr == NULL) {
displayIdx++;
}
if(displayIdx >= 4 && metadataChange->website.ptr == NULL) {
if(displayIdx >= 4 && metadataChange->description.ptr == NULL) {
displayIdx++;
}
if(displayIdx >= 5 && metadataChange->discord_handle.ptr == NULL) {
if(displayIdx >= 5 && metadataChange->website.ptr == NULL) {
displayIdx++;
}
if(displayIdx >= 6 && metadataChange->avatar.ptr == NULL) {
if(displayIdx >= 6 && metadataChange->discord_handle.ptr == NULL) {
displayIdx++;
}
if(displayIdx >= 7 && !metadataChange->has_commission_rate) {
if(displayIdx >= 7 && metadataChange->avatar.ptr == NULL) {
displayIdx++;
}
if(displayIdx >= 8 && !metadataChange->has_commission_rate) {
displayIdx++;
}

const bool hasMemo = ctx->tx_obj->transaction.header.memoSection != NULL;
if (displayIdx >= 8 && !hasMemo) {
if (displayIdx >= 9 && !hasMemo) {
displayIdx++;
}

Expand All @@ -1799,44 +1802,49 @@ static parser_error_t printChangeValidatorMetadata( const parser_context_t *ctx
break;
}
case 2: {
snprintf(outKey, outKeyLen, "Name");
pageStringExt(outVal, outValLen, (const char*)metadataChange->name.ptr, metadataChange->name.len, pageIdx, pageCount);
break;
}
case 3: {
snprintf(outKey, outKeyLen, "Email");
pageStringExt(outVal, outValLen, (const char*)metadataChange->email.ptr, metadataChange->email.len, pageIdx, pageCount);
break;
}
case 3: {
case 4: {
snprintf(outKey, outKeyLen, "Description");
pageStringExt(outVal, outValLen, (const char*)metadataChange->description.ptr, metadataChange->description.len, pageIdx, pageCount);
break;
}
case 4: {
case 5: {
snprintf(outKey, outKeyLen, "Website");
pageStringExt(outVal, outValLen, (const char*)metadataChange->website.ptr, metadataChange->website.len, pageIdx, pageCount);
break;
}
case 5: {
case 6: {
snprintf(outKey, outKeyLen, "Discord handle");
pageStringExt(outVal, outValLen, (const char*)metadataChange->discord_handle.ptr, metadataChange->discord_handle.len, pageIdx, pageCount);
break;
}
case 6: {
case 7: {
snprintf(outKey, outKeyLen, "Avatar");
pageStringExt(outVal, outValLen, (const char*)metadataChange->avatar.ptr, metadataChange->avatar.len, pageIdx, pageCount);
break;
}
case 7: {
case 8: {
snprintf(outKey, outKeyLen, "Commission rate");
CHECK_ERROR(printAmount(&metadataChange->commission_rate, true, POS_DECIMAL_PRECISION, "", outVal, outValLen, pageIdx, pageCount))
break;
}
case 8:
case 9:
CHECK_ERROR(printMemo(ctx, outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount))
break;

default: {
if (!app_mode_expert()) {
return parser_display_idx_out_of_range;
}
displayIdx -= 9;
displayIdx -= 10;
return printExpert(ctx, displayIdx, outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount);
}
}
Expand Down
Loading

0 comments on commit c9ad9a6

Please sign in to comment.