diff --git a/src/util/mod.rs b/src/util/mod.rs index 65ba7a14e..e882341e9 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -4,6 +4,6 @@ pub mod path; pub mod token_list; pub use net_name::NetworkName; -pub use parse::{assign_id, generate_id, parse_params}; +pub use parse::{assign_id, decimals, generate_id, to_apo}; pub use path::{expand_path, join_config_path}; pub use token_list::TokenList; diff --git a/src/util/parse.rs b/src/util/parse.rs index d04930fc6..4abde0747 100644 --- a/src/util/parse.rs +++ b/src/util/parse.rs @@ -132,31 +132,52 @@ pub fn assign_id(network: &str, token: &str, tokenlist: TokenList) -> Result Result<(String, u64)> { +//pub fn parse_params( +// network: &str, +// token: &str, +// amount: u64, +// tokenlist: TokenList, +//) -> Result<(String, u64)> { +// match NetworkName::from_str(network)? { +// NetworkName::Solana => match token { +// "solana" | "sol" => { +// let token_id = "So11111111111111111111111111111111111111112"; +// let decimals = 9; +// let amount_in_apo = amount * u64::pow(10, decimals as u32); +// Ok((token_id.to_string(), amount_in_apo)) +// } +// tkn => { +// let token_id = symbol_to_id(tkn, tokenlist.clone())?; +// let decimals = tokenlist.search_decimal(tkn)?; +// let amount_in_apo = amount * u64::pow(10, decimals as u32); +// Ok((token_id, amount_in_apo)) +// } +// }, +// NetworkName::Bitcoin => Err(Error::NetworkParseError), +// } +//} +// +pub fn decimals(network: &str, token: &str, tokenlist: TokenList) -> Result { match NetworkName::from_str(network)? { NetworkName::Solana => match token { "solana" | "sol" => { - let token_id = "So11111111111111111111111111111111111111112"; let decimals = 9; - let amount_in_apo = amount * u64::pow(10, decimals as u32); - Ok((token_id.to_string(), amount_in_apo)) + Ok(decimals) } tkn => { - let token_id = symbol_to_id(tkn, tokenlist.clone())?; let decimals = tokenlist.search_decimal(tkn)?; - let amount_in_apo = amount * u64::pow(10, decimals as u32); - Ok((token_id, amount_in_apo)) + Ok(decimals) } }, NetworkName::Bitcoin => Err(Error::NetworkParseError), } } +pub fn to_apo(amount: f64, decimals: u32) -> Result { + let apo = amount as u64 * u64::pow(10, decimals as u32); + Ok(apo) +} + pub fn symbol_to_id(token: &str, tokenlist: TokenList) -> Result { let vec: Vec = token.chars().collect(); let mut counter = 0;