Skip to content

Commit

Permalink
fix: Code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
muzaffarbhat07 committed Jan 20, 2025
1 parent e62862e commit 05a0af9
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 50 deletions.
31 changes: 16 additions & 15 deletions apps/solana_app/solana_sign_txn.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,7 @@ STATIC bool solana_handle_initiate_query(const solana_query_t *query) {
return false;
}

snprintf(
msg, sizeof(msg), UI_TEXT_SIGN_TXN_PROMPT, SOLANA_NAME, wallet_name
);
snprintf(msg, sizeof(msg), UI_TEXT_SIGN_TXN_PROMPT, SOLANA_NAME, wallet_name);

// Take user consent to sign the transaction for the wallet
if (!core_confirmation(msg, solana_send_error)) {
Expand Down Expand Up @@ -539,9 +537,9 @@ static bool verify_solana_transfer_token_transaction() {
const uint8_t transfer_instruction_index =
solana_txn_context->transaction_info.transfer_instruction_index;

const uint8_t* token_mint = solana_txn_context->transaction_info
.instruction[transfer_instruction_index]
.program.transfer_checked.token_mint;
const uint8_t *token_mint = solana_txn_context->transaction_info
.instruction[transfer_instruction_index]
.program.transfer_checked.token_mint;
const solana_token_program_t *contract = NULL;
if (!is_token_whitelisted(token_mint, &contract)) {
// Contract Unverifed, Display warning
Expand All @@ -558,21 +556,20 @@ static bool verify_solana_transfer_token_transaction() {
return false;
}

if (!core_scroll_page(ui_text_verify_token_address,
mint_address,
solana_send_error)) {
if (!core_scroll_page(
ui_text_verify_token_address, mint_address, solana_send_error)) {
return false;
}

const uint8_t token_decimals = solana_txn_context->transaction_info
.instruction[transfer_instruction_index]
.program.transfer_checked.decimals;
.instruction[transfer_instruction_index]
.program.transfer_checked.decimals;

char display[50] = {'\0'};
snprintf(display,
sizeof(display),
ui_text_verify_token_decimals,
token_decimals);
sizeof(display),
ui_text_verify_token_decimals,
token_decimals);

if (!core_confirmation(display, solana_send_error)) {
return false;
Expand All @@ -586,7 +583,11 @@ static bool verify_solana_transfer_token_transaction() {
contract = &empty_contract;
} else {
char msg[100] = "";
snprintf(msg, sizeof(msg), UI_TEXT_SEND_TOKEN_PROMPT, contract->symbol, SOLANA_NAME);
snprintf(msg,
sizeof(msg),
UI_TEXT_SEND_TOKEN_PROMPT,
contract->symbol,
SOLANA_NAME);
if (!core_confirmation(msg, solana_send_error)) {
return false;
}
Expand Down
68 changes: 36 additions & 32 deletions apps/solana_app/solana_txn_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ int solana_byte_array_to_unsigned_txn(uint8_t *byte_array,
&error);
if (error != SOL_OK)
return error;
if (i == utxn->transfer_instruction_index && utxn->instruction[i].opaque_data_length == 0)
if (i == utxn->transfer_instruction_index &&
utxn->instruction[i].opaque_data_length == 0)
return SOL_D_MIN_LENGTH;

utxn->instruction[i].opaque_data = byte_array + offset;
Expand Down Expand Up @@ -221,9 +222,9 @@ int solana_byte_array_to_unsigned_txn(uint8_t *byte_array,
.account_addresses_index +
1) *
SOLANA_ACCOUNT_ADDRESS_LENGTH);
utxn->instruction[transfer_instruction_index].program.transfer.lamports =
U64_READ_LE_ARRAY(
utxn->instruction[transfer_instruction_index].opaque_data + 4);
utxn->instruction[transfer_instruction_index]
.program.transfer.lamports = U64_READ_LE_ARRAY(
utxn->instruction[transfer_instruction_index].opaque_data + 4);
break;

default:
Expand All @@ -239,41 +240,44 @@ int solana_byte_array_to_unsigned_txn(uint8_t *byte_array,
*(utxn->instruction[transfer_instruction_index].opaque_data);

switch (instruction_enum) {
case STPI_TRANSFER_CHECKED: // transfer checked instruction
case STPI_TRANSFER_CHECKED: // transfer checked instruction
utxn->instruction[transfer_instruction_index]
.program.transfer_checked.source =
utxn->account_addresses +
(*(utxn->instruction[transfer_instruction_index]
.account_addresses_index +
0) *
SOLANA_ACCOUNT_ADDRESS_LENGTH);
.program.transfer_checked.source =
utxn->account_addresses +
(*(utxn->instruction[transfer_instruction_index]
.account_addresses_index +
0) *
SOLANA_ACCOUNT_ADDRESS_LENGTH);
utxn->instruction[transfer_instruction_index]
.program.transfer_checked.token_mint =
utxn->account_addresses +
(*(utxn->instruction[transfer_instruction_index]
.account_addresses_index +
1) *
SOLANA_ACCOUNT_ADDRESS_LENGTH);
.program.transfer_checked.token_mint =
utxn->account_addresses +
(*(utxn->instruction[transfer_instruction_index]
.account_addresses_index +
1) *
SOLANA_ACCOUNT_ADDRESS_LENGTH);
utxn->instruction[transfer_instruction_index]
.program.transfer_checked.destination =
utxn->account_addresses +
(*(utxn->instruction[transfer_instruction_index]
.account_addresses_index +
2) *
SOLANA_ACCOUNT_ADDRESS_LENGTH);
.account_addresses_index +
2) *
SOLANA_ACCOUNT_ADDRESS_LENGTH);
utxn->instruction[transfer_instruction_index]
.program.transfer_checked.owner =
utxn->account_addresses +
(*(utxn->instruction[transfer_instruction_index]
.account_addresses_index +
3) *
SOLANA_ACCOUNT_ADDRESS_LENGTH);
utxn->instruction[transfer_instruction_index].program.transfer_checked.amount =
U64_READ_LE_ARRAY(
utxn->instruction[transfer_instruction_index].opaque_data + 1);
utxn->instruction[transfer_instruction_index].program.transfer_checked.decimals =
*(utxn->instruction[transfer_instruction_index].opaque_data + sizeof(uint64_t) + 1); // decimal value comes after amount(which is a u64)
break;
.program.transfer_checked.owner =
utxn->account_addresses +
(*(utxn->instruction[transfer_instruction_index]
.account_addresses_index +
3) *
SOLANA_ACCOUNT_ADDRESS_LENGTH);
utxn->instruction[transfer_instruction_index]
.program.transfer_checked.amount = U64_READ_LE_ARRAY(
utxn->instruction[transfer_instruction_index].opaque_data + 1);
utxn->instruction[transfer_instruction_index]
.program.transfer_checked.decimals =
*(utxn->instruction[transfer_instruction_index].opaque_data +
sizeof(uint64_t) +
1); // decimal value comes after amount(which is a u64)
break;

default:
break;
Expand Down
6 changes: 3 additions & 3 deletions apps/solana_app/solana_txn_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ typedef struct solana_token_transfer_checked_data {
uint8_t *source;
uint8_t *token_mint;
uint8_t *destination;
uint8_t *owner; // signer/owner of the source account
uint8_t *owner; // signer/owner of the source account
uint64_t amount;
uint8_t decimals;
} solana_token_transfer_checked_data;
Expand Down Expand Up @@ -146,8 +146,8 @@ typedef struct solana_unsigned_txn {

uint8_t *blockhash;

uint16_t
instructions_count; // deserialization only supports max 2 instructions: create account and transfer
uint16_t instructions_count; // deserialization only supports max 2
// instructions: create account and transfer
solana_instruction instruction[2]; ///< Expects max 2 instructions
uint8_t transfer_instruction_index;

Expand Down

0 comments on commit 05a0af9

Please sign in to comment.