Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/modules/blocktank/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})?;
Expand Down Expand Up @@ -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;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/modules/blocktank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/modules/boltz/tests.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
62 changes: 10 additions & 52 deletions src/modules/onchain/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ pub struct BitcoinAddressValidator;

impl BitcoinAddressValidator {
pub fn validate_address(address: &str) -> Result<ValidationResult, AddressError> {
println!("\nValidating address: {}", address);

let unchecked_addr = match parse_address(address) {
Ok(addr) => addr,
Err(e) => return Err(e),
Expand All @@ -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),
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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
})?;

Expand All @@ -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
})?;

Expand All @@ -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
})?;

Expand Down Expand Up @@ -2133,60 +2126,33 @@ pub async fn get_address_info(
}

fn parse_address(address: &str) -> Result<Address<NetworkUnchecked>, 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<Network, AddressError> {
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")
|| s.starts_with("tb1")
|| 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),
}
}

fn verify_network(
unchecked_addr: Address<NetworkUnchecked>,
expected_network: Network,
) -> Result<Address, AddressError> {
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<AddressType, AddressError> {
Expand Down Expand Up @@ -2220,13 +2186,5 @@ fn get_address_type(address: &str) -> Result<AddressType, AddressError> {
_ => 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)
}
2 changes: 2 additions & 0 deletions src/modules/onchain/tests.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down