Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temp/run ci #32

Closed
wants to merge 14 commits into from
Closed
1 change: 0 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ SortIncludes: false
SpaceAfterCStyleCast: true
AllowShortCaseLabelsOnASingleLine: false
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortFunctionsOnASingleLine: None
BinPackArguments: false
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ jobs:
with:
repository: LedgerHQ/app-ethereum
ref: ${{ ((github.base_ref || github.ref_name) == 'main' && 'master') || (github.base_ref || github.ref_name) }}
submodules: true

- name: Build
run: |
Expand Down
155 changes: 80 additions & 75 deletions src/handle_query_contract_ui.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include <stdbool.h>
#include "stakekit_plugin.h"

// Set UI for the "Send" screen.
// Each methods sets the title and the message to be displayed on the screen.
static void set_send_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
static bool set_send_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
switch (context->selectorIndex) {
case DEPOSIT_SELF_APECOIN:
case SWAP_FROM:
Expand Down Expand Up @@ -63,62 +64,66 @@ static void set_send_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context)
break;
default:
PRINTF("Unhandled selector Index: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
return false;
}

// Convert to string.
amountToString(context->amount_sent,
INT256_LENGTH,
context->decimals_sent,
context->ticker_sent,
msg->msg,
msg->msgLength);
if (!amountToString(context->amount_sent,
INT256_LENGTH,
context->decimals_sent,
context->ticker_sent,
msg->msg,
msg->msgLength)) {
return false;
}
PRINTF("AMOUNT SENT: %s\n", msg->msg);
return true;
}

// Same as the "set_send_ui" function. However the value is extracted from the pluginSharedRO.
static void set_send_value_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
static bool set_send_value_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
switch (context->selectorIndex) {
case STAKE:
strlcpy(msg->title, "Send", msg->titleLength);
break;
default:
PRINTF("Unhandled selector Index: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
return false;
}

if (msg->pluginSharedRO == NULL) {
PRINTF("Error: msg->pluginSharedRO is NULL\n");
return;
return false;
}
if (msg->pluginSharedRO->txContent == NULL) {
PRINTF("Error: msg->pluginSharedRO->txContent is NULL\n");
return;
return false;
}

// Convert to string.
amountToString(msg->pluginSharedRO->txContent->value.value,
msg->pluginSharedRO->txContent->value.length,
context->decimals_sent,
context->ticker_sent,
msg->msg,
msg->msgLength);
if (!amountToString(msg->pluginSharedRO->txContent->value.value,
msg->pluginSharedRO->txContent->value.length,
context->decimals_sent,
context->ticker_sent,
msg->msg,
msg->msgLength)) {
return false;
}
PRINTF("AMOUNT SENT: %s\n", msg->msg);
return true;
}

