From d7c5e21811e7ee567e26cc818b9ba4069962174c Mon Sep 17 00:00:00 2001 From: coreyphillips Date: Fri, 7 Aug 2026 08:49:01 -0400 Subject: [PATCH] fix: stop writing secrets and user data to stdout The crate ships inside a wallet, and println!/eprintln! bypass the log facade the platforms route to their own sinks, so anything printed can be captured by a debugger, a redirected stdio stream or a sysdiagnose bundle. Removes all 21 print macros from non-test library code: 15 deleted, 6 routed through log::*. --- src/lib.rs | 8 +++- src/modules/blocktank/api.rs | 4 +- src/modules/blocktank/tests.rs | 2 + src/modules/boltz/tests.rs | 2 + src/modules/onchain/implementation.rs | 62 +++++---------------------- src/modules/onchain/tests.rs | 2 + 6 files changed, 24 insertions(+), 56 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2eaca51..1dd739b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,9 @@ +// This crate ships inside a wallet, so nothing here may write to the process +// stdio. `println!`/`eprintln!` bypass the `log` facade the platforms route to +// their own sinks, and anything printed can be captured by a debugger, a +// redirected stdio stream or a sysdiagnose bundle. Use `log::*` instead. +#![deny(clippy::print_stdout, clippy::print_stderr, clippy::dbg_macro)] + uniffi::setup_scaffolding!(); // Initialize Android logger so Rust log::info! calls appear in logcat @@ -2281,7 +2287,7 @@ pub extern "system" fn Java_to_bitkit_services_BluetoothInit_nativeInit( } Err(e) => { // Log the error - this will be visible in logcat - eprintln!("Failed to initialize btleplug: {:?}", e); + log::error!("Failed to initialize btleplug: {:?}", e); jni::sys::JNI_FALSE } } diff --git a/src/modules/blocktank/api.rs b/src/modules/blocktank/api.rs index bb05e40..10b6d92 100644 --- a/src/modules/blocktank/api.rs +++ b/src/modules/blocktank/api.rs @@ -32,8 +32,6 @@ impl BlocktankDB { .create_order(lsp_balance_sat, channel_expiry_weeks, options) .await; - println!("Raw API response: {:#?}", response); - let order = response.map_err(|e| BlocktankError::DataError { error_details: format!("Failed to create order with Blocktank client: {}", e), })?; @@ -204,7 +202,7 @@ impl BlocktankDB { match self.refresh_cjit_entry(&entry_id).await { Ok(entry) => refreshed_entries.push(entry), Err(e) => { - println!("Warning: Failed to refresh CJIT entry {}: {}", entry_id, e); + log::warn!("Failed to refresh CJIT entry {}: {}", entry_id, e); continue; } } diff --git a/src/modules/blocktank/tests.rs b/src/modules/blocktank/tests.rs index 376e983..f85ef37 100644 --- a/src/modules/blocktank/tests.rs +++ b/src/modules/blocktank/tests.rs @@ -4,6 +4,8 @@ const STAGING_SERVER: &str = "https://api.stag.blocktank.to/blocktank/api/v2"; #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] + use super::*; use crate::modules::blocktank::liquidity::{ calculate_channel_liquidity_options, get_default_lsp_balance, ChannelLiquidityParams, diff --git a/src/modules/boltz/tests.rs b/src/modules/boltz/tests.rs index f4baecd..8272472 100644 --- a/src/modules/boltz/tests.rs +++ b/src/modules/boltz/tests.rs @@ -1,3 +1,5 @@ +#![allow(clippy::print_stdout)] + use crate::modules::boltz::api::{get_reverse_limits, get_submarine_limits}; use crate::modules::boltz::claim::{claim_reverse_swap_guarded, ClaimOutcome}; use crate::modules::boltz::errors::BoltzError; diff --git a/src/modules/onchain/implementation.rs b/src/modules/onchain/implementation.rs index 6f28870..071a183 100644 --- a/src/modules/onchain/implementation.rs +++ b/src/modules/onchain/implementation.rs @@ -57,8 +57,6 @@ pub struct BitcoinAddressValidator; impl BitcoinAddressValidator { pub fn validate_address(address: &str) -> Result { - println!("\nValidating address: {}", address); - let unchecked_addr = match parse_address(address) { Ok(addr) => addr, Err(e) => return Err(e), @@ -73,8 +71,6 @@ impl BitcoinAddressValidator { } let address_type = get_address_type(address)?; - println!("✓ Validation successful!"); - Ok(ValidationResult { address: address.to_string(), network: NetworkType::from(expected_network), @@ -86,12 +82,9 @@ impl BitcoinAddressValidator { let external_word_count = word_count.map(|wc| wc.into()); let mnemonic = bitcoin_address_generator::generate_mnemonic(external_word_count, None); match mnemonic { - Ok(mnemonic) => { - println!("✓ Generated mnemonic: {}", mnemonic); - Ok(mnemonic) - } + Ok(mnemonic) => Ok(mnemonic), Err(e) => { - println!("✗ Failed to generate mnemonic: {:?}", e); + log::error!("Failed to generate mnemonic: {:?}", e); Err(AddressError::MnemonicGenerationFailed) } } @@ -145,7 +138,7 @@ impl BitcoinAddressValidator { bip39_passphrase, ) .map_err(|e| { - println!("✗ Failed to derive address: {:?}", e); + log::error!("Failed to derive address: {:?}", e); AddressError::AddressDerivationFailed })?; @@ -171,7 +164,7 @@ impl BitcoinAddressValidator { count, ) .map_err(|e| { - println!("✗ Failed to derive addresses: {:?}", e); + log::error!("Failed to derive addresses: {:?}", e); AddressError::AddressDerivationFailed })?; @@ -191,7 +184,7 @@ impl BitcoinAddressValidator { bip39_passphrase, ) .map_err(|e| { - println!("✗ Failed to derive private key: {:?}", e); + log::error!("Failed to derive private key: {:?}", e); AddressError::AddressDerivationFailed })?; @@ -2133,21 +2126,12 @@ pub async fn get_address_info( } fn parse_address(address: &str) -> Result, AddressError> { - Address::from_str(address) - .map_err(|e| { - println!("✗ Failed to parse address: {:?}", e); - AddressError::InvalidAddress - }) - .map(|addr| { - println!("✓ Successfully parsed address"); - addr - }) + Address::from_str(address).map_err(|_| AddressError::InvalidAddress) } fn determine_network(address: &str) -> Result { match address { s if s.starts_with("1") || s.starts_with("3") || s.starts_with("bc1") => { - println!("✓ Determined network: Bitcoin"); Ok(Network::Bitcoin) } s if s.starts_with("2") @@ -2155,17 +2139,10 @@ fn determine_network(address: &str) -> Result { || s.starts_with("m") || s.starts_with("n") => { - println!("✓ Determined network: Testnet"); Ok(Network::Testnet) } - s if s.starts_with("bcrt1") => { - println!("✓ Determined network: Regtest"); - Ok(Network::Regtest) - } - _ => { - println!("✗ Could not determine network"); - Err(AddressError::InvalidNetwork) - } + s if s.starts_with("bcrt1") => Ok(Network::Regtest), + _ => Err(AddressError::InvalidNetwork), } } @@ -2173,20 +2150,9 @@ fn verify_network( unchecked_addr: Address, expected_network: Network, ) -> Result { - println!( - "Attempting to verify address for network: {:?}", - expected_network - ); unchecked_addr .require_network(expected_network) - .map_err(|e| { - println!("✗ Network verification failed: {:?}", e); - AddressError::InvalidNetwork - }) - .map(|addr| { - println!("✓ Address verified for network"); - addr - }) + .map_err(|_| AddressError::InvalidNetwork) } fn get_address_type(address: &str) -> Result { @@ -2220,13 +2186,5 @@ fn get_address_type(address: &str) -> Result { _ => Some(AddressType::Unknown), }; - address_type - .map(|t| { - println!("✓ Determined address type: {:?}", t); - t - }) - .ok_or_else(|| { - println!("✗ Could not determine address type"); - AddressError::InvalidAddress - }) + address_type.ok_or(AddressError::InvalidAddress) } diff --git a/src/modules/onchain/tests.rs b/src/modules/onchain/tests.rs index 2bd0577..84158b2 100644 --- a/src/modules/onchain/tests.rs +++ b/src/modules/onchain/tests.rs @@ -1,5 +1,7 @@ #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] + use super::super::implementation::{ onchain_to_bdk_network, run_account_info_blocking, LegacyRnNativeSegwitRecoverySpendable, };