Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
chore: add speculos feature around debug prints
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Dec 26, 2023
1 parent 13efa7c commit b62a8ca
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ icon = "crab_14x14.gif"

[package.metadata.ledger.nanosplus]
icon = "crab_14x14.gif"

[features]
default = []
speculos = ["ledger_device_sdk/speculos"]
7 changes: 7 additions & 0 deletions src/handlers/get_public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ use ledger_secure_sdk_sys::{
cx_hash_no_throw, cx_hash_t, cx_keccak_init_no_throw, cx_sha3_t, CX_LAST, CX_OK,
};

#[cfg(feature = "speculos")]
use ledger_device_sdk::testing;

pub fn handler_get_public_key(comm: &mut Comm, display: bool) -> Result<(), AppSW> {
let mut path = [0u32; MAX_ALLOWED_PATH_LEN];
let data = comm.get_data().map_err(|_| AppSW::WrongApduLength)?;
Expand Down Expand Up @@ -58,7 +61,11 @@ pub fn handler_get_public_key(comm: &mut Comm, display: bool) -> Result<(), AppS
}
}

#[cfg(feature = "speculos")]
testing::debug_print("showing public key\n");
if !ui_display_pk(&address)? {
#[cfg(feature = "speculos")]
testing::debug_print("denied\n");
return Err(AppSW::Deny);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/handlers/get_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
use crate::AppSW;
use core::str::FromStr;
use ledger_device_sdk::io;
#[cfg(feature = "speculos")]
use ledger_device_sdk::testing;


pub fn handler_get_version(comm: &mut io::Comm) -> Result<(), AppSW> {
#[cfg(feature = "speculos")]
testing::debug_print("enter `handler_get_version` fn\n");
if let Some((major, minor, patch)) = parse_version_string(env!("CARGO_PKG_VERSION")) {
comm.append(&[major, minor, patch]);
Ok(())
Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ use handlers::{
sign_tx::{handler_sign_tx, TxContext},
};
use ledger_device_sdk::io::{ApduHeader, Comm, Event, Reply, StatusWords};
#[cfg(feature = "speculos")]
use ledger_device_sdk::testing;

ledger_device_sdk::set_panic!(ledger_device_sdk::exiting_panic);

Expand Down Expand Up @@ -109,6 +111,8 @@ impl TryFrom<ApduHeader> for Instruction {

#[no_mangle]
extern "C" fn sample_main() {
#[cfg(feature = "speculos")]
testing::debug_print("enter `sample_main` fn\n\n");
let mut comm = Comm::new();

// display_pending_review(&mut comm);
Expand Down

0 comments on commit b62a8ca

Please sign in to comment.