diff --git a/src/handle_finalize.c b/src/handle_finalize.c index 0a3459c9..82deccb9 100644 --- a/src/handle_finalize.c +++ b/src/handle_finalize.c @@ -34,7 +34,7 @@ void handle_finalize(ethPluginFinalize_t *msg) { msg->numScreens = 3; break; case GOVERNOR_PROPOSE: - msg->numScreens = context->lisk.body.governorPropose.target_len * 2; + msg->numScreens = context->lisk.body.governorPropose.value_len * 2; break; default: msg->result = ETH_PLUGIN_RESULT_ERROR; diff --git a/src/handle_init_contract.c b/src/handle_init_contract.c index 656d77c0..5010bdc6 100644 --- a/src/handle_init_contract.c +++ b/src/handle_init_contract.c @@ -65,7 +65,7 @@ void handle_init_contract(ethPluginInitContract_t *msg) { break; case GOVERNOR_CAST_VOTE: case GOVERNOR_CAST_VOTE_WITH_REASON: - context->next_param = PROPOSAL_ID; + context->next_param = ID; break; // Keep this default: diff --git a/src/handle_provide_parameter.c b/src/handle_provide_parameter.c index ed6f7fba..ae788265 100644 --- a/src/handle_provide_parameter.c +++ b/src/handle_provide_parameter.c @@ -17,9 +17,9 @@ static void handle_claim_regular_account(ethPluginProvideParameter_t *msg, conte copy_parameter(context->lisk.body.claim.public_key, msg->parameter, sizeof(context->lisk.body.claim.public_key)); - context->next_param = CLAIM_AMOUNT; + context->next_param = AMOUNT; break; - case CLAIM_AMOUNT: // _amount + case AMOUNT: // _amount copy_parameter(context->lisk.body.claim.claim_amount, msg->parameter, sizeof(context->lisk.body.claim.claim_amount)); @@ -29,9 +29,9 @@ static void handle_claim_regular_account(ethPluginProvideParameter_t *msg, conte copy_address(context->lisk.body.claim.recipient, msg->parameter, sizeof(context->lisk.body.claim.recipient)); - context->next_param = ED25519_SIGNATURE; + context->next_param = SKIPED_PARAMETER; break; - case ED25519_SIGNATURE: // _sig + case SKIPED_PARAMETER: // ED25519_SIGNATURE context->next_param = UNEXPECTED_PARAMETER; break; case UNEXPECTED_PARAMETER: @@ -52,9 +52,9 @@ static void handle_claim_multisig_account(ethPluginProvideParameter_t *msg, cont copy_parameter(context->lisk.body.claim.lsk_address, msg->parameter, sizeof(context->lisk.body.claim.lsk_address)); - context->next_param = CLAIM_AMOUNT; + context->next_param = AMOUNT; break; - case CLAIM_AMOUNT: // _amount + case AMOUNT: // _amount copy_parameter(context->lisk.body.claim.claim_amount, msg->parameter, sizeof(context->lisk.body.claim.claim_amount)); @@ -67,9 +67,9 @@ static void handle_claim_multisig_account(ethPluginProvideParameter_t *msg, cont copy_address(context->lisk.body.claim.recipient, msg->parameter, sizeof(context->lisk.body.claim.recipient)); - context->next_param = ED25519_SIGNATURES; + context->next_param = SKIPED_PARAMETER; break; - case ED25519_SIGNATURES: // _sigs + case SKIPED_PARAMETER: // ED25519_SIGNATURES context->next_param = UNEXPECTED_PARAMETER; break; case UNEXPECTED_PARAMETER: @@ -84,15 +84,15 @@ static void handle_claim_multisig_account(ethPluginProvideParameter_t *msg, cont static void handle_reward_create_position(ethPluginProvideParameter_t *msg, context_t *context) { switch (context->next_param) { case AMOUNT: // amount - copy_parameter(context->lisk.body.rewardCreatePosition.lock_amount, + copy_parameter(context->lisk.body.rewardCreatePosition.first, msg->parameter, - sizeof(context->lisk.body.rewardCreatePosition.lock_amount)); + sizeof(context->lisk.body.rewardCreatePosition.first)); context->next_param = DURATION; break; case DURATION: // lockingDuration - copy_parameter(context->lisk.body.rewardCreatePosition.lock_duration, + copy_parameter(context->lisk.body.rewardCreatePosition.second, msg->parameter, - sizeof(context->lisk.body.rewardCreatePosition.lock_duration)); + sizeof(context->lisk.body.rewardCreatePosition.second)); context->next_param = UNEXPECTED_PARAMETER; break; case UNEXPECTED_PARAMETER: @@ -107,18 +107,18 @@ static void handle_reward_create_position(ethPluginProvideParameter_t *msg, cont static void handle_lock_ids_array(ethPluginProvideParameter_t *msg, context_t *context) { switch (context->next_param) { case OFFSET: - context->next_param = LOCK_IDS_LEN; + context->next_param = ARRAY_LENGTH; break; - case LOCK_IDS_LEN: + case ARRAY_LENGTH: if (!U2BE_from_parameter(msg->parameter, &context->lisk.body.reward.lock_ids_len) || context->lisk.body.reward.lock_ids_len > 4 || context->lisk.body.reward.lock_ids_len == 0) { msg->result = ETH_PLUGIN_RESULT_ERROR; } - context->next_param = LOCK_ID; + context->next_param = ID; break; - case LOCK_ID: + case ID: copy_parameter(context->lisk.body.reward.lock_id[counter].value, msg->parameter, INT256_LENGTH); @@ -141,9 +141,9 @@ static void handle_lock_ids_array(ethPluginProvideParameter_t *msg, context_t *c static void handle_increase_locking_amount(ethPluginProvideParameter_t *msg, context_t *context) { switch (context->next_param) { case OFFSET: - context->next_param = INCREASE_LEN; + context->next_param = ARRAY_LENGTH; break; - case INCREASE_LEN: + case ARRAY_LENGTH: if (!U2BE_from_parameter(msg->parameter, &context->lisk.body.rewardIncLockingAmount.len) || context->lisk.body.rewardIncLockingAmount.len > 2 || @@ -151,22 +151,22 @@ static void handle_increase_locking_amount(ethPluginProvideParameter_t *msg, con msg->result = ETH_PLUGIN_RESULT_ERROR; } - context->next_param = LOCK_ID; + context->next_param = ID; break; - case LOCK_ID: - copy_parameter(context->lisk.body.rewardIncLockingAmount.lock_id[counter].value, + case ID: + copy_parameter(context->lisk.body.rewardIncLockingAmount.first[counter].value, msg->parameter, INT256_LENGTH); context->next_param = AMOUNT; break; case AMOUNT: - copy_parameter(context->lisk.body.rewardIncLockingAmount.amount[counter].value, + copy_parameter(context->lisk.body.rewardIncLockingAmount.second[counter].value, msg->parameter, INT256_LENGTH); if (context->lisk.body.rewardIncLockingAmount.len > 1 && counter < context->lisk.body.rewardIncLockingAmount.len - 1) { counter++; - context->next_param = LOCK_ID; + context->next_param = ID; } else { context->next_param = NONE; } @@ -183,9 +183,9 @@ static void handle_increase_locking_amount(ethPluginProvideParameter_t *msg, con static void handle_extend_duration(ethPluginProvideParameter_t *msg, context_t *context) { switch (context->next_param) { case OFFSET: - context->next_param = INCREASE_LEN; + context->next_param = ARRAY_LENGTH; break; - case INCREASE_LEN: + case ARRAY_LENGTH: if (!U2BE_from_parameter(msg->parameter, &context->lisk.body.rewardExtendDuration.len) || context->lisk.body.rewardExtendDuration.len > 2 || @@ -193,22 +193,22 @@ static void handle_extend_duration(ethPluginProvideParameter_t *msg, context_t * msg->result = ETH_PLUGIN_RESULT_ERROR; } - context->next_param = LOCK_ID; + context->next_param = ID; break; - case LOCK_ID: - copy_parameter(context->lisk.body.rewardExtendDuration.lock_id[counter].value, + case ID: + copy_parameter(context->lisk.body.rewardExtendDuration.first[counter].value, msg->parameter, INT256_LENGTH); context->next_param = DURATION; break; case DURATION: - copy_parameter(context->lisk.body.rewardExtendDuration.duration[counter].value, + copy_parameter(context->lisk.body.rewardExtendDuration.second[counter].value, msg->parameter, INT256_LENGTH); if (context->lisk.body.rewardExtendDuration.len > 1 && counter < context->lisk.body.rewardExtendDuration.len - 1) { counter++; - context->next_param = LOCK_ID; + context->next_param = ID; } else { context->next_param = NONE; } @@ -225,15 +225,15 @@ static void handle_extend_duration(ethPluginProvideParameter_t *msg, context_t * static void handle_add_unused_rewards(ethPluginProvideParameter_t *msg, context_t *context) { switch (context->next_param) { case AMOUNT: - copy_parameter(context->lisk.body.rewardAddUnusedRewards.amount, + copy_parameter(context->lisk.body.rewardAddUnusedRewards.data.first, msg->parameter, - sizeof(context->lisk.body.rewardAddUnusedRewards.amount)); + sizeof(context->lisk.body.rewardAddUnusedRewards.data.first)); context->next_param = DURATION; break; case DURATION: - copy_parameter(context->lisk.body.rewardAddUnusedRewards.duration, + copy_parameter(context->lisk.body.rewardAddUnusedRewards.data.second, msg->parameter, - sizeof(context->lisk.body.rewardAddUnusedRewards.duration)); + sizeof(context->lisk.body.rewardAddUnusedRewards.data.second)); context->next_param = DELAY; break; case DELAY: @@ -257,15 +257,15 @@ static void handle_claim_airdrop(ethPluginProvideParameter_t *msg, context_t *co copy_parameter(context->lisk.body.claim.lsk_address, msg->parameter, sizeof(context->lisk.body.claim.lsk_address)); - context->next_param = CLAIM_AMOUNT; + context->next_param = AMOUNT; break; - case CLAIM_AMOUNT: // amount + case AMOUNT: // amount copy_parameter(context->lisk.body.claim.claim_amount, msg->parameter, sizeof(context->lisk.body.claim.claim_amount)); - context->next_param = PROOF; + context->next_param = SKIPED_PARAMETER; break; - case PROOF: // merkleProof + case SKIPED_PARAMETER: // merkleProof context->next_param = NONE; break; case NONE: @@ -279,14 +279,16 @@ static void handle_claim_airdrop(ethPluginProvideParameter_t *msg, context_t *co static void handle_governor_cast_vote(ethPluginProvideParameter_t *msg, context_t *context) { switch (context->next_param) { - case PROPOSAL_ID: // proposalId - copy_parameter(context->lisk.body.governor.proposal_id, msg->parameter, INT256_LENGTH); + case ID: // proposalId + copy_parameter(context->lisk.body.governor.data.first, + msg->parameter, + sizeof(context->lisk.body.governor.data.first)); context->next_param = SUPPORT; break; case SUPPORT: // support - copy_parameter(context->lisk.body.governor.support, + copy_parameter(context->lisk.body.governor.data.second, msg->parameter, - sizeof(context->lisk.body.governor.support)); + sizeof(context->lisk.body.governor.data.second)); context->next_param = NONE; break; case NONE: @@ -302,20 +304,22 @@ static void handle_governor_cast_vote_with_reason(ethPluginProvideParameter_t *m context_t *context) { uint16_t tmp; switch (context->next_param) { - case PROPOSAL_ID: // proposalId - copy_parameter(context->lisk.body.governor.proposal_id, msg->parameter, INT256_LENGTH); + case ID: // proposalId + copy_parameter(context->lisk.body.governor.data.first, + msg->parameter, + sizeof(context->lisk.body.governor.data.first)); context->next_param = SUPPORT; break; case SUPPORT: // support - copy_parameter(context->lisk.body.governor.support, + copy_parameter(context->lisk.body.governor.data.second, msg->parameter, - sizeof(context->lisk.body.governor.support)); + sizeof(context->lisk.body.governor.data.second)); context->next_param = OFFSET; break; case OFFSET: - context->next_param = REASON_LENGTH; + context->next_param = ARRAY_LENGTH; break; - case REASON_LENGTH: // reason + case ARRAY_LENGTH: // reason if (!U2BE_from_parameter(msg->parameter, &tmp)) { msg->result = ETH_PLUGIN_RESULT_ERROR; return; @@ -329,9 +333,9 @@ static void handle_governor_cast_vote_with_reason(ethPluginProvideParameter_t *m } max_counter = counter; - context->next_param = REASON; + context->next_param = VALUE; break; - case REASON: + case VALUE: if (counter == max_counter) { copy_text(context->lisk.body.governor.reason.value, context->lisk.body.governor.reason.len, @@ -365,13 +369,13 @@ static void handle_governor_propose(ethPluginProvideParameter_t *msg, context_t case OFFSET: context->offset = U2BE(msg->parameter, PARAMETER_LENGTH - sizeof(context->offset)); context->go_to_offset = true; - context->next_param = PROPOSE_TARGET_LEN; + context->next_param = ARRAY_LENGTH; break; - case PROPOSE_TARGET_LEN: + case ARRAY_LENGTH: if (!U2BE_from_parameter(msg->parameter, - &context->lisk.body.governorPropose.target_len) || - context->lisk.body.governorPropose.target_len > 2 || - context->lisk.body.governorPropose.target_len == 0) { + &context->lisk.body.governorPropose.data.len) || + context->lisk.body.governorPropose.data.len > 2 || + context->lisk.body.governorPropose.data.len == 0) { msg->result = ETH_PLUGIN_RESULT_ERROR; } @@ -380,10 +384,10 @@ static void handle_governor_propose(ethPluginProvideParameter_t *msg, context_t context->next_param = TARGET_ADDRESS; break; case TARGET_ADDRESS: - copy_address(context->lisk.body.governorPropose.targets[counter].value, + copy_address(context->lisk.body.governorPropose.data.first[counter].value, msg->parameter, - sizeof(context->lisk.body.governorPropose.targets[counter].value)); - if (counter + 1 < context->lisk.body.governorPropose.target_len) { + sizeof(context->lisk.body.governorPropose.data.first[counter].value)); + if (counter + 1 < context->lisk.body.governorPropose.data.len) { counter++; context->next_param = SECOND_TARGET_ADDRESS; } else { @@ -391,9 +395,9 @@ static void handle_governor_propose(ethPluginProvideParameter_t *msg, context_t } break; case SECOND_TARGET_ADDRESS: - copy_address(context->lisk.body.governorPropose.targets[counter].value, + copy_address(context->lisk.body.governorPropose.data.first[counter].value, msg->parameter, - sizeof(context->lisk.body.governorPropose.targets[counter].value)); + sizeof(context->lisk.body.governorPropose.data.first[counter].value)); counter = 0; context->next_param = PROPOSE_VALUE_LEN; break; @@ -402,14 +406,14 @@ static void handle_governor_propose(ethPluginProvideParameter_t *msg, context_t &context->lisk.body.governorPropose.value_len) || context->lisk.body.governorPropose.value_len > 2 || context->lisk.body.governorPropose.value_len == 0 || - context->lisk.body.governorPropose.target_len != - context->lisk.body.governorPropose.value_len) { + context->lisk.body.governorPropose.value_len != + context->lisk.body.governorPropose.data.len) { msg->result = ETH_PLUGIN_RESULT_ERROR; } context->next_param = VALUE; break; case VALUE: - copy_parameter(context->lisk.body.governorPropose.values[counter].value, + copy_parameter(context->lisk.body.governorPropose.data.second[counter].value, msg->parameter, INT256_LENGTH); if (counter + 1 < context->lisk.body.governorPropose.value_len) { @@ -420,7 +424,7 @@ static void handle_governor_propose(ethPluginProvideParameter_t *msg, context_t } break; case SECOND_VALUE: - copy_parameter(context->lisk.body.governorPropose.values[counter].value, + copy_parameter(context->lisk.body.governorPropose.data.second[counter].value, msg->parameter, INT256_LENGTH); context->next_param = NONE; diff --git a/src/handle_query_contract_ui.c b/src/handle_query_contract_ui.c index 5bf2d564..5d039b0c 100644 --- a/src/handle_query_contract_ui.c +++ b/src/handle_query_contract_ui.c @@ -21,23 +21,23 @@ static bool set_bytes_to_hex(char *msg, size_t msgLen, const uint8_t *value, uin return true; } -// Set UI for "Claim LSK" screen. -static bool set_claim_ui(ethQueryContractUI_t *msg, const context_t *context) { - if (context->selectorIndex == CLAIM_AIRDROP) { - strlcpy(msg->title, "Claim Airdrop (LSK)", msg->titleLength); - } else { - strlcpy(msg->title, "Claim LSK", msg->titleLength); - } +// Set UI with custom title for amount screen with uint8 data. +static bool set_amount_ui_uint8(ethQueryContractUI_t *msg, + const uint8_t *amount, + const char *title) { + strlcpy(msg->title, title, msg->titleLength); uint8_t decimals = 18; const char *ticker = "LSK"; - return amountToString(context->lisk.body.claim.claim_amount, - sizeof(context->lisk.body.claim.claim_amount), - decimals, - ticker, - msg->msg, - msg->msgLength); + return amountToString(amount, INT256_LENGTH, decimals, ticker, msg->msg, msg->msgLength); +} + +// Set UI with custom title for amount screen with uint8 data. +static bool set_amount_ui_arr(ethQueryContractUI_t *msg, + const arr_uint8_t *amount, + const char *title) { + return set_amount_ui_uint8(msg, amount->value, title); } // Set UI for "Sender Public Key" screen. @@ -50,8 +50,8 @@ static bool set_sender_public_key_ui(ethQueryContractUI_t *msg, context_t *conte return true; } -// Set UI for "Sender Address" screen. -static bool set_sender_address_ui(ethQueryContractUI_t *msg, context_t *context) { +// Set UI for "Lisk Address" screen. +static bool set_lisk_address_ui(ethQueryContractUI_t *msg, context_t *context) { if (context->selectorIndex == CLAIM_AIRDROP) { strlcpy(msg->title, "Lisk Address", msg->titleLength); } else { @@ -69,132 +69,31 @@ static bool set_sender_address_ui(ethQueryContractUI_t *msg, context_t *context) return true; } -// Set UI for "Recipient" screen. -static bool set_recipient_ui(ethQueryContractUI_t *msg, context_t *context) { - strlcpy(msg->title, "Recipient Address L2", msg->titleLength); - - // 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); - - uint8_t decimals = 18; - const char *ticker = "LSK"; - - return amountToString(context->lisk.body.rewardCreatePosition.lock_amount, - sizeof(context->lisk.body.rewardCreatePosition.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, "Duration (in days)", msg->titleLength); - return uint256_to_decimal(context->lisk.body.rewardCreatePosition.lock_duration, - sizeof(context->lisk.body.rewardCreatePosition.lock_duration), - msg->msg, - msg->msgLength); -} - -// Set UI for "Lock IDs" screen. -static bool set_lock_ids_ui(ethQueryContractUI_t *msg, arr_uint8_t *lock) { - strlcpy(msg->title, "Lock ID", msg->titleLength); - return uint256_to_decimal(lock->value, INT256_LENGTH, msg->msg, msg->msgLength); -} - -// Set UI for "Increase Amount" screen. -static bool set_amount_ui(ethQueryContractUI_t *msg, arr_uint8_t *amount) { - strlcpy(msg->title, "Increase Amount", msg->titleLength); - - uint8_t decimals = 18; - const char *ticker = "LSK"; - - return amountToString(amount->value, INT256_LENGTH, decimals, ticker, msg->msg, msg->msgLength); -} - -// Set UI for "Extend Duration" screen. -static bool set_duration_ui(ethQueryContractUI_t *msg, arr_uint8_t *duration) { - strlcpy(msg->title, "Duration", msg->titleLength); - return uint256_to_decimal(duration->value, INT256_LENGTH, msg->msg, msg->msgLength); -} - -// Set UI for "Unused Rewards Amount" screen. -static bool set_unused_amount_ui(ethQueryContractUI_t *msg, const context_t *context) { - strlcpy(msg->title, "Amount", msg->titleLength); - - uint8_t decimals = 18; - const char *ticker = "LSK"; - - return amountToString(context->lisk.body.rewardAddUnusedRewards.amount, - sizeof(context->lisk.body.rewardAddUnusedRewards.amount), - decimals, - ticker, - msg->msg, - msg->msgLength); -} - -// Set UI for "Add Unused Duration" screen. -static bool set_unused_duration_ui(ethQueryContractUI_t *msg, context_t *context) { - strlcpy(msg->title, "Duration (in days)", msg->titleLength); - return uint256_to_decimal(context->lisk.body.rewardAddUnusedRewards.duration, - sizeof(context->lisk.body.rewardAddUnusedRewards.duration), - msg->msg, - msg->msgLength); -} - -// Set UI for "Add Unused Duration" screen. -static bool set_unused_delay_ui(ethQueryContractUI_t *msg, context_t *context) { - strlcpy(msg->title, "Delay (in days)", msg->titleLength); - return uint256_to_decimal(context->lisk.body.rewardAddUnusedRewards.delay, - sizeof(context->lisk.body.rewardAddUnusedRewards.delay), - msg->msg, - msg->msgLength); -} - -// Set UI for "Proposal ID" screen. -static bool set_proposal_id_ui(ethQueryContractUI_t *msg, context_t *context) { - strlcpy(msg->title, "Proposal ID", msg->titleLength); - return uint256_to_decimal(context->lisk.body.governor.proposal_id, - INT256_LENGTH, - msg->msg, - msg->msgLength); -} - -// Set UI for "Support" screen. -static bool set_support_ui(ethQueryContractUI_t *msg, context_t *context) { - strlcpy(msg->title, "Support", msg->titleLength); - return uint256_to_decimal(context->lisk.body.governor.support, - sizeof(context->lisk.body.governor.support), - msg->msg, - msg->msgLength); -} - +// Set UI for "Reason" screen. static bool set_reason_ui(ethQueryContractUI_t *msg, string_uint8_t *reason) { strlcpy(msg->title, "Reason", msg->titleLength); snprintf(msg->msg, msg->msgLength, "%s", reason->value); return true; } -// Set UI for "Target Address" screen. -static bool set_target_ui(ethQueryContractUI_t *msg, arr_address_t *target) { - strlcpy(msg->title, "Target Address", msg->titleLength); +// Set UI with custom title for decimal screan with uint8 data +static bool set_decimal_ui_uint8(ethQueryContractUI_t *msg, + const uint8_t *value, + const char *title) { + strlcpy(msg->title, title, msg->titleLength); + return uint256_to_decimal(value, INT256_LENGTH, msg->msg, msg->msgLength); +} + +// Set UI with custom title for "decimal" screen with array of uint8 data. +static bool set_decimal_ui_arr(ethQueryContractUI_t *msg, + const arr_uint8_t *arr, + const char *title) { + return set_decimal_ui_uint8(msg, arr->value, title); +} + +// Set UI with custom title for address Screen. +static bool set_address_ui(ethQueryContractUI_t *msg, uint8_t *address, const char *title) { + strlcpy(msg->title, title, msg->titleLength); // Prefix the address with `0x`. msg->msg[0] = '0'; @@ -205,17 +104,11 @@ static bool set_target_ui(ethQueryContractUI_t *msg, arr_address_t *target) { uint64_t chainid = 0; return getEthAddressStringFromBinary( - target->value, + address, msg->msg + 2, // +2 here because we've already prefixed with '0x'. chainid); } -// Set UI for "Value" screen. -static bool set_value_ui(ethQueryContractUI_t *msg, arr_uint8_t *value) { - strlcpy(msg->title, "Value", msg->titleLength); - return uint256_to_decimal(value->value, INT256_LENGTH, msg->msg, msg->msgLength); -} - void handle_query_contract_ui(ethQueryContractUI_t *msg) { context_t *context = (context_t *) msg->pluginContext; bool ret = false; @@ -232,13 +125,17 @@ void handle_query_contract_ui(ethQueryContractUI_t *msg) { case CLAIM_REGULAR_ACCOUNT: switch (msg->screenIndex) { case 0: - ret = set_claim_ui(msg, context); + ret = set_amount_ui_uint8(msg, + context->lisk.body.claim.claim_amount, + "Claim LSK"); break; case 1: ret = set_sender_public_key_ui(msg, context); break; case 2: - ret = set_recipient_ui(msg, context); + ret = set_address_ui(msg, + context->lisk.body.claim.recipient, + "Recipient Address L2"); break; default: PRINTF("Received an invalid screenIndex\n"); @@ -247,13 +144,17 @@ void handle_query_contract_ui(ethQueryContractUI_t *msg) { case CLAIM_MULTI_SIGNATURE_ACCOUNT: switch (msg->screenIndex) { case 0: - ret = set_claim_ui(msg, context); + ret = set_amount_ui_uint8(msg, + context->lisk.body.claim.claim_amount, + "Claim LSK"); break; case 1: - ret = set_sender_address_ui(msg, context); + ret = set_lisk_address_ui(msg, context); break; case 2: - ret = set_recipient_ui(msg, context); + ret = set_address_ui(msg, + context->lisk.body.claim.recipient, + "Recipient Address L2"); break; default: PRINTF("Received an invalid screenIndex\n"); @@ -262,10 +163,15 @@ void handle_query_contract_ui(ethQueryContractUI_t *msg) { case REWARD_CREATE_POSITION: switch (msg->screenIndex) { case 0: - ret = set_lock_amount_ui(msg, context); + ret = set_amount_ui_uint8(msg, + context->lisk.body.rewardCreatePosition.first, + "Lock Amount"); break; case 1: - ret = set_lock_duration_ui(msg, context); + ret = + set_decimal_ui_uint8(msg, + context->lisk.body.rewardAddUnusedRewards.data.second, + "Duration (in days)"); break; default: PRINTF("Received an invalid screenIndex\n"); @@ -275,13 +181,20 @@ void handle_query_contract_ui(ethQueryContractUI_t *msg) { case REWARD_FUND_STAKING_REWARDS: switch (msg->screenIndex) { case 0: - ret = set_unused_amount_ui(msg, context); + ret = set_amount_ui_uint8(msg, + context->lisk.body.rewardAddUnusedRewards.data.first, + "Amount"); break; case 1: - ret = set_unused_duration_ui(msg, context); + ret = + set_decimal_ui_uint8(msg, + context->lisk.body.rewardAddUnusedRewards.data.second, + "Duration (in days)"); break; case 2: - ret = set_unused_delay_ui(msg, context); + ret = set_decimal_ui_uint8(msg, + context->lisk.body.rewardAddUnusedRewards.delay, + "Delay (in days)"); break; default: PRINTF("Received an invalid screenIndex\n"); @@ -293,7 +206,9 @@ void handle_query_contract_ui(ethQueryContractUI_t *msg) { case REWARD_RESUME_UNLOCKING: case REWARD_DELETE_POSITIONS: if (msg->screenIndex < context->lisk.body.reward.lock_ids_len) { - ret = set_lock_ids_ui(msg, &context->lisk.body.reward.lock_id[msg->screenIndex]); + ret = set_decimal_ui_arr(msg, + &context->lisk.body.reward.lock_id[msg->screenIndex], + "Lock ID"); } else { PRINTF("Received an invalid screenIndex\n"); } @@ -301,18 +216,24 @@ void handle_query_contract_ui(ethQueryContractUI_t *msg) { case REWARD_INC_LOCKING_AMOUNT: switch (msg->screenIndex) { case 0: - ret = - set_lock_ids_ui(msg, &context->lisk.body.rewardIncLockingAmount.lock_id[0]); + ret = set_decimal_ui_arr(msg, + &context->lisk.body.rewardIncLockingAmount.first[0], + "Lock ID"); break; case 1: - ret = set_amount_ui(msg, &context->lisk.body.rewardIncLockingAmount.amount[0]); + ret = set_amount_ui_arr(msg, + &context->lisk.body.rewardIncLockingAmount.second[0], + "Increase Amount"); break; case 2: - ret = - set_lock_ids_ui(msg, &context->lisk.body.rewardIncLockingAmount.lock_id[1]); + ret = set_decimal_ui_arr(msg, + &context->lisk.body.rewardIncLockingAmount.first[1], + "Lock ID"); break; case 3: - ret = set_amount_ui(msg, &context->lisk.body.rewardIncLockingAmount.amount[1]); + ret = set_amount_ui_arr(msg, + &context->lisk.body.rewardIncLockingAmount.second[1], + "Increase Amount"); break; default: PRINTF("Received an invalid screenIndex\n"); @@ -321,18 +242,24 @@ void handle_query_contract_ui(ethQueryContractUI_t *msg) { case REWARD_EXTEND_DURATION: switch (msg->screenIndex) { case 0: - ret = set_lock_ids_ui(msg, &context->lisk.body.rewardExtendDuration.lock_id[0]); + ret = set_decimal_ui_arr(msg, + &context->lisk.body.rewardExtendDuration.first[0], + "Lock ID"); break; case 1: - ret = - set_duration_ui(msg, &context->lisk.body.rewardExtendDuration.duration[0]); + ret = set_decimal_ui_arr(msg, + &context->lisk.body.rewardExtendDuration.second[0], + "Duration"); break; case 2: - ret = set_lock_ids_ui(msg, &context->lisk.body.rewardExtendDuration.lock_id[1]); + ret = set_decimal_ui_arr(msg, + &context->lisk.body.rewardExtendDuration.first[1], + "Lock ID"); break; case 3: - ret = - set_duration_ui(msg, &context->lisk.body.rewardExtendDuration.duration[1]); + ret = set_decimal_ui_arr(msg, + &context->lisk.body.rewardExtendDuration.second[1], + "Duration"); break; default: PRINTF("Received an invalid screenIndex\n"); @@ -341,10 +268,12 @@ void handle_query_contract_ui(ethQueryContractUI_t *msg) { case CLAIM_AIRDROP: switch (msg->screenIndex) { case 0: - ret = set_sender_address_ui(msg, context); + ret = set_lisk_address_ui(msg, context); break; case 1: - ret = set_claim_ui(msg, context); + ret = set_amount_ui_uint8(msg, + context->lisk.body.claim.claim_amount, + "Claim Airdrop (LSK)"); break; default: PRINTF("Received an invalid screenIndex\n"); @@ -353,10 +282,14 @@ void handle_query_contract_ui(ethQueryContractUI_t *msg) { case GOVERNOR_CAST_VOTE: switch (msg->screenIndex) { case 0: - ret = set_proposal_id_ui(msg, context); + ret = set_decimal_ui_uint8(msg, + context->lisk.body.governor.data.first, + "Proposal ID"); break; case 1: - ret = set_support_ui(msg, context); + ret = set_decimal_ui_uint8(msg, + context->lisk.body.governor.data.second, + "Support"); break; default: PRINTF("Received an invalid screenIndex\n"); @@ -365,10 +298,14 @@ void handle_query_contract_ui(ethQueryContractUI_t *msg) { case GOVERNOR_CAST_VOTE_WITH_REASON: switch (msg->screenIndex) { case 0: - ret = set_proposal_id_ui(msg, context); + ret = set_decimal_ui_uint8(msg, + context->lisk.body.governor.data.first, + "Proposal ID"); break; case 1: - ret = set_support_ui(msg, context); + ret = set_decimal_ui_uint8(msg, + context->lisk.body.governor.data.second, + "Support"); break; case 2: ret = set_reason_ui(msg, &context->lisk.body.governor.reason); @@ -380,16 +317,24 @@ void handle_query_contract_ui(ethQueryContractUI_t *msg) { case GOVERNOR_PROPOSE: switch (msg->screenIndex) { case 0: - ret = set_target_ui(msg, &context->lisk.body.governorPropose.targets[0]); + ret = set_address_ui(msg, + context->lisk.body.governorPropose.data.first[0].value, + "Target Address"); break; case 1: - ret = set_value_ui(msg, &context->lisk.body.governorPropose.values[0]); + ret = set_decimal_ui_arr(msg, + &context->lisk.body.governorPropose.data.second[0], + "Value"); break; case 2: - ret = set_target_ui(msg, &context->lisk.body.governorPropose.targets[1]); + ret = set_address_ui(msg, + context->lisk.body.governorPropose.data.first[1].value, + "Target Address"); break; case 3: - ret = set_value_ui(msg, &context->lisk.body.governorPropose.values[1]); + ret = set_decimal_ui_arr(msg, + &context->lisk.body.governorPropose.data.second[1], + "Value"); break; default: PRINTF("Received an invalid screenIndex\n"); diff --git a/src/plugin.h b/src/plugin.h index e02391bd..0a56700c 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -66,6 +66,22 @@ typedef struct { uint8_t value[ADDRESS_LENGTH]; } arr_address_t; +typedef struct { + uint8_t len; + uint8_t value[PARAMETER_LENGTH]; +} string_uint8_t; + +typedef struct { + arr_uint8_t first[2]; + arr_uint8_t second[2]; + uint16_t len; +} double_arr_with_len_t; + +typedef struct { + uint8_t first[INT256_LENGTH]; + uint8_t second[INT256_LENGTH]; +} tuple_t; + // This array will be automatically expanded to map all selector_t names with the correct value. // Do not modify ! extern const uint32_t SELECTORS[SELECTOR_COUNT]; @@ -74,49 +90,36 @@ extern const uint32_t SELECTORS[SELECTOR_COUNT]; // EDIT THIS: Adapt the parameter names here. typedef enum { // Common parameters + AMOUNT, PROOF, - CLAIM_AMOUNT, + ID, + ARRAY_LENGTH, + LSK_ADDRESS, + OFFSET, RECIPIENT, + SKIPED_PARAMETER, UNEXPECTED_PARAMETER, NONE, // Claim regular account parameters PUBLIC_KEY, - ED25519_SIGNATURE, // Claim multi-sig account parameters MULTISIG_KEYS, - LSK_ADDRESS, - ED25519_SIGNATURES, // Reward contract parameters - AMOUNT, - DURATION, - LOCK_ID, - LOCK_IDS_LEN, - LOCK_ID_NEXT, - INCREASE_LEN, - OFFSET, DELAY, + DURATION, // Governor contract parameters - PROPOSAL_ID, - SUPPORT, - REASON, - REASON_LENGTH, - PROPOSE_TARGET_LEN, PROPOSE_VALUE_LEN, - TARGET_ADDRESS, SECOND_TARGET_ADDRESS, - VALUE, SECOND_VALUE, + SUPPORT, + TARGET_ADDRESS, + VALUE, } parameter; -typedef struct { - uint8_t len; - uint8_t value[PARAMETER_LENGTH]; -} string_uint8_t; - typedef struct { union { struct { @@ -126,41 +129,25 @@ typedef struct { uint8_t lsk_address[LISK_ADDRESS_LENGTH]; } claim; - struct { - uint8_t lock_amount[INT256_LENGTH]; - uint8_t lock_duration[INT256_LENGTH]; - } rewardCreatePosition; - + tuple_t rewardCreatePosition; struct { uint16_t lock_ids_len; arr_uint8_t lock_id[4]; } reward; + double_arr_with_len_t rewardIncLockingAmount; + double_arr_with_len_t rewardExtendDuration; struct { - arr_uint8_t lock_id[2]; - arr_uint8_t amount[2]; - uint16_t len; - } rewardIncLockingAmount; - struct { - arr_uint8_t lock_id[2]; - arr_uint8_t duration[2]; - uint16_t len; - } rewardExtendDuration; - struct { - uint8_t amount[INT256_LENGTH]; - uint8_t duration[INT256_LENGTH]; + tuple_t data; uint8_t delay[INT256_LENGTH]; } rewardAddUnusedRewards; struct { - uint8_t proposal_id[INT256_LENGTH]; - uint8_t support[INT256_LENGTH]; + tuple_t data; string_uint8_t reason; } governor; struct { - uint16_t target_len; + double_arr_with_len_t data; uint16_t value_len; - arr_address_t targets[2]; - arr_uint8_t values[2]; } governorPropose; } body;