Skip to content

Commit

Permalink
Merge pull request #6 from blooo-io/feat/LDG-650-implement-method-mint
Browse files Browse the repository at this point in the history
Feat/ldg 650 implement method mint
  • Loading branch information
Steven2505 authored Jan 22, 2025
2 parents b5a2c92 + 07c8df4 commit f9d278a
Show file tree
Hide file tree
Showing 38 changed files with 2,166 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/handle_finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ void handle_finalize(ethPluginFinalize_t *msg) {
case DELEGATE:
msg->numScreens = 1;
break;
case MINT:
msg->numScreens = 4;
break;
default:
PRINTF("Selector index: %d not supported\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand Down
3 changes: 3 additions & 0 deletions src/handle_init_contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ void handle_init_contract(ethPluginInitContract_t *msg) {
case DELEGATE:
context->next_param = BENEFICIARY;
break;
case MINT:
context->next_param = ADDRESS;
break;
// Keep this
default:
PRINTF("Missing selectorIndex: %d\n", context->selectorIndex);
Expand Down
34 changes: 34 additions & 0 deletions src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,37 @@ static void handle_beneficiary(ethPluginProvideParameter_t *msg, context_t *cont
}
}

static void handle_mint(ethPluginProvideParameter_t *msg, context_t *context) {
switch (context->next_param) {
case ADDRESS:
copy_address(context->address, msg->parameter, sizeof(context->address));
context->next_param = MIN_AMOUNT_RECEIVED;
break;
case MIN_AMOUNT_RECEIVED:
copy_parameter(context->amount_received,
msg->parameter,
sizeof(context->amount_received));
context->next_param = BENEFICIARY;
break;
case BENEFICIARY:
copy_address(context->beneficiary, msg->parameter, sizeof(context->beneficiary));
context->next_param = BOOLEAN;
break;
case BOOLEAN:
if (!U2BE_from_parameter(msg->parameter, &context->boolean)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
context->next_param = NONE;
break;
case NONE:
break;
default:
PRINTF("Param not supported: %d\n", context->next_param);
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
}

void handle_provide_parameter(ethPluginProvideParameter_t *msg) {
context_t *context = (context_t *) msg->pluginContext;
// We use `%.*H`: it's a utility function to print bytes. You first give
Expand All @@ -32,6 +63,9 @@ void handle_provide_parameter(ethPluginProvideParameter_t *msg) {
case DELEGATE:
handle_beneficiary(msg, context);
break;
case MINT:
handle_mint(msg, context);
break;
default:
PRINTF("Selector Index not supported: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand Down
4 changes: 4 additions & 0 deletions src/handle_query_contract_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ void handle_query_contract_id(ethQueryContractID_t *msg) {
strlcpy(msg->version, "Delegate", msg->versionLength);
msg->result = ETH_PLUGIN_RESULT_OK;
break;
case MINT:
strlcpy(msg->version, "Mint", 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;
Expand Down
70 changes: 67 additions & 3 deletions src/handle_query_contract_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

// 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) {
strlcpy(msg->title, "Receive Min.", msg->titleLength);
static bool set_receive_ui(ethQueryContractUI_t *msg, const context_t *context) {
strlcpy(msg->title, "Amount", msg->titleLength);

uint8_t decimals = context->decimals;
const char *ticker = context->ticker;
Expand All @@ -41,7 +41,7 @@
ticker,
msg->msg,
msg->msgLength);
} */
}

// Set UI for "Beneficiary" screen.
static bool set_beneficiary_ui(ethQueryContractUI_t *msg, context_t *context) {
Expand All @@ -50,6 +50,7 @@ static bool set_beneficiary_ui(ethQueryContractUI_t *msg, context_t *context) {
strlcpy(msg->title, "Address", msg->titleLength);
break;
case DELEGATE:
case MINT:
strlcpy(msg->title, "Beneficiary", msg->titleLength);
break;
default:
Expand All @@ -73,6 +74,50 @@ static bool set_beneficiary_ui(ethQueryContractUI_t *msg, context_t *context) {
chainid);
}

static bool set_address_ui(ethQueryContractUI_t *msg, context_t *context) {
switch (context->selectorIndex) {
case MINT:
strlcpy(msg->title, "Address", msg->titleLength);
break;
default:
PRINTF("Received an invalid selectorIndex\n");
break;
}

// Prefix the address with `0x`.
msg->msg[0] = '0';
msg->msg[1] = 'x';

// We need a random chainID for legacy reasons with `getEthAddressStringFromBinary`.
// Setting it to `0` will make it work with every chainID :)
uint64_t chainid = 0;

return getEthAddressStringFromBinary(
context->address,
msg->msg + 2, // +2 here because we've already prefixed with '0x'.
chainid);
}

static bool set_boolean_ui(ethQueryContractUI_t *msg, context_t *context) {
switch (context->selectorIndex) {
case MINT:
strlcpy(msg->title, "Basket Mode", msg->titleLength);
break;
default:
PRINTF("Received an invalid selectorIndex\n");
break;
}

if (context->boolean == 0) {
snprintf(msg->msg, msg->msgLength, "%s", "False");
return true;
} else {
snprintf(msg->msg, msg->msgLength, "%s", "True");
return true;
}
return false;
}

void handle_query_contract_ui(ethQueryContractUI_t *msg) {
context_t *context = (context_t *) msg->pluginContext;
bool ret = false;
Expand All @@ -97,6 +142,25 @@ void handle_query_contract_ui(ethQueryContractUI_t *msg) {
break;
}
break;
case MINT:
switch (msg->screenIndex) {
case 0:
ret = set_address_ui(msg, context);
break;
case 1:
ret = set_receive_ui(msg, context);
break;
case 2:
ret = set_beneficiary_ui(msg, context);
break;
case 3:
ret = set_boolean_ui(msg, context);
break;
default:
PRINTF("Received an invalid screenIndex\n");
break;
}
break;
default:
PRINTF("Received an invalid selectorIndex\n");
break;
Expand Down
9 changes: 6 additions & 3 deletions src/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
// - a map named SELECTORS associating each NAME with it's value
#define SELECTORS_LIST(X) \
X(CREATE_REWARD_VAULT, 0x577ee5c7) \
X(DELEGATE, 0x5c19a95c)
X(DELEGATE, 0x5c19a95c) \
X(MINT, 0x328ebaf7)

// Xmacro helpers to define the enum and map
// Do not modify !
Expand All @@ -51,6 +52,8 @@ typedef enum {
MIN_AMOUNT_RECEIVED = 0,
TOKEN_RECEIVED,
BENEFICIARY,
ADDRESS,
BOOLEAN,
PATH_OFFSET,
PATH_LENGTH,
UNEXPECTED_PARAMETER,
Expand All @@ -64,17 +67,17 @@ typedef struct context_s {
// For display.
uint8_t amount_received[INT256_LENGTH];
uint8_t beneficiary[ADDRESS_LENGTH];
uint8_t address[ADDRESS_LENGTH];
uint8_t token_received[ADDRESS_LENGTH];
char ticker[MAX_TICKER_LEN];
uint8_t decimals;
uint8_t token_found;

uint16_t boolean;
// For parsing data.
uint8_t next_param; // Set to be the next param we expect to parse.
uint16_t offset; // Offset at which the array or struct starts.
bool go_to_offset; // If set, will force the parsing to iterate through parameters until
// `offset` is reached.

// For both parsing and display.
selector_t selectorIndex;
} context_t;
Expand Down
Loading

0 comments on commit f9d278a

Please sign in to comment.