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

feat/Ldg 653 implement method create reward vault #3

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes
File renamed without changes
File renamed without changes
15 changes: 9 additions & 6 deletions src/handle_finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ void handle_finalize(ethPluginFinalize_t *msg) {

msg->uiType = ETH_UI_TYPE_GENERIC;

// EDIT THIS: Set the total number of screen you will need.
msg->numScreens = 2;
// EDIT THIS: Handle this case like you wish to (i.e. maybe no additional screen needed?).
// If the beneficiary is NOT the sender, we will need an additional screen to display it.
if (memcmp(msg->address, context->beneficiary, ADDRESS_LENGTH) != 0) {
msg->numScreens += 1;
switch (context->selectorIndex) {
case CREATE_REWARD_VAULT:
case DELEGATE:
msg->numScreens = 1;
break;
default:
PRINTF("Selector index: %d not supported\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}

// EDIT THIS: set `tokenLookup1` (and maybe `tokenLookup2`) to point to
Expand Down
8 changes: 3 additions & 5 deletions src/handle_init_contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ void handle_init_contract(ethPluginInitContract_t *msg) {
// EDIT THIS: Adapt the `cases`, and set the `next_param` to be the first parameter you expect
// to parse.
switch (context->selectorIndex) {
case SWAP_EXACT_ETH_FOR_TOKENS:
context->next_param = MIN_AMOUNT_RECEIVED;
break;
case BOILERPLATE_DUMMY_2:
context->next_param = TOKEN_RECEIVED;
case CREATE_REWARD_VAULT:
case DELEGATE:
context->next_param = BENEFICIARY;
break;
// Keep this
default:
Expand Down
52 changes: 21 additions & 31 deletions src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
@@ -1,39 +1,28 @@
#include "plugin.h"

// EDIT THIS: Remove this function and write your own handlers!
static void handle_swap_exact_eth_for_tokens(ethPluginProvideParameter_t *msg, context_t *context) {
if (context->go_to_offset) {
if (msg->parameterOffset != context->offset + SELECTOR_SIZE) {
return;
}
context->go_to_offset = false;
}
static void handle_delegate(ethPluginProvideParameter_t *msg, context_t *context) {
switch (context->next_param) {
case MIN_AMOUNT_RECEIVED: // amountOutMin
copy_parameter(context->amount_received,
msg->parameter,
sizeof(context->amount_received));
context->next_param = PATH_OFFSET;
case BENEFICIARY:
copy_address(context->beneficiary, msg->parameter, sizeof(context->beneficiary));
context->next_param = NONE;
break;
case PATH_OFFSET: // path
context->offset = U2BE(msg->parameter, PARAMETER_LENGTH - 2);
context->next_param = BENEFICIARY;
case NONE:
break;
case BENEFICIARY: // to
copy_address(context->beneficiary, msg->parameter, sizeof(context->beneficiary));
context->next_param = PATH_LENGTH;
context->go_to_offset = true;
default:
PRINTF("Param not supported: %d\n", context->next_param);
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
case PATH_LENGTH:
context->offset = msg->parameterOffset - SELECTOR_SIZE + PARAMETER_LENGTH * 2;
context->go_to_offset = true;
context->next_param = TOKEN_RECEIVED;
}
}

static void handle_create_reward_vault(ethPluginProvideParameter_t *msg, context_t *context) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est de la duplication de code, le handle_create_reward_vault et handle_delegate font la même chose. Peut-être, renommé la fonction en handle_beneficiary() et l'utiliser pour les deux méthodes

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GuilaneDen ça devrait être fix :)

switch (context->next_param) {
case BENEFICIARY:
copy_address(context->beneficiary, msg->parameter, sizeof(context->beneficiary));
context->next_param = NONE;
break;
case TOKEN_RECEIVED: // path[1] -> contract address of token received
copy_address(context->token_received, msg->parameter, sizeof(context->token_received));
context->next_param = UNEXPECTED_PARAMETER;
case NONE:
break;
// Keep this
default:
PRINTF("Param not supported: %d\n", context->next_param);
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand All @@ -55,10 +44,11 @@ void handle_provide_parameter(ethPluginProvideParameter_t *msg) {

// EDIT THIS: adapt the cases and the names of the functions.
switch (context->selectorIndex) {
case SWAP_EXACT_ETH_FOR_TOKENS:
handle_swap_exact_eth_for_tokens(msg, context);
case CREATE_REWARD_VAULT:
handle_create_reward_vault(msg, context);
break;
case BOILERPLATE_DUMMY_2:
case DELEGATE:
handle_delegate(msg, context);
break;
default:
PRINTF("Selector Index not supported: %d\n", context->selectorIndex);
Expand Down
19 changes: 13 additions & 6 deletions src/handle_query_contract_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ void handle_query_contract_id(ethQueryContractID_t *msg) {
strlcpy(msg->name, APPNAME, msg->nameLength);

// EDIT THIS: Adapt the cases by modifying the strings you pass to `strlcpy`.
if (context->selectorIndex == SWAP_EXACT_ETH_FOR_TOKENS) {
strlcpy(msg->version, "Swap", msg->versionLength);
msg->result = ETH_PLUGIN_RESULT_OK;
} else {
PRINTF("Selector index: %d not supported\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
switch (context->selectorIndex) {
case CREATE_REWARD_VAULT:
strlcpy(msg->version, "Create Reward Vault", msg->versionLength);
msg->result = ETH_PLUGIN_RESULT_OK;
break;
case DELEGATE:
strlcpy(msg->version, "Delegate", msg->versionLength);
msg->result = ETH_PLUGIN_RESULT_OK;
break;
default:
PRINTF("Selector index: %d not supported\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
}
45 changes: 28 additions & 17 deletions src/handle_query_contract_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

// Set UI for the "Send" screen.
// EDIT THIS: Adapt / remove this function to your needs.
static bool set_send_ui(ethQueryContractUI_t *msg) {
/* static bool set_send_ui(ethQueryContractUI_t *msg) {
strlcpy(msg->title, "Send", msg->titleLength);

const uint8_t *eth_amount = msg->pluginSharedRO->txContent->value.value;
Expand All @@ -19,11 +19,11 @@ static bool set_send_ui(ethQueryContractUI_t *msg) {
"ETH",
msg->msg,
msg->msgLength);
}
} */

// Set UI for "Receive" screen.
// EDIT THIS: Adapt / remove this function to your needs.
static bool set_receive_ui(ethQueryContractUI_t *msg, const context_t *context) {
/* static bool set_receive_ui(ethQueryContractUI_t *msg, const context_t *context) {
strlcpy(msg->title, "Receive Min.", msg->titleLength);

uint8_t decimals = context->decimals;
Expand All @@ -41,12 +41,21 @@ static bool set_receive_ui(ethQueryContractUI_t *msg, const context_t *context)
ticker,
msg->msg,
msg->msgLength);
}
} */

// Set UI for "Beneficiary" screen.
// EDIT THIS: Adapt / remove this function to your needs.
static bool set_beneficiary_ui(ethQueryContractUI_t *msg, context_t *context) {
strlcpy(msg->title, "Beneficiary", msg->titleLength);
switch (context->selectorIndex) {
case CREATE_REWARD_VAULT:
strlcpy(msg->title, "Address", msg->titleLength);
break;
case DELEGATE:
strlcpy(msg->title, "Beneficiary", msg->titleLength);
break;
default:
PRINTF("Received an invalid selectorIndex\n");
break;
}

// Prefix the address with `0x`.
msg->msg[0] = '0';
Expand Down Expand Up @@ -76,19 +85,21 @@ void handle_query_contract_ui(ethQueryContractUI_t *msg) {
memset(msg->msg, 0, msg->msgLength);

// EDIT THIS: Adapt the cases for the screens you'd like to display.
switch (msg->screenIndex) {
case 0:
ret = set_send_ui(msg);
break;
case 1:
ret = set_receive_ui(msg, context);
switch (context->selectorIndex) {
case CREATE_REWARD_VAULT:
case DELEGATE:
switch (msg->screenIndex) {
case 0:
ret = set_beneficiary_ui(msg, context);
break;
default:
PRINTF("Received an invalid screenIndex\n");
break;
}
break;
case 2:
ret = set_beneficiary_ui(msg, context);
break;
// Keep this
default:
PRINTF("Received an invalid screenIndex\n");
PRINTF("Received an invalid selectorIndex\n");
break;
}
msg->result = ret ? ETH_PLUGIN_RESULT_OK : ETH_PLUGIN_RESULT_ERROR;
}
7 changes: 4 additions & 3 deletions src/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
// A Xmacro below will create for you:
// - an enum named selector_t with every NAME
// - a map named SELECTORS associating each NAME with it's value
#define SELECTORS_LIST(X) \
X(SWAP_EXACT_ETH_FOR_TOKENS, 0x7ff36ab5) \
X(BOILERPLATE_DUMMY_2, 0x13374242)
#define SELECTORS_LIST(X) \
X(CREATE_REWARD_VAULT, 0x577ee5c7) \
X(DELEGATE, 0x5c19a95c)

// Xmacro helpers to define the enum and map
// Do not modify !
Expand All @@ -54,6 +54,7 @@ typedef enum {
PATH_OFFSET,
PATH_LENGTH,
UNEXPECTED_PARAMETER,
NONE,
} parameter;

// Shared global memory with Ethereum app. Must be at most 5 * 32 bytes.
Expand Down
Empty file.
36 changes: 0 additions & 36 deletions tests/abis/0x000102030405060708090a0b0c0d0e0f10111213.abi.json

This file was deleted.

Loading
Loading