Skip to content

Commit

Permalink
Merge pull request #126 from Zondax/fix/staking
Browse files Browse the repository at this point in the history
Fix/staking
  • Loading branch information
jleni authored Sep 8, 2021
2 parents 10e7fde + b27b808 commit 86c06f3
Show file tree
Hide file tree
Showing 22 changed files with 111 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ endif

APPVERSION_M=1
APPVERSION_N=0
APPVERSION_P=1
APPVERSION_P=2

$(info COIN = [$(COIN)])

Expand Down
109 changes: 103 additions & 6 deletions app/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,14 @@ parser_error_t parser_getItemTokenTransfer(const parser_context_t *ctx,
return parser_no_data;
}

bool is_stake_tx = parser_tx_obj.tx_fields.call.special_transfer_type == neuron_stake_transaction;
const bool is_stake_tx = parser_tx_obj.tx_fields.call.special_transfer_type == neuron_stake_transaction;
if (is_stake_tx) {
return parser_unexepected_error;
}

if (displayIdx == 0) {
snprintf(outKey, outKeyLen, "Transaction type");
if(is_stake_tx){
snprintf(outVal, outValLen, "Stake Neuron");
}else {
snprintf(outVal, outValLen, "Send ICP");
}
snprintf(outVal, outValLen, "Send ICP");
return parser_ok;
}

Expand Down Expand Up @@ -411,6 +411,94 @@ parser_error_t parser_getItemTokenTransfer(const parser_context_t *ctx,
return parser_no_data;
}

parser_error_t parser_getItemStakeNeuron(const parser_context_t *ctx,
uint8_t displayIdx,
char *outKey, uint16_t outKeyLen,
char *outVal, uint16_t outValLen,
uint8_t pageIdx, uint8_t *pageCount) {
MEMZERO(outKey, outKeyLen);
MEMZERO(outVal, outValLen);
snprintf(outKey, outKeyLen, "?");
snprintf(outVal, outValLen, "?");
*pageCount = 1;

uint8_t numItems = 0;
CHECK_PARSER_ERR(parser_getNumItems(ctx, &numItems))
CHECK_APP_CANARY()

call_t *fields = &parser_tx_obj.tx_fields.call;

if (displayIdx < 0 || displayIdx >= numItems) {
return parser_no_data;
}

const bool is_stake_tx = parser_tx_obj.tx_fields.call.special_transfer_type == neuron_stake_transaction;
if (!is_stake_tx) {
return parser_unexepected_error;
}

if (displayIdx == 0) {
snprintf(outKey, outKeyLen, "Transaction type");
snprintf(outVal, outValLen, "Stake Neuron");
return parser_ok;
}

if(app_mode_expert()){
if (displayIdx == 1) {
snprintf(outKey, outKeyLen, "Sender ");
return print_textual(fields->sender.data, fields->sender.len, outVal, outValLen, pageIdx, pageCount);
}

if (displayIdx == 2) {
snprintf(outKey, outKeyLen, "Subaccount ");
snprintf(outVal, outValLen, "Not set");

if (fields->pb_fields.SendRequest.has_from_subaccount) {
char buffer[100];
zxerr_t err = print_hexstring(buffer, sizeof(buffer), fields->pb_fields.SendRequest.from_subaccount.sub_account, 32);
if (err != zxerr_ok) {
return parser_unexepected_error;
}
pageString(outVal, outValLen, buffer, pageIdx, pageCount);
}

return parser_ok;
}
displayIdx -= 2;
}

if (displayIdx == 1) {
snprintf(outKey, outKeyLen, "From account");
return print_accountBytes(fields->sender, &fields->pb_fields.SendRequest,
outVal, outValLen,
pageIdx, pageCount);
}

if (displayIdx == 2) {
snprintf(outKey, outKeyLen, "Payment (ICP)");
PARSER_ASSERT_OR_ERROR(fields->pb_fields.SendRequest.payment.has_receiver_gets, parser_unexpected_number_items)
return print_ICP(fields->pb_fields.SendRequest.payment.receiver_gets.e8s,
outVal, outValLen,
pageIdx, pageCount);
}

if (displayIdx == 3) {
snprintf(outKey, outKeyLen, "Maximum fee (ICP)");
PARSER_ASSERT_OR_ERROR(fields->pb_fields.SendRequest.has_max_fee, parser_unexpected_number_items)
return print_ICP(fields->pb_fields.SendRequest.max_fee.e8s,
outVal, outValLen,
pageIdx, pageCount);
}

if (displayIdx == 4) {
snprintf(outKey, outKeyLen, "Memo");
PARSER_ASSERT_OR_ERROR(fields->pb_fields.SendRequest.has_memo, parser_unexpected_number_items)
return print_u64(fields->pb_fields.SendRequest.memo.memo, outVal, outValLen, pageIdx, pageCount);
}

return parser_no_data;
}

