anya-core 1.2.0

Enterprise-grade Bitcoin Infrastructure Platform
Documentation
// [AIR-3][AIS-3][BPC-3][RES-3] Fix for the string_to_address function
pub fn string_to_address(address_str: &str) -> Result<Address<NetworkChecked>, Box<dyn Error>> {
    // Accepts bc1p... and tb1p... Taproot addresses
    // [AIR-3][AIS-3][BPC-3][RES-3] Use FromStr trait to parse address
    let address = Address::from_str(address_str)
        .map_err(|_| Box::new(BitcoinError::InvalidAddress(address_str.to_string())) as Box<dyn Error>)?;
    
    // [AIR-3][AIS-3][BPC-3][RES-3] Require the address to be network checked
    // This follows official Bitcoin Improvement Proposals (BIPs) standards for network validation
    let checked_address = address.require_network(Network::Bitcoin)
        .map_err(|_| Box::new(BitcoinError::InvalidAddress(format!("Network validation failed for {}", address_str))) as Box<dyn Error>)?;
    
    Ok(checked_address)
}

// [AIR-3][AIS-3][BPC-3][RES-3] Fix for the from_str function
pub fn from_str(address_str: &str) -> Result<Address<NetworkChecked>, Box<dyn Error>> {
    // [AIR-3][AIS-3][BPC-3][RES-3] Use FromStr trait to parse address
    let address = Address::from_str(address_str)
        .map_err(|_| Box::new(BitcoinError::InvalidAddress(address_str.to_string())) as Box<dyn Error>)?;
    
    // [AIR-3][AIS-3][BPC-3][RES-3] Require the address to be network checked
    // This follows official Bitcoin Improvement Proposals (BIPs) standards for network validation
    let checked_address = address.require_network(Network::Bitcoin)
        .map_err(|_| Box::new(BitcoinError::InvalidAddress(format!("Network validation failed for {}", address_str))) as Box<dyn Error>)?;
    
    Ok(checked_address)
}