From 02d3f56bfa46cc754d45faed8ae9bcf60bb1d093 Mon Sep 17 00:00:00 2001 From: lunar-mining Date: Sat, 2 Oct 2021 21:46:25 +0200 Subject: [PATCH] renamed TokenList to SolTokenList --- src/bin/darkfid.rs | 15 ++++++++------- src/util/mod.rs | 2 +- src/util/parse.rs | 8 ++++---- src/util/token_list.rs | 10 +++++----- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/bin/darkfid.rs b/src/bin/darkfid.rs index e9a38ca4a..154ee93cd 100644 --- a/src/bin/darkfid.rs +++ b/src/bin/darkfid.rs @@ -19,7 +19,7 @@ use drk::{ serial::{deserialize, serialize}, util::{ assign_id, decimals, decode_base10, expand_path, generate_id, join_config_path, - NetworkName, TokenList, + DrkTokenList, NetworkName, SolTokenList, }, wallet::WalletDb, Result, @@ -28,7 +28,7 @@ use drk::{ struct Darkfid { config: DarkfidConfig, client: Arc>, - tokenlist: TokenList, + tokenlist: SolTokenList, } #[async_trait] @@ -77,7 +77,8 @@ impl Darkfid { let client = Arc::new(Mutex::new(client)); - let tokenlist = TokenList::new()?; + let tokenlist = SolTokenList::new()?; + let drk_tokenlist = DrkTokenList::new(tokenlist.clone())?; Ok(Self { config, @@ -368,10 +369,6 @@ impl Darkfid { // --> {"method": "transfer", [dToken, address, amount]} // <-- {"result": "txID"} async fn transfer(&self, id: Value, params: Value) -> JsonResult { - //let token_vec = self.wallet.get_token_ids(); - - //for (network_name, token_id) in self.tokenlist.drk_tokenlist.iter() {} - let args = params.as_array(); if args.is_none() { @@ -394,6 +391,10 @@ impl Darkfid { let _token = token.as_str().unwrap(); + //let token_vec = self.wallet.get_token_ids(); + + //for (network_name, token_id) in self.tokenlist.drk_tokenlist.iter() {} + if address.as_str().is_none() { return JsonResult::Err(jsonerr(InvalidAddressParam, None, id)); } diff --git a/src/util/mod.rs b/src/util/mod.rs index 0ceca67f0..71485b48d 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -6,4 +6,4 @@ pub mod token_list; pub use net_name::NetworkName; pub use parse::{assign_id, decimals, decode_base10, encode_base10, generate_id}; pub use path::{expand_path, join_config_path}; -pub use token_list::{DrkTokenList, TokenList}; +pub use token_list::{DrkTokenList, SolTokenList}; diff --git a/src/util/parse.rs b/src/util/parse.rs index 718f5c4fe..8d39b81e9 100644 --- a/src/util/parse.rs +++ b/src/util/parse.rs @@ -5,7 +5,7 @@ use std::str::FromStr; use crate::{ serial::{deserialize, serialize}, - util::{NetworkName, TokenList}, + util::{NetworkName, SolTokenList}, Error, Result, }; @@ -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: TokenList) -> 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: TokenList) -> Result Result { +pub fn decimals(network: &str, _token: &str, _tokenlist: SolTokenList) -> Result { match NetworkName::from_str(network)? { #[cfg(feature = "sol")] NetworkName::Solana => match _token { @@ -92,7 +92,7 @@ pub fn decimals(network: &str, _token: &str, _tokenlist: TokenList) -> Result 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 44620d612..63936cd7d 100644 --- a/src/util/token_list.rs +++ b/src/util/token_list.rs @@ -6,11 +6,11 @@ use serde_json::Value; use std::collections::HashMap; #[derive(Debug, Clone)] -pub struct TokenList { +pub struct SolTokenList { sol_tokenlist: Value, } -impl TokenList { +impl SolTokenList { pub fn new() -> Result { // TODO: FIXME let file_contents = std::fs::read_to_string("token/solanatokenlist.json")?; @@ -75,7 +75,7 @@ pub struct DrkTokenList { } impl DrkTokenList { - pub fn new(list: TokenList) -> Result { + pub fn new(list: SolTokenList) -> Result { let mut drk_tokenlist = HashMap::new(); let symbols = list.clone().get_symbols()?; for symbol in symbols { @@ -91,12 +91,12 @@ impl DrkTokenList { mod tests { use super::*; - use crate::util::TokenList; + use crate::util::SolTokenList; use crate::Result; #[test] pub fn test_get_symbols() -> Result<()> { - let token = TokenList::new()?; + let token = SolTokenList::new()?; let symbols = token.get_symbols()?; for symbol in symbols { println!("{}", symbol)