save allocations by passing a reference of token list

This commit is contained in:
ghassmo
2021-10-06 09:51:15 +03:00
parent 712480f827
commit da472dc2b7
3 changed files with 11 additions and 11 deletions

View File

@@ -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");

View File

@@ -43,7 +43,7 @@ pub fn generate_id(tkn_str: &str, network: &NetworkName) -> Result<jubjub::Fr> {
Ok(token_id)
}
pub fn assign_id(network: &str, _token: &str, _tokenlist: SolTokenList) -> Result<String> {
pub fn assign_id(network: &str, _token: &str, _tokenlist: &SolTokenList) -> Result<String> {
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<usize> {
pub fn decimals(network: &str, _token: &str, _tokenlist: &SolTokenList) -> Result<usize> {
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<String> {
pub fn symbol_to_id(token: &str, tokenlist: &SolTokenList) -> Result<String> {
let vec: Vec<char> = token.chars().collect();
let mut counter = 0;
for c in vec {

View File

@@ -23,9 +23,9 @@ impl SolTokenList {
Ok(Self { tokens })
}
pub fn get_symbols(self) -> Result<Vec<String>> {
pub fn get_symbols(&self) -> Result<Vec<String>> {
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<Option<String>> {
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<Option<usize>> {
for item in self.tokens {
pub fn search_decimal(&self, symbol: &str) -> Result<Option<usize>> {
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)?;