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

Updated to use the latest plugin SDK #12

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion ethereum-plugin-sdk
3 changes: 1 addition & 2 deletions src/handle_finalize.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "kiln_plugin.h"

void handle_finalize(void *parameters) {
ethPluginFinalize_t *msg = (ethPluginFinalize_t *) parameters;
void handle_finalize(ethPluginFinalize_t *msg) {
context_t *context = (context_t *) msg->pluginContext;

msg->uiType = ETH_UI_TYPE_GENERIC;
Expand Down
4 changes: 1 addition & 3 deletions src/handle_init_contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ static int find_selector(uint32_t selector, const uint32_t *selectors, size_t n,
return -1;
}

void handle_init_contract(void *parameters) {
ethPluginInitContract_t *msg = (ethPluginInitContract_t *) parameters;

void handle_init_contract(ethPluginInitContract_t *msg) {
if (msg->interfaceVersion != ETH_PLUGIN_INTERFACE_VERSION_LATEST) {
msg->result = ETH_PLUGIN_RESULT_UNAVAILABLE;
return;
Expand Down
3 changes: 1 addition & 2 deletions src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "kiln_plugin.h"

void handle_provide_parameter(void *parameters) {
ethPluginProvideParameter_t *msg = (ethPluginProvideParameter_t *) parameters;
void handle_provide_parameter(ethPluginProvideParameter_t *msg) {
context_t *context = (context_t *) msg->pluginContext;

PRINTF("plugin provide parameter: offset %d\nBytes: %.*H\n",
Expand Down
5 changes: 5 additions & 0 deletions src/handle_provide_token.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "kiln_plugin.h"

void handle_provide_token(ethPluginProvideInfo_t *msg) {
msg->result = ETH_PLUGIN_RESULT_OK;
}
3 changes: 1 addition & 2 deletions src/handle_query_contract_id.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "kiln_plugin.h"

void handle_query_contract_id(void *parameters) {
ethQueryContractID_t *msg = (ethQueryContractID_t *) parameters;
void handle_query_contract_id(ethQueryContractID_t *msg) {
const context_t *context = (const context_t *) msg->pluginContext;

strlcpy(msg->name, PLUGIN_NAME, msg->nameLength);
Expand Down
103 changes: 58 additions & 45 deletions src/handle_query_contract_ui.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdbool.h>
#include "kiln_plugin.h"

static void withdraw_rewards_ui(ethQueryContractUI_t *msg, context_t *context) {
static bool withdraw_rewards_ui(ethQueryContractUI_t *msg, context_t *context) {
strlcpy(msg->title, "Rewards", msg->titleLength);

switch (context->selectorIndex) {
Expand All @@ -20,23 +21,25 @@ static void withdraw_rewards_ui(ethQueryContractUI_t *msg, context_t *context) {
strlcpy(msg->msg, "?", msg->msgLength);
break;
}
return true;
}

static void withdraw_ui(ethQueryContractUI_t *msg, context_t *context) {
static bool withdraw_ui(ethQueryContractUI_t *msg, context_t *context) {
bool ret = false;

switch (msg->screenIndex) {
case 0:
withdraw_rewards_ui(msg, context);
msg->result = ETH_PLUGIN_RESULT_OK;
ret = withdraw_rewards_ui(msg, context);
break;

default:
PRINTF("Received an invalid screenIndex\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
return ret;
}

static void batch_withdraw_rewards_ui(ethQueryContractUI_t *msg, context_t *context) {
static bool batch_withdraw_rewards_ui(ethQueryContractUI_t *msg, context_t *context) {
strlcpy(msg->title, "Rewards", msg->titleLength);

switch (context->selectorIndex) {
Expand All @@ -56,157 +59,167 @@ static void batch_withdraw_rewards_ui(ethQueryContractUI_t *msg, context_t *cont
strlcpy(msg->msg, "?", msg->msgLength);
break;
}
return true;
}

static void batch_withdraw_ui(ethQueryContractUI_t *msg, context_t *context) {
static bool batch_withdraw_ui(ethQueryContractUI_t *msg, context_t *context) {
bool ret = false;

switch (msg->screenIndex) {
case 0:
batch_withdraw_rewards_ui(msg, context);
msg->result = ETH_PLUGIN_RESULT_OK;
ret = batch_withdraw_rewards_ui(msg, context);
break;

default:
PRINTF("Received an invalid screenIndex\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
return ret;
}

static void request_exits_ui(ethQueryContractUI_t *msg) {
static bool request_exits_ui(ethQueryContractUI_t *msg) {
strlcpy(msg->title, "Request", msg->titleLength);
strlcpy(msg->msg, "Validators Exit", msg->msgLength);
return true;
}

static void request_exit_ui(ethQueryContractUI_t *msg) {
static bool request_exit_ui(ethQueryContractUI_t *msg) {
bool ret = false;

switch (msg->screenIndex) {
case 0:
request_exits_ui(msg);
msg->result = ETH_PLUGIN_RESULT_OK;
ret = request_exits_ui(msg);
break;

default:
PRINTF("Received an invalid screenIndex\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
return ret;
}

static void stake_ui(ethQueryContractUI_t *msg) {
static bool stake_ui(ethQueryContractUI_t *msg) {
bool ret = false;

switch (msg->screenIndex) {
case 0:
strlcpy(msg->title, "Stake", msg->titleLength);
const uint8_t *eth_amount = msg->pluginSharedRO->txContent->value.value;
uint8_t eth_amount_size = msg->pluginSharedRO->txContent->value.length;

amountToString(eth_amount,
eth_amount_size,
WEI_TO_ETHER,
"ETH",
msg->msg,
msg->msgLength);

msg->result = ETH_PLUGIN_RESULT_OK;
ret = amountToString(eth_amount,
eth_amount_size,
WEI_TO_ETHER,
"ETH",
msg->msg,
msg->msgLength);
break;

default:
PRINTF("Received an invalid screenIndex\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
return ret;
}

static void request_exit_ui_v2(ethQueryContractUI_t *msg) {
static bool request_exit_ui_v2(ethQueryContractUI_t *msg) {
bool ret = false;

switch (msg->screenIndex) {
case 0:
strlcpy(msg->title, "Request", msg->titleLength);
strlcpy(msg->msg, "Position Exit", msg->msgLength);
msg->result = ETH_PLUGIN_RESULT_OK;
ret = true;
break;

default:
PRINTF("Received an invalid screenIndex\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
return ret;
}

static void multiclaim_ui_v2(ethQueryContractUI_t *msg) {
static bool multiclaim_ui_v2(ethQueryContractUI_t *msg) {
bool ret = false;

switch (msg->screenIndex) {
case 0:
strlcpy(msg->title, "Withdraw", msg->titleLength);
strlcpy(msg->msg, "Exited Positions", msg->msgLength);
msg->result = ETH_PLUGIN_RESULT_OK;
ret = true;
break;

default:
PRINTF("Received an invalid screenIndex\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
return ret;
}

static void claim_ui_v2(ethQueryContractUI_t *msg) {
static bool claim_ui_v2(ethQueryContractUI_t *msg) {
bool ret = false;

switch (msg->screenIndex) {
case 0:
strlcpy(msg->title, "Withdraw", msg->titleLength);
strlcpy(msg->msg, "Exited Position", msg->msgLength);
msg->result = ETH_PLUGIN_RESULT_OK;
ret = true;
break;

default:
PRINTF("Received an invalid screenIndex\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
return ret;
}

void handle_query_contract_ui(void *parameters) {
ethQueryContractUI_t *msg = (ethQueryContractUI_t *) parameters;
void handle_query_contract_ui(ethQueryContractUI_t *msg) {
context_t *context = (context_t *) msg->pluginContext;
bool ret = false;

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

switch (context->selectorIndex) {
case KILN_V1_DEPOSIT:
stake_ui(msg);
ret = stake_ui(msg);
break;

case KILN_V1_WITHDRAW:
case KILN_V1_WITHDRAW_EL:
case KILN_V1_WITHDRAW_CL:
withdraw_ui(msg, context);
ret = withdraw_ui(msg, context);
break;

case KILN_V1_BATCH_WITHDRAW:
case KILN_V1_BATCH_WITHDRAW_EL:
case KILN_V1_BATCH_WITHDRAW_CL:
batch_withdraw_ui(msg, context);
ret = batch_withdraw_ui(msg, context);
break;

case KILN_V1_REQUEST_EXIT:
request_exit_ui(msg);
ret = request_exit_ui(msg);
break;

case KILN_V2_STAKE:
stake_ui(msg);
ret = stake_ui(msg);
break;

case KILN_V2_REQUEST_EXIT:
request_exit_ui_v2(msg);
ret = request_exit_ui_v2(msg);
break;

case KILN_V2_MULTICLAIM:
multiclaim_ui_v2(msg);
ret = multiclaim_ui_v2(msg);
break;

case KILN_V2_CLAIM:
claim_ui_v2(msg);
ret = claim_ui_v2(msg);
break;

default:
PRINTF("Selector Index not supported: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
msg->result = ret ? ETH_PLUGIN_RESULT_OK : ETH_PLUGIN_RESULT_ERROR;
}
6 changes: 0 additions & 6 deletions src/kiln_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,3 @@ typedef struct context_t {
} context_t;

_Static_assert(sizeof(context_t) <= 5 * 32, "Structure of parameters too big.");

void handle_provide_parameter(void *parameters);
void handle_query_contract_ui(void *parameters);
void handle_init_contract(void *parameters);
void handle_finalize(void *parameters);
void handle_query_contract_id(void *parameters);
Loading
Loading