// Set UI for "Send 2" screen.
// Each methods sets the title and the message to be displayed on the screen.
static void set_send_2_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
static bool set_send_2_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
switch (context->selectorIndex) {
case LIDO_CLAIM_WITHDRAWALS:
strlcpy(msg->title, "Request ID", msg->titleLength);
break;
default:
PRINTF("Unhandled selector Index: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
return false;
}

amountToString(context->contract_address, // Location of the 2nd request ID.
Expand All @@ -127,11 +132,12 @@ static void set_send_2_ui(ethQueryContractUI_t *msg, plugin_parameters_t *contex
context->ticker_sent,
msg->msg,
msg->msgLength);
return true;
}

// Set UI for "Receive" screen.
// Each methods sets the title and the message to be displayed on the screen.
static void set_receive_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
static bool set_receive_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
switch (context->selectorIndex) {
case WITHDRAW_SELF_APECOIN:
case SWAP_TO:
Expand All @@ -149,31 +155,33 @@ static void set_receive_ui(ethQueryContractUI_t *msg, plugin_parameters_t *conte
break;
default:
PRINTF("Unhandled selector Index: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
return false;
}

// Convert to string.
amountToString(context->amount_received,
INT256_LENGTH,
context->decimals_received,
context->ticker_received,
msg->msg,
msg->msgLength);
if (!amountToString(context->amount_received,
INT256_LENGTH,
context->decimals_received,
context->ticker_received,
msg->msg,
msg->msgLength)) {
return false;
}
PRINTF("AMOUNT RECEIVED: %s\n", msg->msg);
return true;
}

// Set UI for "Receive 2" screen.
// Each methods sets the title and the message to be displayed on the screen.
static void set_receive_2_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
static bool set_receive_2_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
switch (context->selectorIndex) {
case LIDO_CLAIM_WITHDRAWALS:
strlcpy(msg->title, "Hint", msg->titleLength);
break;
default:
PRINTF("Unhandled selector Index: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
return false;
}

amountToString(context->recipient, // Location of the 2nd hint.
Expand All @@ -182,12 +190,13 @@ static void set_receive_2_ui(ethQueryContractUI_t *msg, plugin_parameters_t *con
context->ticker_sent,
msg->msg,
msg->msgLength);
return true;
}

// Utility function to print an address to the UI.
static void print_address(ethQueryContractUI_t *msg, uint8_t *address) {
static bool print_address(ethQueryContractUI_t *msg, uint8_t *address) {
if (msg == NULL || msg->msgLength <= MIN_MSG_LENGTH) {
return;
return false;
}
// Prefix the address with `0x`.
msg->msg[0] = '0';
Expand All @@ -199,15 +208,15 @@ static void print_address(ethQueryContractUI_t *msg, uint8_t *address) {

// Get the string representation of the address stored in `context->beneficiary`. Put it in
// `msg->msg`.
getEthAddressStringFromBinary(
return getEthAddressStringFromBinary(
address,
msg->msg + 2, // +2 here because we've already prefixed with '0x'.
chainid);
}

// Set UI for "Recipient" screen.
// Each methods sets the title and the message to be displayed on the screen.
static void set_recipient_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
static bool set_recipient_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
switch (context->selectorIndex) {
case SUBMIT_MATIC_LIDO:
case REQUEST_WITHDRAW:
Expand Down Expand Up @@ -250,17 +259,16 @@ static void set_recipient_ui(ethQueryContractUI_t *msg, plugin_parameters_t *con
break;
default:
PRINTF("Unhandled selector Index: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
return false;
}

print_address(msg, context->recipient);
return print_address(msg, context->recipient);
}

// Set UI for "Recipient 2" screen. When having more than one recipient.
// The recipient address is saved in the contract_address
// Each methods sets the title and the message to be displayed on the screen.
static void set_recipient_2_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
static bool set_recipient_2_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
switch (context->selectorIndex) {
case COMET_CLAIM:
strlcpy(msg->title, "Comet Protocol", msg->titleLength);
Expand All @@ -274,34 +282,32 @@ static void set_recipient_2_ui(ethQueryContractUI_t *msg, plugin_parameters_t *c
break;
default:
PRINTF("Unhandled selector Index: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
return false;
}

print_address(msg, context->contract_address);
return print_address(msg, context->contract_address);
}

// Set UI for "Recipient 2" screen. When having more than two recipients.
// The recipient address is saved in the amount_received
// Each methods sets the title and the message to be displayed on the screen.
static void set_recipient_3_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
static bool set_recipient_3_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
switch (context->selectorIndex) {
case VOTE:
case REVOKE_ACTIVE:
strlcpy(msg->title, "Greater Group", msg->titleLength);
break;
default:
PRINTF("Unhandled selector Index: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
return false;
}

print_address(msg, context->amount_received);
return print_address(msg, context->amount_received);
}

// Set UI for smart contract address screen.
// Each methods sets the title and the message to be displayed on the screen.
static void set_smart_contract_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
static bool set_smart_contract_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
switch (context->selectorIndex) {
case CLAIM_SELF_APECOIN:
case CREATE_ACCOUNT:
Expand All @@ -316,46 +322,46 @@ static void set_smart_contract_ui(ethQueryContractUI_t *msg, plugin_parameters_t
break;
default:
PRINTF("Unhandled selector Index: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
return false;
}

if (msg->pluginSharedRO == NULL) {
PRINTF("Error: msg->pluginSharedRO is NULL\n");
return;
return false;
}
if (msg->pluginSharedRO->txContent == NULL) {
PRINTF("Error: msg->pluginSharedRO->txContent is NULL\n");
return;
return false;
}

print_address(msg, msg->pluginSharedRO->txContent->destination);
return print_address(msg, msg->pluginSharedRO->txContent->destination);
}

// Set UI for unbound nonce boolean screen.
// Each methods sets the title and the message to be displayed on the screen.
static void set_unbound_nonce_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
static bool set_unbound_nonce_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
switch (context->selectorIndex) {
case UNSTAKE_CLAIM_TOKENS_NEW:
strlcpy(msg->title, "Unbound Nonce", msg->titleLength);
break;
default:
PRINTF("Unhandled selector Index: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
return false;
}
if (context->unbound_nonce == 0) {
strlcpy(msg->msg, "False", msg->msgLength);
} else {
strlcpy(msg->msg, "True", msg->msgLength);
}
return true;
}

// Set UI for "Warning" screen.
static void set_warning_ui(ethQueryContractUI_t *msg,
static bool set_warning_ui(ethQueryContractUI_t *msg,
const plugin_parameters_t *context __attribute__((unused))) {
strlcpy(msg->title, "WARNING", msg->titleLength);
strlcpy(msg->msg, "Unknown token", msg->msgLength);
return true;
}

// Set UI for the methods needing a send screen.
Expand Down Expand Up @@ -658,51 +664,50 @@ static screens_t get_screen(ethQueryContractUI_t *msg,
}

// Set the UI according to the screen that needs to be displayed.
void handle_query_contract_ui(void *parameters) {
ethQueryContractUI_t *msg = (ethQueryContractUI_t *) parameters;
void handle_query_contract_ui(ethQueryContractUI_t *msg) {
plugin_parameters_t *context = (plugin_parameters_t *) msg->pluginContext;
bool ret = false;

(void) memset(msg->title, 0, msg->titleLength);
(void) memset(msg->msg, 0, msg->msgLength);

screens_t screen = get_screen(msg, context);
switch (screen) {
case SEND_SCREEN:
set_send_ui(msg, context);
ret = set_send_ui(msg, context);
break;
case SEND_VALUE_SCREEN:
set_send_value_ui(msg, context);
ret = set_send_value_ui(msg, context);
break;
case RECEIVE_SCREEN:
set_receive_ui(msg, context);
ret = set_receive_ui(msg, context);
break;
case RECIPIENT_SCREEN:
set_recipient_ui(msg, context);
ret = set_recipient_ui(msg, context);
break;
case RECIPIENT_2_SCREEN:
set_recipient_2_ui(msg, context);
ret = set_recipient_2_ui(msg, context);
break;
case RECIPIENT_3_SCREEN:
set_recipient_3_ui(msg, context);
ret = set_recipient_3_ui(msg, context);
break;
case SMART_CONTRACT_SCREEN:
set_smart_contract_ui(msg, context);
ret = set_smart_contract_ui(msg, context);
break;
case UNBOUND_NONCE_SCREEN:
set_unbound_nonce_ui(msg, context);
ret = set_unbound_nonce_ui(msg, context);
break;
case SEND_2_SCREEN:
set_send_2_ui(msg, context);
ret = set_send_2_ui(msg, context);
break;
case RECEIVE_2_SCREEN:
set_receive_2_ui(msg, context);
ret = set_receive_2_ui(msg, context);
break;
case WARN_SCREEN:
set_warning_ui(msg, context);
ret = set_warning_ui(msg, context);
break;
default:
PRINTF("Received an invalid screenIndex %d\n", screen);
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
break;
}
msg->result = ETH_PLUGIN_RESULT_OK;
msg->result = ret ? ETH_PLUGIN_RESULT_OK : ETH_PLUGIN_RESULT_ERROR;
}
Loading