parser_error_t parser_getItemStartStopDissolve(uint8_t displayIdx,
char *outKey, uint16_t outKeyLen,
char *outVal, uint16_t outValLen,
Expand Down Expand Up @@ -666,6 +754,15 @@ parser_error_t parser_getItem(const parser_context_t *ctx,
case call: {
switch(parser_tx_obj.tx_fields.call.pbtype) {
case pb_sendrequest : {
const bool is_stake_tx = parser_tx_obj.tx_fields.call.special_transfer_type == neuron_stake_transaction;

if (is_stake_tx) {
return parser_getItemStakeNeuron(ctx, displayIdx,
outKey, outKeyLen,
outVal, outValLen,
pageIdx, pageCount);
}

return parser_getItemTokenTransfer(ctx, displayIdx,
outKey, outKeyLen,
outVal, outValLen,
Expand Down
9 changes: 6 additions & 3 deletions app/src/parser_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,13 @@ uint8_t _getNumItems(const parser_context_t *c, const parser_tx_t *v) {
case call: {
switch(v->tx_fields.call.pbtype) {
case pb_sendrequest: {
if (!app_mode_expert()) {
return 6;
const bool is_stake_tx = v->tx_fields.call.special_transfer_type == neuron_stake_transaction;

if (is_stake_tx) {
return app_mode_expert() ? 7 : 5;
}
return 8;

return app_mode_expert() ? 8 : 6;
}

case pb_listneurons : {
Expand Down
Binary file modified tests_zemu/snapshots/s-mainmenu/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-mainmenu/00011.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-sign_staketx_normal/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-sign_staketx_normal/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-sign_staketx_normal/00005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-sign_staketx_normal/00006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-sign_staketx_normal/00007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed tests_zemu/snapshots/s-sign_staketx_normal/00008.png
Binary file not shown.
Binary file removed tests_zemu/snapshots/s-sign_staketx_normal/00009.png
Binary file not shown.
Binary file modified tests_zemu/snapshots/x-mainmenu/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/x-mainmenu/00011.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/x-sign_staketx_normal/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/x-sign_staketx_normal/00005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/x-sign_staketx_normal/00006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/x-sign_staketx_normal/00007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/x-sign_staketx_normal/00008.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed tests_zemu/snapshots/x-sign_staketx_normal/00009.png
Binary file not shown.
Binary file removed tests_zemu/snapshots/x-sign_staketx_normal/00010.png
Binary file not shown.
2 changes: 1 addition & 1 deletion tests_zemu/tests/phase2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('Phase2', function () {
// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot())

await sim.compareSnapshotsAndAccept('.', `${m.prefix.toLowerCase()}-sign_staketx_normal`, m.name === 'nanos' ? 8 : 9)
await sim.compareSnapshotsAndAccept('.', `${m.prefix.toLowerCase()}-sign_staketx_normal`, m.name === 'nanos' ? 6 : 7)

const signatureResponse = await respRequest
console.log(signatureResponse)
Expand Down

0 comments on commit 86c06f3

Please sign in to comment.