Skip to content

Commit

Permalink
Merge pull request #23 from blooo-io/fix/add-valid-variable
Browse files Browse the repository at this point in the history
Fix/add-valid-variable
  • Loading branch information
GuilaneDen authored Mar 8, 2023
2 parents d4a4adb + a80dc78 commit 8dffb87
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 72 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ APP_LOAD_PARAMS += $(COMMON_LOAD_PARAMS)

APPVERSION_M = 1
APPVERSION_N = 0
APPVERSION_P = 4
APPVERSION_P = 5
APPVERSION = "$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)"

APPNAME = "APWine"
Expand Down
8 changes: 4 additions & 4 deletions src/apwine_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ extern const contract_address_future_vault_t
#define PAIR_PATH_LAST 8
#define TOKEN_PATH_SENT 9
#define TOKEN_PATH_RECEIVED 10
#define NONE 11

// Number of decimals used when the token wasn't found in the CAL.
#define DEFAULT_DECIMAL WEI_TO_ETHER
Expand All @@ -137,12 +136,13 @@ typedef struct apwine_parameters_t {
char ticker_sent[MAX_TICKER_LEN];
char ticker_received[MAX_TICKER_LEN];

// 32 * 2 + 20 * 2 + 12 * 2 == 64 + 40 + 24 == 128
// 32 * 5 == 160 bytes so there are 160 - 128 == 32 bytes left.
// 32 * 2 + 20 * 2 + 11 * 2 == 64 + 40 + 22 == 126
// 32 * 5 == 160 bytes so there are 160 - 126 == 34 bytes left.

uint16_t offset;
uint16_t checkpoint;
uint16_t array_len;
uint8_t valid;
uint8_t next_param;
uint8_t tokens_found;
uint8_t decimals_sent;
Expand All @@ -153,7 +153,7 @@ typedef struct apwine_parameters_t {
uint8_t token_path_sent;
uint8_t token_path_received;
uint8_t skip;
// 11 * 1b + 2 * 2b == 12 + 4 == 16 bytes. There are 32 - 15 == 17 byte left.
// 11 * 1b + 3 * 2b == 11 + 6 == 17 bytes. There are 34 - 17 == 17 byte left.
} apwine_parameters_t;

// Piece of code that will check that the above structure is not bigger than 5 * 32. Do not remove
Expand Down
84 changes: 44 additions & 40 deletions src/handle_finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,52 @@ static void received_network_token(apwine_parameters_t *context) {
void handle_finalize(void *parameters) {
ethPluginFinalize_t *msg = (ethPluginFinalize_t *) parameters;
apwine_parameters_t *context = (apwine_parameters_t *) msg->pluginContext;
if (context->valid) {
switch (context->selectorIndex) {
case REDEEM_YIELD:
msg->numScreens = 0;
break;
case INCREASE_AMOUNT:
case INCERASE_UNLOCK_TIME:
msg->numScreens = 1;
break;
case SWAP_EXACT_AMOUNT_IN:
case SWAP_EXACT_AMOUNT_OUT:
case ZAPINTOPT:
msg->numScreens = 4;
break;
default:
msg->numScreens = 2;
break;
}

switch (context->selectorIndex) {
case REDEEM_YIELD:
msg->numScreens = 0;
break;
case INCREASE_AMOUNT:
case INCERASE_UNLOCK_TIME:
msg->numScreens = 1;
break;
case SWAP_EXACT_AMOUNT_IN:
case SWAP_EXACT_AMOUNT_OUT:
case ZAPINTOPT:
msg->numScreens = 4;
break;
default:
msg->numScreens = 2;
break;
}
if (!ADDRESS_IS_NETWORK_TOKEN(context->contract_address_sent)) {
// Address is not network token (0xeee...) so we will need to look up the token in the
// CAL.
printf_hex_array("Setting address sent to: ",
ADDRESS_LENGTH,
context->contract_address_sent);
msg->tokenLookup1 = context->contract_address_sent;
} else {
sent_network_token(context);
msg->tokenLookup1 = NULL;
}
if (!ADDRESS_IS_NETWORK_TOKEN(context->contract_address_received)) {
// Address is not network token (0xeee...) so we will need to look up the token in the
// CAL.
printf_hex_array("Setting address received to: ",
ADDRESS_LENGTH,
context->contract_address_received);
msg->tokenLookup2 = context->contract_address_received;
} else {
received_network_token(context);
msg->tokenLookup2 = NULL;
}

if (!ADDRESS_IS_NETWORK_TOKEN(context->contract_address_sent)) {
// Address is not network token (0xeee...) so we will need to look up the token in the
// CAL.
printf_hex_array("Setting address sent to: ",
ADDRESS_LENGTH,
context->contract_address_sent);
msg->tokenLookup1 = context->contract_address_sent;
} else {
sent_network_token(context);
msg->tokenLookup1 = NULL;
}
if (!ADDRESS_IS_NETWORK_TOKEN(context->contract_address_received)) {
// Address is not network token (0xeee...) so we will need to look up the token in the
// CAL.
printf_hex_array("Setting address received to: ",
ADDRESS_LENGTH,
context->contract_address_received);
msg->tokenLookup2 = context->contract_address_received;
msg->uiType = ETH_UI_TYPE_GENERIC;
msg->result = ETH_PLUGIN_RESULT_OK;
} else {
received_network_token(context);
msg->tokenLookup2 = NULL;
PRINTF("Context not valid\n");
msg->result = ETH_PLUGIN_RESULT_FALLBACK;
}

msg->uiType = ETH_UI_TYPE_GENERIC;
msg->result = ETH_PLUGIN_RESULT_OK;
}
1 change: 1 addition & 0 deletions src/handle_init_contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void handle_init_contract(void *parameters) {

apwine_parameters_t *context = (apwine_parameters_t *) msg->pluginContext;
memset(context, 0, sizeof(*context));
context->valid = 0;

// Determine a function to call
size_t i;
Expand Down
46 changes: 23 additions & 23 deletions src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ static void handle_token_received(ethPluginProvideParameter_t *msg, apwine_param
}

static void handle_array_length(ethPluginProvideParameter_t *msg, apwine_parameters_t *context) {
U2BE_from_parameter(msg->parameter, &(context->array_len));
if (!U2BE_from_parameter(msg->parameter, &(context->array_len))) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
PRINTF("LIST LEN: %d\n", context->array_len);
}

Expand Down Expand Up @@ -81,7 +83,7 @@ static void handle_swap_exact_amount(ethPluginProvideParameter_t *msg,
if (context->array_len <= 1) {
context->skip = 1; // skip _tokenPath length
context->next_param = TOKEN_PATH_SENT;
} else if (context->array_len <= 2) {
} else {
context->next_param = PAIR_PATH_LAST;
}
break;
Expand All @@ -102,9 +104,8 @@ static void handle_swap_exact_amount(ethPluginProvideParameter_t *msg,
break;
case TOKEN_PATH_RECEIVED: // _tokenPath[length-2]
handle_token_path_received(msg, context);
context->next_param = NONE;
break;
case NONE:
// When all parameters are parsed
context->valid = 1;
break;
default:
PRINTF("Param not supported\n");
Expand All @@ -126,6 +127,8 @@ static void handle_remove_liquidity(ethPluginProvideParameter_t *msg,
handle_amount_received(msg, context);
// We call the handle_token method to print "Unknown Token"
handle_token_received(msg, context);
// When all parameters are parsed
context->valid = 1;
break;
default:
PRINTF("Param not supported\n");
Expand All @@ -146,9 +149,8 @@ static void handle_add_liquidity(ethPluginProvideParameter_t *msg, apwine_parame
handle_amount_received(msg, context);
// We call the handle_token method to print "Unknown Token"
handle_token_received(msg, context);
context->next_param = NONE;
break;
case NONE:
// When all parameters are parsed
context->valid = 1;
break;
default:
PRINTF("Param not supported\n");
Expand All @@ -166,9 +168,8 @@ static void handle_deposit_withdraw(ethPluginProvideParameter_t *msg,
break;
case AMOUNT_SENT: // _amount
handle_amount_sent(msg, context);
context->next_param = NONE;
break;
case NONE:
// When all parameters are parsed
context->valid = 1;
break;
default:
PRINTF("Param not supported\n");
Expand All @@ -190,9 +191,9 @@ static void handle_zapintopt(ethPluginProvideParameter_t *msg, apwine_parameters
break;
case AMOUNT_RECEIVED: // _inputs[0]
handle_amount_received(msg, context);
context->next_param = NONE;
break;
case NONE:
context->skip++; // skip _inputs[1]
// When all parameters are parsed
context->valid = 1;
break;
default:
PRINTF("Param not supported\n");
Expand All @@ -207,9 +208,8 @@ static void handle_increase_amount(ethPluginProvideParameter_t *msg, apwine_para
handle_amount_sent(msg, context);
// We call the handle_token method to print "Unknown Token"
handle_token_sent(msg, context);
context->next_param = NONE;
break;
case NONE:
// When all parameters are parsed
context->valid = 1;
break;
default:
PRINTF("Param not supported\n");
Expand All @@ -228,9 +228,8 @@ static void handle_create_lock(ethPluginProvideParameter_t *msg, apwine_paramete
break;
case AMOUNT_RECEIVED: // _unlock_time
handle_amount_received(msg, context);
context->next_param = NONE;
break;
case NONE:
// When all parameters are parsed
context->valid = 1;
break;
default:
PRINTF("Param not supported\n");
Expand All @@ -244,9 +243,8 @@ static void handle_increase_unlock_time(ethPluginProvideParameter_t *msg,
switch (context->next_param) {
case AMOUNT_SENT: // _unlock_time
handle_amount_sent(msg, context);
context->next_param = NONE;
break;
case NONE:
// When all parameters are parsed
context->valid = 1;
break;
default:
PRINTF("Param not supported\n");
Expand Down Expand Up @@ -303,6 +301,8 @@ void handle_provide_parameter(void *parameters) {
handle_increase_unlock_time(msg, context);
break;
case REDEEM_YIELD:
// When all parameters are parsed
context->valid = 1;
break;
default:
PRINTF("Selector Index %d not supported\n", context->selectorIndex);
Expand Down
8 changes: 4 additions & 4 deletions src/handle_query_contract_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ static void set_receive_ticker_ui(ethQueryContractUI_t *msg, apwine_parameters_t
} else {
if (context->pair_path_last == 0) {
if (context->token_path_received == 0) {
strlcpy(msg->msg, currentToken->ticker_underlying, msg->msgLength);
} else if (context->token_path_received == 1) {
strlcpy(msg->msg, currentToken->ticker_pt, msg->msgLength);
} else if (context->token_path_received == 1) {
strlcpy(msg->msg, currentToken->ticker_underlying, msg->msgLength);
}
} else {
if (context->token_path_received == 0) {
strlcpy(msg->msg, currentToken->ticker_fyt, msg->msgLength);
} else if (context->token_path_received == 1) {
strlcpy(msg->msg, currentToken->ticker_pt, msg->msgLength);
} else if (context->token_path_received == 1) {
strlcpy(msg->msg, currentToken->ticker_fyt, msg->msgLength);
}
}
}
Expand Down
Binary file removed tests/elfs/apwine_nanos.elf
Binary file not shown.
Binary file removed tests/elfs/apwine_nanosp.elf
Binary file not shown.
Binary file removed tests/elfs/apwine_nanox.elf
Binary file not shown.
Binary file removed tests/elfs/ethereum_nanos.elf
Binary file not shown.
Binary file removed tests/elfs/ethereum_nanosp.elf
Binary file not shown.
Binary file removed tests/elfs/ethereum_nanox.elf
Binary file not shown.

0 comments on commit 8dffb87

Please sign in to comment.