Skip to content

Commit

Permalink
Add some logs
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeutin-ledger committed Sep 24, 2024
1 parent 4232b37 commit 583a74d
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ static int set_token(const uint8_t address[ADDRESS_LENGTH], io_data_t *io_data)
PRINTF("Token to set is WETH\n");
io_data->asset_type = WETH;
} else {
PRINTF("Token to set is unknown\n");
PRINTF("Token to set is unknown %.*H\n", ADDRESS_LENGTH, address);
io_data->asset_type = UNKNOWN_TOKEN;
memmove(io_data->u.address, address, ADDRESS_LENGTH);
}
Expand Down Expand Up @@ -578,15 +578,19 @@ static void handle_execute(ethPluginProvideParameter_t *msg, context_t *context)
// ######################

case COMMANDS_OFFSET:
PRINTF("Interpreting as COMMANDS_OFFSET\n");
context->next_param = INPUTS_HEADER_OFFSET;
break;
case INPUTS_HEADER_OFFSET:
PRINTF("Interpreting as INPUTS_HEADER_OFFSET\n");
context->next_param = DEADLINE;
break;
case DEADLINE:
PRINTF("Interpreting as DEADLINE\n");
context->next_param = COMMANDS_LENGTH;
break;
case COMMANDS_LENGTH:
PRINTF("Interpreting as COMMANDS_LENGTH\n");
context->commands_number = U2BE(msg->parameter, PARAMETER_LENGTH - 2);
if (context->commands_number > sizeof(context->commands)) {
PRINTF("Error: too many commands\n");
Expand All @@ -595,13 +599,15 @@ static void handle_execute(ethPluginProvideParameter_t *msg, context_t *context)
context->next_param = COMMANDS;
break;
case COMMANDS:
PRINTF("Interpreting as COMMANDS\n");
memmove(context->commands, msg->parameter, context->commands_number);
for (int i = 0; i < context->commands_number; ++i) {
PRINTF("Command n %d: %02x\n", i, context->commands[i]);
}
context->next_param = INPUTS_NUMBER;
break;
case INPUTS_NUMBER: {
PRINTF("Interpreting as INPUTS_NUMBER\n");
uint8_t inputs_number = U2BE(msg->parameter, PARAMETER_LENGTH - 2);
if (context->commands_number != inputs_number) {
PRINTF("Error: context->commands_number != context->inputs_number\n");
Expand All @@ -612,6 +618,7 @@ static void handle_execute(ethPluginProvideParameter_t *msg, context_t *context)
}
} break;
case INPUTS_OFFSET:
PRINTF("Interpreting as INPUTS_OFFSET\n");
++context->current_input_offset_read;
if (context->current_input_offset_read == context->commands_number) {
context->current_command = 0;
Expand All @@ -626,9 +633,11 @@ static void handle_execute(ethPluginProvideParameter_t *msg, context_t *context)
// ################

case INPUT_WRAP_ETH_LENGTH:
PRINTF("Interpreting as INPUT_WRAP_ETH_LENGTH\n");
context->next_param = INPUT_WRAP_ETH_RECIPIENT;
break;
case INPUT_WRAP_ETH_RECIPIENT:
PRINTF("Interpreting as INPUT_WRAP_ETH_RECIPIENT\n");
PRINTF("Checking WRAP recipient\n");
if (!is_router_address(msg->parameter + PARAMETER_LENGTH - ADDRESS_LENGTH)) {
if (!is_sender_address(msg->parameter + PARAMETER_LENGTH - ADDRESS_LENGTH,
Expand All @@ -643,6 +652,7 @@ static void handle_execute(ethPluginProvideParameter_t *msg, context_t *context)
context->next_param = INPUT_WRAP_ETH_AMOUNT;
break;
case INPUT_WRAP_ETH_AMOUNT:
PRINTF("Interpreting as INPUT_WRAP_ETH_AMOUNT\n");
if (add_wrap_or_unwrap(msg->parameter, context, INPUT) != 0) {
PRINTF("Error in add_wrap_or_unwrap for input\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand All @@ -659,9 +669,11 @@ static void handle_execute(ethPluginProvideParameter_t *msg, context_t *context)
// ###################

case INPUT_UNWRAP_WETH_LENGTH:
PRINTF("Interpreting as INPUT_UNWRAP_WETH_LENGTH\n");
context->next_param = INPUT_UNWRAP_WETH_RECIPIENT;
break;
case INPUT_UNWRAP_WETH_RECIPIENT:
PRINTF("Interpreting as INPUT_UNWRAP_WETH_RECIPIENT\n");
PRINTF("Checking UNWRAP recipient\n");
if (!is_router_address(msg->parameter + PARAMETER_LENGTH - ADDRESS_LENGTH)) {
if (!is_sender_address(msg->parameter + PARAMETER_LENGTH - ADDRESS_LENGTH,
Expand All @@ -676,6 +688,7 @@ static void handle_execute(ethPluginProvideParameter_t *msg, context_t *context)
context->next_param = INPUT_UNWRAP_WETH_AMOUNT;
break;
case INPUT_UNWRAP_WETH_AMOUNT:
PRINTF("Interpreting as INPUT_UNWRAP_WETH_AMOUNT\n");
if (add_wrap_or_unwrap(msg->parameter, context, OUTPUT) != 0) {
PRINTF("Error in add_wrap_or_unwrap for output\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand All @@ -693,15 +706,19 @@ static void handle_execute(ethPluginProvideParameter_t *msg, context_t *context)
// ###################

case INPUT_PAY_PORTION_LENGTH:
PRINTF("Interpreting as INPUT_PAY_PORTION_LENGTH\n");
context->next_param = INPUT_PAY_PORTION_TOKEN;
break;
case INPUT_PAY_PORTION_TOKEN:
PRINTF("Interpreting as INPUT_PAY_PORTION_TOKEN\n");
context->next_param = INPUT_PAY_PORTION_RECIPIENT;
break;
case INPUT_PAY_PORTION_RECIPIENT:
PRINTF("Interpreting as INPUT_PAY_PORTION_RECIPIENT\n");
context->next_param = INPUT_PAY_PORTION_AMOUNT;
break;
case INPUT_PAY_PORTION_AMOUNT: {
PRINTF("Interpreting as INPUT_PAY_PORTION_AMOUNT\n");
uint16_t new;
if (!U2BE_from_parameter(msg->parameter, &new)) {
PRINTF("Error: Not a valid basis point amount\n");
Expand All @@ -727,11 +744,13 @@ static void handle_execute(ethPluginProvideParameter_t *msg, context_t *context)
// ######################

case INPUT_PERMIT2_LENGTH:
PRINTF("Interpreting as INPUT_PERMIT2_LENGTH\n");
context->permit2_length = U2BE(msg->parameter, PARAMETER_LENGTH - 2);
context->current_permit_read = 0;
context->next_param = INPUT_PERMIT2_SKIP_TOKEN;
break;
case INPUT_PERMIT2_SKIP_TOKEN:
PRINTF("Interpreting as INPUT_PERMIT2_SKIP_TOKEN\n");
context->current_permit_read += PARAMETER_LENGTH;
if (context->current_permit_read >= context->permit2_length) {
++context->current_command;
Expand All @@ -745,34 +764,41 @@ static void handle_execute(ethPluginProvideParameter_t *msg, context_t *context)
// Parsing V2_SWAP_EXACT_IN
// ########################
case INPUT_V2_SWAP_EXACT_IN_LENGTH:
PRINTF("Interpreting as INPUT_V2_SWAP_EXACT_IN_LENGTH\n");
if (check_or_set_swap_type(context, EXACT_IN) != 0) {
PRINTF("Error: check_or_set_swap_type failed for EXACT_IN\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
context->next_param = INPUT_V2_SWAP_EXACT_IN_RECIPIENT;
break;
case INPUT_V2_SWAP_EXACT_IN_RECIPIENT:
PRINTF("Interpreting as INPUT_V2_SWAP_EXACT_IN_RECIPIENT\n");
if (handle_recipient(msg->parameter, context) != 0) {
PRINTF("Error: handle_recipient failed\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
context->next_param = INPUT_V2_SWAP_EXACT_IN_AMOUNT_IN;
break;
case INPUT_V2_SWAP_EXACT_IN_AMOUNT_IN:
PRINTF("Interpreting as INPUT_V2_SWAP_EXACT_IN_AMOUNT_IN\n");
memmove(context->input.tmp_amount, msg->parameter, PARAMETER_LENGTH);
context->next_param = INPUT_V2_SWAP_EXACT_IN_AMOUNT_OUT_MIN;
break;
case INPUT_V2_SWAP_EXACT_IN_AMOUNT_OUT_MIN:
PRINTF("Interpreting as INPUT_V2_SWAP_EXACT_IN_AMOUNT_OUT_MIN\n");
memmove(context->output.tmp_amount, msg->parameter, PARAMETER_LENGTH);
context->next_param = INPUT_V2_SWAP_EXACT_IN_PATH_OFFSET;
break;
case INPUT_V2_SWAP_EXACT_IN_PATH_OFFSET:
PRINTF("Interpreting as INPUT_V2_SWAP_EXACT_IN_PATH_OFFSET\n");
context->next_param = INPUT_V2_SWAP_EXACT_IN_PAYER_IS_USER;
break;
case INPUT_V2_SWAP_EXACT_IN_PAYER_IS_USER:
PRINTF("Interpreting as INPUT_V2_SWAP_EXACT_IN_PAYER_IS_USER\n");
context->next_param = INPUT_V2_SWAP_EXACT_IN_PATH_LENGTH;
break;
case INPUT_V2_SWAP_EXACT_IN_PATH_LENGTH:
PRINTF("Interpreting as INPUT_V2_SWAP_EXACT_IN_PATH_LENGTH\n");
context->path_length = U2BE(msg->parameter, PARAMETER_LENGTH - 2);
if (context->path_length < 2) {
PRINTF("Path length is too small to make sense %d\n", context->path_length);
Expand All @@ -782,6 +808,7 @@ static void handle_execute(ethPluginProvideParameter_t *msg, context_t *context)
context->next_param = INPUT_V2_SWAP_EXACT_IN_PATH;
break;
case INPUT_V2_SWAP_EXACT_IN_PATH: {
PRINTF("Interpreting as INPUT_V2_SWAP_EXACT_IN_PATH\n");
bool finished;
if (parse_v2_path(context, msg->parameter, &finished) != 0) {
PRINTF("Failed to parse path for V2_SWAP_EXACT_IN\n");
Expand All @@ -803,34 +830,41 @@ static void handle_execute(ethPluginProvideParameter_t *msg, context_t *context)
// #########################

case INPUT_V2_SWAP_EXACT_OUT_LENGTH:
PRINTF("Interpreting as INPUT_V2_SWAP_EXACT_OUT_LENGTH\n");
if (check_or_set_swap_type(context, EXACT_OUT) != 0) {
PRINTF("Error: check_or_set_swap_type failed for EXACT_OUT\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
context->next_param = INPUT_V2_SWAP_EXACT_OUT_RECIPIENT;
break;
case INPUT_V2_SWAP_EXACT_OUT_RECIPIENT:
PRINTF("Interpreting as INPUT_V2_SWAP_EXACT_OUT_RECIPIENT\n");
if (handle_recipient(msg->parameter, context) != 0) {
PRINTF("Error: handle_recipient failed\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
context->next_param = INPUT_V2_SWAP_EXACT_OUT_AMOUNT_OUT;
break;
case INPUT_V2_SWAP_EXACT_OUT_AMOUNT_OUT:
PRINTF("Interpreting as INPUT_V2_SWAP_EXACT_OUT_AMOUNT_OUT\n");
memmove(context->output.tmp_amount, msg->parameter, PARAMETER_LENGTH);
context->next_param = INPUT_V2_SWAP_EXACT_OUT_AMOUNT_IN_MAX;
break;
case INPUT_V2_SWAP_EXACT_OUT_AMOUNT_IN_MAX:
PRINTF("Interpreting as INPUT_V2_SWAP_EXACT_OUT_AMOUNT_IN_MAX\n");
memmove(context->input.tmp_amount, msg->parameter, PARAMETER_LENGTH);
context->next_param = INPUT_V2_SWAP_EXACT_OUT_PATH_OFFSET;
break;
case INPUT_V2_SWAP_EXACT_OUT_PATH_OFFSET:
PRINTF("Interpreting as INPUT_V2_SWAP_EXACT_OUT_PATH_OFFSET\n");
context->next_param = INPUT_V2_SWAP_EXACT_OUT_PAYER_IS_USER;
break;
case INPUT_V2_SWAP_EXACT_OUT_PAYER_IS_USER:
PRINTF("Interpreting as INPUT_V2_SWAP_EXACT_OUT_PAYER_IS_USER\n");
context->next_param = INPUT_V2_SWAP_EXACT_OUT_PATH_LENGTH;
break;
case INPUT_V2_SWAP_EXACT_OUT_PATH_LENGTH:
PRINTF("Interpreting as INPUT_V2_SWAP_EXACT_OUT_PATH_LENGTH\n");
context->path_length = U2BE(msg->parameter, PARAMETER_LENGTH - 2);
if (context->path_length < 2) {
PRINTF("Path length is too small to make sense %d\n", context->path_length);
Expand All @@ -840,6 +874,7 @@ static void handle_execute(ethPluginProvideParameter_t *msg, context_t *context)
context->next_param = INPUT_V2_SWAP_EXACT_OUT_PATH;
break;
case INPUT_V2_SWAP_EXACT_OUT_PATH: {
PRINTF("Interpreting as INPUT_V2_SWAP_EXACT_OUT_PATH\n");
bool finished;
if (parse_v2_path(context, msg->parameter, &finished) != 0) {
PRINTF("Failed to parse path for V2_SWAP_EXACT_OUT\n");
Expand All @@ -861,34 +896,41 @@ static void handle_execute(ethPluginProvideParameter_t *msg, context_t *context)
// ########################

case INPUT_V3_SWAP_EXACT_IN_LENGTH:
PRINTF("Interpreting as INPUT_V3_SWAP_EXACT_IN_LENGTH\n");
if (check_or_set_swap_type(context, EXACT_IN) != 0) {
PRINTF("Error: check_or_set_swap_type failed for EXACT_IN\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
context->next_param = INPUT_V3_SWAP_EXACT_IN_RECIPIENT;
break;
case INPUT_V3_SWAP_EXACT_IN_RECIPIENT:
PRINTF("Interpreting as INPUT_V3_SWAP_EXACT_IN_RECIPIENT\n");
if (handle_recipient(msg->parameter, context) != 0) {
PRINTF("Error: handle_recipient failed\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
context->next_param = INPUT_V3_SWAP_EXACT_IN_AMOUNT_IN;
break;
case INPUT_V3_SWAP_EXACT_IN_AMOUNT_IN:
PRINTF("Interpreting as INPUT_V3_SWAP_EXACT_IN_AMOUNT_IN\n");
memmove(context->input.tmp_amount, msg->parameter, PARAMETER_LENGTH);
context->next_param = INPUT_V3_SWAP_EXACT_IN_AMOUNT_OUT_MIN;
break;
case INPUT_V3_SWAP_EXACT_IN_AMOUNT_OUT_MIN:
PRINTF("Interpreting as INPUT_V3_SWAP_EXACT_IN_AMOUNT_OUT_MIN\n");
memmove(context->output.tmp_amount, msg->parameter, PARAMETER_LENGTH);
context->next_param = INPUT_V3_SWAP_EXACT_IN_PATH_OFFSET;
break;
case INPUT_V3_SWAP_EXACT_IN_PATH_OFFSET:
PRINTF("Interpreting as INPUT_V3_SWAP_EXACT_IN_PATH_OFFSET\n");
context->next_param = INPUT_V3_SWAP_EXACT_IN_PAYER_IS_USER;
break;
case INPUT_V3_SWAP_EXACT_IN_PAYER_IS_USER:
PRINTF("Interpreting as INPUT_V3_SWAP_EXACT_IN_PAYER_IS_USER\n");
context->next_param = INPUT_V3_SWAP_EXACT_IN_PATH_LENGTH;
break;
case INPUT_V3_SWAP_EXACT_IN_PATH_LENGTH:
PRINTF("Interpreting as INPUT_V3_SWAP_EXACT_IN_PATH_LENGTH\n");
context->path_length = U2BE(msg->parameter, PARAMETER_LENGTH - 2);
if (!v3_path_length_is_valid(context->path_length)) {
PRINTF("Path length is invalid\n");
Expand All @@ -898,6 +940,7 @@ static void handle_execute(ethPluginProvideParameter_t *msg, context_t *context)
context->next_param = INPUT_V3_SWAP_EXACT_IN_PATH;
break;
case INPUT_V3_SWAP_EXACT_IN_PATH: {
PRINTF("Interpreting as INPUT_V3_SWAP_EXACT_IN_PATH\n");
bool finished;
if (parse_v3_path(context, msg->parameter, false, &finished) != 0) {
PRINTF("Failed to parse path for V3_SWAP_EXACT_IN\n");
Expand All @@ -918,34 +961,41 @@ static void handle_execute(ethPluginProvideParameter_t *msg, context_t *context)
// #########################

case INPUT_V3_SWAP_EXACT_OUT_LENGTH:
PRINTF("Interpreting as INPUT_V3_SWAP_EXACT_OUT_LENGTH\n");
if (check_or_set_swap_type(context, EXACT_OUT) != 0) {
PRINTF("Error: check_or_set_swap_type failed for EXACT_OUT\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
context->next_param = INPUT_V3_SWAP_EXACT_OUT_RECIPIENT;
break;
case INPUT_V3_SWAP_EXACT_OUT_RECIPIENT:
PRINTF("Interpreting as INPUT_V3_SWAP_EXACT_OUT_RECIPIENT\n");
if (handle_recipient(msg->parameter, context) != 0) {
PRINTF("Error: handle_recipient failed\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
context->next_param = INPUT_V3_SWAP_EXACT_OUT_AMOUNT_OUT;
break;
case INPUT_V3_SWAP_EXACT_OUT_AMOUNT_OUT:
PRINTF("Interpreting as INPUT_V3_SWAP_EXACT_OUT_AMOUNT_OUT\n");
memmove(context->output.tmp_amount, msg->parameter, PARAMETER_LENGTH);
context->next_param = INPUT_V3_SWAP_EXACT_OUT_AMOUNT_IN_MAX;
break;
case INPUT_V3_SWAP_EXACT_OUT_AMOUNT_IN_MAX:
PRINTF("Interpreting as INPUT_V3_SWAP_EXACT_OUT_AMOUNT_IN_MAX\n");
memmove(context->input.tmp_amount, msg->parameter, PARAMETER_LENGTH);
context->next_param = INPUT_V3_SWAP_EXACT_OUT_PATH_OFFSET;
break;
case INPUT_V3_SWAP_EXACT_OUT_PATH_OFFSET:
PRINTF("Interpreting as INPUT_V3_SWAP_EXACT_OUT_PATH_OFFSET\n");
context->next_param = INPUT_V3_SWAP_EXACT_OUT_PAYER_IS_USER;
break;
case INPUT_V3_SWAP_EXACT_OUT_PAYER_IS_USER:
PRINTF("Interpreting as INPUT_V3_SWAP_EXACT_OUT_PAYER_IS_USER\n");
context->next_param = INPUT_V3_SWAP_EXACT_OUT_PATH_LENGTH;
break;
case INPUT_V3_SWAP_EXACT_OUT_PATH_LENGTH:
PRINTF("Interpreting as INPUT_V3_SWAP_EXACT_OUT_PATH_LENGTH\n");
context->path_length = U2BE(msg->parameter, PARAMETER_LENGTH - 2);
if (!v3_path_length_is_valid(context->path_length)) {
PRINTF("Path length is invalid\n");
Expand All @@ -956,6 +1006,7 @@ static void handle_execute(ethPluginProvideParameter_t *msg, context_t *context)
break;

case INPUT_V3_SWAP_EXACT_OUT_PATH: {
PRINTF("Interpreting as INPUT_V3_SWAP_EXACT_OUT_PATH\n");
bool finished;
if (parse_v3_path(context, msg->parameter, true, &finished) != 0) {
PRINTF("Failed to parse path for V3_SWAP_EXACT_OUT\n");
Expand Down

0 comments on commit 583a74d

Please sign in to comment.