From da472dc2b72061fb4d47de95dcb898f80133d5b4 Mon Sep 17 00:00:00 2001 From: ghassmo Date: Wed, 6 Oct 2021 09:51:15 +0300 Subject: [PATCH] save allocations by passing a reference of token list --- src/bin/darkfid.rs | 6 +++--- src/util/parse.rs | 6 +++--- src/util/token_list.rs | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/bin/darkfid.rs b/src/bin/darkfid.rs index 0300e2a27..45d22843c 100644 --- a/src/bin/darkfid.rs +++ b/src/bin/darkfid.rs @@ -210,7 +210,7 @@ impl Darkfid { let network = network.as_str().unwrap(); - let token_id = match assign_id(&network, &token, self.sol_tokenlist.clone()) { + let token_id = match assign_id(&network, &token, &self.sol_tokenlist.clone()) { Ok(t) => t, Err(e) => { debug!(target: "DARKFID", "TOKEN ID IS ERR"); @@ -286,7 +286,7 @@ impl Darkfid { let amount = amount.as_f64().unwrap(); - let decimals = match decimals(network, token, self.sol_tokenlist.clone()) { + let decimals = match decimals(network, token, &self.sol_tokenlist.clone()) { Ok(d) => d, Err(e) => { return JsonResult::Err(jsonerr(InternalError, Some(e.to_string()), id)); @@ -300,7 +300,7 @@ impl Darkfid { } }; - let token_id = match assign_id(&network, &token, self.sol_tokenlist.clone()) { + let token_id = match assign_id(&network, &token, &self.sol_tokenlist.clone()) { Ok(t) => t, Err(e) => { debug!(target: "DARKFID", "TOKEN ID IS ERR"); diff --git a/src/util/parse.rs b/src/util/parse.rs index f69b4a847..416649551 100644 --- a/src/util/parse.rs +++ b/src/util/parse.rs @@ -43,7 +43,7 @@ pub fn generate_id(tkn_str: &str, network: &NetworkName) -> Result { Ok(token_id) } -pub fn assign_id(network: &str, _token: &str, _tokenlist: SolTokenList) -> Result { +pub fn assign_id(network: &str, _token: &str, _tokenlist: &SolTokenList) -> Result { match NetworkName::from_str(network)? { #[cfg(feature = "sol")] NetworkName::Solana => match _token.to_lowercase().as_str() { @@ -68,7 +68,7 @@ pub fn assign_id(network: &str, _token: &str, _tokenlist: SolTokenList) -> Resul } } -pub fn decimals(network: &str, _token: &str, _tokenlist: SolTokenList) -> Result { +pub fn decimals(network: &str, _token: &str, _tokenlist: &SolTokenList) -> Result { match NetworkName::from_str(network)? { #[cfg(feature = "sol")] NetworkName::Solana => match _token { @@ -96,7 +96,7 @@ pub fn decimals(network: &str, _token: &str, _tokenlist: SolTokenList) -> Result // Ok(apo) //} -pub fn symbol_to_id(token: &str, tokenlist: SolTokenList) -> Result { +pub fn symbol_to_id(token: &str, tokenlist: &SolTokenList) -> Result { let vec: Vec = token.chars().collect(); let mut counter = 0; for c in vec { diff --git a/src/util/token_list.rs b/src/util/token_list.rs index d976dcf6b..7e9b678f2 100644 --- a/src/util/token_list.rs +++ b/src/util/token_list.rs @@ -23,9 +23,9 @@ impl SolTokenList { Ok(Self { tokens }) } - pub fn get_symbols(self) -> Result> { + pub fn get_symbols(&self) -> Result> { let mut symbols = Vec::new(); - for item in self.tokens { + for item in self.tokens.iter() { let symbol = item["symbol"].as_str().unwrap(); symbols.push(symbol.to_string()); } @@ -33,7 +33,7 @@ impl SolTokenList { } pub fn search_id(&self, symbol: &str) -> Result> { - for item in self.tokens.clone() { + for item in self.tokens.iter() { if item["symbol"] == symbol.to_uppercase() { let address = item["address"].clone(); let address = address.as_str().ok_or(Error::TokenParseError)?; @@ -58,8 +58,8 @@ impl SolTokenList { // return Ok(ids); // } - pub fn search_decimal(self, symbol: &str) -> Result> { - for item in self.tokens { + pub fn search_decimal(&self, symbol: &str) -> Result> { + for item in self.tokens.iter() { if item["symbol"] == symbol.to_uppercase() { let decimals = item["decimals"].clone(); let decimals = decimals.as_u64().ok_or(Error::TokenParseError)?;