use crate::error::{Result, ZeraError};
pub const ZRA_FALLBACK_DENOMINATION: &str = "1000000000";
pub fn get_denomination_fallback(contract_id: &str) -> Result<String> {
match contract_id {
"$ZRA+0000" => Ok(ZRA_FALLBACK_DENOMINATION.to_string()),
_ => Err(ZeraError::Validation(format!(
"No denomination fallback configured for contract ID: {contract_id}. Please add a denomination fallback for this contract."
))),
}
}
pub fn has_denomination_fallback(contract_id: &str) -> bool {
matches!(contract_id, "$ZRA+0000")
}
pub fn get_decimal_places_from_denomination(denomination: &str) -> Result<u32> {
if denomination.is_empty() || !denomination.chars().all(|c| c.is_ascii_digit()) {
return Err(ZeraError::Validation(
"Denomination must be a valid number string".to_string(),
));
}
if denomination == "0" {
return Err(ZeraError::Validation(
"Denomination must be greater than 0".to_string(),
));
}
Ok(denomination.len().saturating_sub(1) as u32)
}