Skip to content

Commit

Permalink
last_amount and last_fee can be converted to total_amount and total_f…
Browse files Browse the repository at this point in the history
…ee to be dual used for swap and summary.

No tests failed and amounts are accurate for both swap and batch transaction.
  • Loading branch information
ajinkyaraj-23 committed Aug 22, 2024
1 parent 42411fd commit 7245590
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
1 change: 1 addition & 0 deletions app/src/apdu_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ refill_blo_done(void)
TZ_CHECK(sign_packet());
TZ_SUCCEED();
}

#ifdef HAVE_BAGL
tz_ui_stream_push_accept_reject();
#endif
Expand Down
4 changes: 2 additions & 2 deletions app/src/handle_swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ swap_check_validity(void)
TZ_ASSERT(EXC_REJECT, op->nb_reveal <= 1);
TZ_ASSERT(EXC_REJECT, (op->batch_index - op->nb_reveal) == 1);
TZ_ASSERT(EXC_REJECT, op->last_tag == TZ_OPERATION_TAG_TRANSACTION);
TZ_ASSERT(EXC_REJECT, op->last_amount == G_swap_params.amount);
TZ_ASSERT(EXC_REJECT, op->last_fee == G_swap_params.fee);
TZ_ASSERT(EXC_REJECT, op->total_amount == G_swap_params.amount);
TZ_ASSERT(EXC_REJECT, op->total_fee == G_swap_params.fee);

tz_format_address(op->destination, 22, dstaddr, sizeof(dstaddr));

Expand Down
14 changes: 6 additions & 8 deletions app/src/parser/operation_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,11 @@ tz_operation_parser_init(tz_parser_state *state, uint16_t size,
memset(&state->operation.destination, 0, 22);
op->batch_index = 0;
#ifdef HAVE_SWAP
op->last_tag = TZ_OPERATION_TAG_END;
op->nb_reveal = 0;
op->last_fee = 0;
op->last_amount = 0;
op->last_tag = TZ_OPERATION_TAG_END;
op->nb_reveal = 0;
#endif // HAVE_SWAP
op->total_fee = 0;
op->total_amount = 0;
op->frame = op->stack;
op->stack[0].stop = size;
if (!skip_magic) {
Expand Down Expand Up @@ -662,22 +662,20 @@ tz_step_read_num(tz_parser_state *state)
&op->frame->step_read_num.state, b,
op->frame->step_read_num.natural));
if (op->frame->step_read_num.state.stop) {
#ifdef HAVE_SWAP
uint64_t value;
if (!tz_string_to_mutez(state->buffers.num.decimal, &value)) {
tz_raise(INVALID_DATA);
}
switch (op->frame->step_read_num.kind) {
case TZ_OPERATION_FIELD_AMOUNT:
op->last_amount = value;
op->total_amount += value;
break;
case TZ_OPERATION_FIELD_FEE:
op->last_fee = value;
op->total_fee += value;
break;
default:
break;
}
#endif // HAVE_SWAP
if (op->frame->step_read_num.skip) {
tz_must(pop_frame(state));
tz_continue;
Expand Down
10 changes: 5 additions & 5 deletions app/src/parser/operation_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ typedef struct {
uint8_t destination[22]; /// saved for entrypoint dispatch
uint16_t batch_index; /// to print a sequence number
#ifdef HAVE_SWAP
tz_operation_tag last_tag; /// last operations tag encountered
uint16_t nb_reveal; /// number of reveal encountered
uint64_t last_fee; /// last fee encountered
uint64_t last_amount; /// last amount encountered
#endif // HAVE_SWAP
tz_operation_tag last_tag; /// last operations tag encountered
uint16_t nb_reveal; /// number of reveal encountered
#endif // HAVE_SWAP
uint64_t total_fee; /// last fee encountered
uint64_t total_amount; /// last amount encountered
} tz_operation_state;

0 comments on commit 7245590

Please sign in to comment.