Skip to content

Commit

Permalink
:WIP: Revert and implement handler for reward createPosition function
Browse files Browse the repository at this point in the history
  • Loading branch information
nagdahimanshu committed Apr 23, 2024
1 parent 5382688 commit 233b4b5
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 66 deletions.
4 changes: 3 additions & 1 deletion src/handle_finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ void handle_finalize(ethPluginFinalize_t *msg) {
switch (context->selectorIndex) {
case CLAIM_REGULAR_ACCOUNT:
case CLAIM_MULTI_SIGNATURE_ACCOUNT:
case STAKING_LOCK_AMOUNT:
msg->numScreens = 3;
break;
case REWARD_CREATE_POSITION:
msg->numScreens = 2;
break;
default:
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
Expand Down
4 changes: 2 additions & 2 deletions src/handle_init_contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ void handle_init_contract(ethPluginInitContract_t *msg) {
case CLAIM_MULTI_SIGNATURE_ACCOUNT:
context->next_param = PROOF;
break;
case STAKING_LOCK_AMOUNT:
context->next_param = LOCK_OWNER;
case REWARD_CREATE_POSITION:
context->next_param = LOCK_AMOUNT;
break;
// Keep this
default:
Expand Down
29 changes: 13 additions & 16 deletions src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,21 @@ static void handle_claim_multisig_account(ethPluginProvideParameter_t *msg, cont
}
}

static void handle_staking_lock_amount(ethPluginProvideParameter_t *msg, context_t *context) {
static void handle_reward_create_position(ethPluginProvideParameter_t *msg, context_t *context) {
switch (context->next_param) {
case LOCK_OWNER: // lockOwner
copy_address(context->lisk.body.staking.lockOwner,
msg->parameter,
sizeof(context->lisk.body.staking.lockOwner));
context->next_param = AMOUNT;
break;
case AMOUNT: // amount
copy_parameter(context->lisk.body.staking.amount,
case LOCK_AMOUNT: // amount
copy_parameter(context->lisk.body.reward.lock_amount,
msg->parameter,
sizeof(context->lisk.body.staking.amount));
context->next_param = LOCKING_DURATION;
sizeof(context->lisk.body.reward.lock_amount));
context->next_param = LOCK_DURATION;
break;
case LOCKING_DURATION: // lockingDuration
copy_parameter(context->lisk.body.staking.lockingDuration,
case LOCK_DURATION: // lockingDuration
copy_parameter(context->lisk.body.reward.lock_duration,
msg->parameter,
sizeof(context->lisk.body.staking.lockingDuration));
sizeof(context->lisk.body.reward.lock_duration));
context->next_param = UNEXPECTED_PARAMETER;
break;
case UNEXPECTED_PARAMETER:
break;
default:
PRINTF("Param not supported: %d\n", context->next_param);
Expand Down Expand Up @@ -113,8 +110,8 @@ void handle_provide_parameter(ethPluginProvideParameter_t *msg) {
case CLAIM_MULTI_SIGNATURE_ACCOUNT:
handle_claim_multisig_account(msg, context);
break;
case STAKING_LOCK_AMOUNT:
handle_staking_lock_amount(msg, context);
case REWARD_CREATE_POSITION:
handle_reward_create_position(msg, context);
break;
default:
PRINTF("Selector Index not supported: %d\n", context->selectorIndex);
Expand Down
2 changes: 1 addition & 1 deletion src/handle_query_contract_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void handle_query_contract_id(ethQueryContractID_t *msg) {
context->selectorIndex == CLAIM_MULTI_SIGNATURE_ACCOUNT) {
strlcpy(msg->version, "Claim LSK", msg->versionLength);
msg->result = ETH_PLUGIN_RESULT_OK;
} else if (context->selectorIndex == STAKING_LOCK_AMOUNT) {
} else if (context->selectorIndex == REWARD_CREATE_POSITION) {
strlcpy(msg->version, "Stake Amount", msg->versionLength);
msg->result = ETH_PLUGIN_RESULT_OK;
} else {
Expand Down
68 changes: 31 additions & 37 deletions src/handle_query_contract_ui.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "plugin.h"

static bool handle_amount(ethQueryContractUI_t *msg, const context_t *context) {
// Set UI for "Claim LSK" screen.
static bool set_claim_ui(ethQueryContractUI_t *msg, const context_t *context) {
strlcpy(msg->title, "Claim LSK", msg->titleLength);

uint8_t decimals = 18;
const char *ticker = "LSK";

Expand All @@ -12,29 +15,6 @@ static bool handle_amount(ethQueryContractUI_t *msg, const context_t *context) {
msg->msgLength);
}

static bool handle_address(ethQueryContractUI_t *msg, context_t *context) {
// 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;

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

// Set UI for "Claim LSK" screen.
static bool set_claim_ui(ethQueryContractUI_t *msg, const context_t *context) {
strlcpy(msg->title, "Claim LSK", msg->titleLength);
return handle_amount(msg, context);
}

// Set UI for "Sender Public Key" screen.
static bool set_sender_public_key_ui(ethQueryContractUI_t *msg, context_t *context) {
strlcpy(msg->title, "Sender Lisk Public Key", msg->titleLength);
Expand All @@ -57,26 +37,43 @@ static bool set_sender_address_ui(ethQueryContractUI_t *msg, context_t *context)
// Set UI for "Recipient" screen.
static bool set_recipient_ui(ethQueryContractUI_t *msg, context_t *context) {
strlcpy(msg->title, "Recipient Address L2", msg->titleLength);
return handle_address(msg, context);
}

// Set UI for "Lock Owner" screen.
static bool set_lock_owner_ui(ethQueryContractUI_t *msg, context_t *context) {
strlcpy(msg->title, "Lock Owner", msg->titleLength);
return handle_address(msg, context);
// 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;

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

// Set UI for "Lock Amount" screen.
static bool set_lock_amount_ui(ethQueryContractUI_t *msg, const context_t *context) {
strlcpy(msg->title, "Lock Amount", msg->titleLength);
return handle_amount(msg, context);

uint8_t decimals = 18;
const char *ticker = "LSK";

return amountToString(context->lisk.body.reward.lock_amount,
sizeof(context->lisk.body.reward.lock_amount),
decimals,
ticker,
msg->msg,
msg->msgLength);
}

// Set UI for "Lock Duration" screen.
static bool set_lock_duration_ui(ethQueryContractUI_t *msg, context_t *context) {
strlcpy(msg->title, "Lock Duration (in days)", msg->titleLength);
return uint256_to_decimal(context->lisk.body.staking.lockingDuration,
sizeof(context->lisk.body.staking.lockingDuration),
return uint256_to_decimal(context->lisk.body.reward.lock_duration,
sizeof(context->lisk.body.reward.lock_duration),
msg->msg,
msg->msgLength);
}
Expand Down Expand Up @@ -124,11 +121,8 @@ void handle_query_contract_ui(ethQueryContractUI_t *msg) {
PRINTF("Received an invalid screenIndex\n");
}
break;
case STAKING_LOCK_AMOUNT:
case REWARD_CREATE_POSITION:
switch (msg->screenIndex) {
case 0:
ret = set_lock_owner_ui(msg, context);
break;
case 1:
ret = set_lock_amount_ui(msg, context);
break;
Expand Down
16 changes: 7 additions & 9 deletions src/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#define SELECTORS_LIST(X) \
X(CLAIM_REGULAR_ACCOUNT, 0xf6de242d) \
X(CLAIM_MULTI_SIGNATURE_ACCOUNT, 0x2f559f68) \
X(STAKING_LOCK_AMOUNT, 0x1c319c2d) // TODO: Update MethodID once available
X(REWARD_CREATE_POSITION, 0xd1aaef05) // TODO: May be rename it to REWARD_STAKE_AMOUNT

// Xmacro helpers to define the enum and map
// Do not modify !
Expand Down Expand Up @@ -67,10 +67,9 @@ typedef enum {
LSK_ADDRESS,
ED25519_SIGNATURES,

// Staking lock amount parameters
LOCK_OWNER,
AMOUNT,
LOCKING_DURATION,
// Reward create position parameters
LOCK_AMOUNT,
LOCK_DURATION,
} parameter;

typedef struct {
Expand All @@ -82,10 +81,9 @@ typedef struct {
uint8_t lsk_address[LISK_ADDRESS_LENGTH];
} claim;
struct {
uint8_t lockOwner[ADDRESS_LENGTH];
uint8_t amount[INT256_LENGTH];
uint8_t lockingDuration[INT256_LENGTH];
} staking;
uint8_t lock_amount[INT256_LENGTH];
uint8_t lock_duration[INT256_LENGTH];
} reward;
} body;
} lisk_t;

Expand Down

0 comments on commit 233b4b5

Please sign in to comment.