forked from solana-labs/ledger-app-solana
-
Notifications
You must be signed in to change notification settings - Fork 26
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
Fbe/sol token swap #107
Open
fbeutin-ledger
wants to merge
1
commit into
y333_241030/token_account_owner_display
Choose a base branch
from
fbe/sol_token_swap
base: y333_241030/token_account_owner_display
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fbe/sol token swap #107
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#include "io.h" | ||
#include "io_utils.h" | ||
#include "os.h" | ||
#include "ux.h" | ||
#include "cx.h" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,14 @@ | |
#include "swap_lib_calls.h" | ||
#include "swap_utils.h" | ||
#include "sol/printer.h" | ||
#include "util.h" | ||
|
||
#define MAX_SWAP_TOKEN_LENGTH 15 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already defined in |
||
|
||
typedef struct swap_validated_s { | ||
bool initialized; | ||
uint8_t decimals; | ||
char ticker[MAX_SWAP_TOKEN_LENGTH]; | ||
uint64_t amount; | ||
char recipient[BASE58_PUBKEY_LENGTH]; | ||
} swap_validated_t; | ||
|
@@ -18,12 +23,6 @@ static uint8_t *G_swap_sign_return_value_address; | |
|
||
// Save the data validated during the Exchange app flow | ||
bool copy_transaction_parameters(create_transaction_parameters_t *params) { | ||
// Ensure no subcoin configuration | ||
if (params->coin_configuration != NULL || params->coin_configuration_length != 0) { | ||
PRINTF("No coin_configuration expected\n"); | ||
return false; | ||
} | ||
|
||
// Ensure no extraid | ||
if (params->destination_address_extra_id == NULL) { | ||
PRINTF("destination_address_extra_id expected\n"); | ||
|
@@ -39,6 +38,22 @@ bool copy_transaction_parameters(create_transaction_parameters_t *params) { | |
swap_validated_t swap_validated; | ||
memset(&swap_validated, 0, sizeof(swap_validated)); | ||
|
||
// Parse config and save decimals and ticker | ||
// If there is no coin_configuration, consider that we are doing a SOL swap | ||
if (params->coin_configuration == NULL) { | ||
memcpy(swap_validated.ticker, "SOL", sizeof("SOL")); | ||
swap_validated.decimals = SOL_DECIMALS; | ||
} else { | ||
if (!swap_parse_config(params->coin_configuration, | ||
params->coin_configuration_length, | ||
swap_validated.ticker, | ||
sizeof(swap_validated.ticker), | ||
&swap_validated.decimals)) { | ||
PRINTF("Fail to parse coin_configuration\n"); | ||
return false; | ||
} | ||
} | ||
|
||
// Save recipient | ||
strlcpy(swap_validated.recipient, | ||
params->destination_address, | ||
|
@@ -72,13 +87,19 @@ bool check_swap_amount(const char *title, const char *text) { | |
return false; | ||
} | ||
|
||
if (strcmp(title, "Transfer") != 0) { | ||
PRINTF("Refused field '%s', expecting 'Transfer'\n", title); | ||
char expected_title[MAX(sizeof("Transfer tokens"), sizeof("Transfer"))] = {'\0'}; | ||
if (is_token_transaction()) { | ||
strcpy(expected_title, "Transfer tokens"); | ||
} else { | ||
strcpy(expected_title, "Transfer"); | ||
} | ||
if (strcmp(title, expected_title) != 0) { | ||
PRINTF("Refused title '%s', expecting '%s'\n", title, expected_title); | ||
return false; | ||
} | ||
|
||
char validated_amount[MAX_PRINTABLE_AMOUNT_SIZE]; | ||
if (print_amount(G_swap_validated.amount, validated_amount, sizeof(validated_amount)) != 0) { | ||
if (print_token_amount(G_swap_validated.amount, G_swap_validated.ticker, G_swap_validated.decimals, validated_amount, sizeof(validated_amount)) != 0) { | ||
PRINTF("Conversion failed\n"); | ||
return false; | ||
} | ||
|
@@ -98,8 +119,14 @@ bool check_swap_recipient(const char *title, const char *text) { | |
return false; | ||
} | ||
|
||
if (strcmp(title, "Recipient") != 0) { | ||
PRINTF("Refused field '%s', expecting 'Recipient'\n", title); | ||
char expected_title[MAX(sizeof("To (token account)"), sizeof("Recipient"))] = {'\0'}; | ||
if (is_token_transaction()) { | ||
strcpy(expected_title, "To (token account)"); | ||
} else { | ||
strcpy(expected_title, "Recipient"); | ||
} | ||
if (strcmp(title, expected_title) != 0) { | ||
PRINTF("Refused title '%s', expecting '%s'\n", title, expected_title); | ||
return false; | ||
} | ||
|
||
|
@@ -116,3 +143,7 @@ void __attribute__((noreturn)) finalize_exchange_sign_transaction(bool is_succes | |
*G_swap_sign_return_value_address = is_success; | ||
os_lib_end(); | ||
} | ||
|
||
bool is_token_transaction() { | ||
return (memcmp(G_swap_validated.ticker, "SOL", sizeof("SOL")) != 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we use the macro already defined in the SDK: https://github.com/LedgerHQ/ledger-secure-sdk/blob/a2be76cb8a7cf66079ad37101c33853a3278d2d3/include/os_math.h#L4 ?