Просмотр исходного кода

disabled parse_params. replaced with to_apo() and decimals()

lunar-mining 4 лет назад
Родитель
Сommit
3190f622d2
2 измененных файлов с 34 добавлено и 13 удалено
  1. 1 1
      src/util/mod.rs
  2. 33 12
      src/util/parse.rs

+ 1 - 1
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;

+ 33 - 12
src/util/parse.rs

@@ -132,31 +132,52 @@ pub fn assign_id(network: &str, token: &str, tokenlist: TokenList) -> Result<Str
     }
 }
 
-pub fn parse_params(
-    network: &str,
-    token: &str,
-    amount: u64,
-    tokenlist: TokenList,
-) -> 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<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))
+                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<u64> {
+    let apo = amount as u64 * u64::pow(10, decimals as u32);
+    Ok(apo)
+}
+
 pub fn symbol_to_id(token: &str, tokenlist: TokenList) -> Result<String> {
     let vec: Vec<char> = token.chars().collect();
     let mut counter = 0;