Skip to content

Commit

Permalink
chore: improve log::info of apdu-s
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Feb 12, 2024
1 parent 72fde37 commit a77f2da
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ fn hd_path_to_bytes(hd_path: &slip10::BIP32Path) -> Vec<u8> {
.collect::<Vec<u8>>()
}

#[inline(always)]
fn log_command(index: usize, is_last_chunk: bool, command: &APDUCommand<Vec<u8>>) {
log::info!(
"APDU in{}: {}",
if is_last_chunk {
" (last)".to_string()
} else {
format!(" ({})", index)
},
hex::encode(&command.serialize())
);
}

/// Get the version of NEAR App installed on Ledger
///
/// # Returns
Expand Down Expand Up @@ -329,7 +342,7 @@ pub fn sign_transaction(
p2: NETWORK_ID,
data: chunk.to_vec(),
};
log::info!("APDU in: {}", hex::encode(&command.serialize()));
log_command(i, is_last_chunk, &command);
match transport.exchange(&command) {
Ok(response) => {
log::info!(
Expand Down Expand Up @@ -402,7 +415,7 @@ pub fn sign_message_nep413(
p2: NETWORK_ID,
data: chunk.to_vec(),
};
log::info!("APDU in: {}", hex::encode(&command.serialize()));
log_command(i, is_last_chunk, &command);
match transport.exchange(&command) {
Ok(response) => {
log::info!(
Expand Down Expand Up @@ -460,7 +473,7 @@ pub fn sign_message_nep366_delegate_action(
p2: NETWORK_ID,
data: chunk.to_vec(),
};
log::info!("APDU in: {}", hex::encode(&command.serialize()));
log_command(i, is_last_chunk, &command);
match transport.exchange(&command) {
Ok(response) => {
log::info!(
Expand Down

0 comments on commit a77f2da

Please sign in to comment.