diff --git a/src/bin/darkfid.rs b/src/bin/darkfid.rs index 6b8455d94..3ca0872af 100644 --- a/src/bin/darkfid.rs +++ b/src/bin/darkfid.rs @@ -29,7 +29,7 @@ use drk::{ state::ProgramState, util::{ assign_id, decode_base10, encode_base10, expand_path, join_config_path, DrkTokenList, - NetworkName, SolTokenList, + NetworkName, TokenList, }, wallet::WalletDb, Error, Result, @@ -70,7 +70,7 @@ impl RequestHandler for Darkfid { struct Darkfid { client: Arc>, state: Arc>, - sol_tokenlist: SolTokenList, + sol_tokenlist: TokenList, drk_tokenlist: DrkTokenList, cashiers: Vec, } @@ -81,7 +81,7 @@ impl Darkfid { state: Arc>, cashiers: Vec, ) -> Result { - let sol_tokenlist = SolTokenList::new()?; + let sol_tokenlist = TokenList::new(include_bytes!("../../token/solana_token_list.json"))?; let drk_tokenlist = DrkTokenList::new(sol_tokenlist.clone())?; Ok(Self { diff --git a/src/util/mod.rs b/src/util/mod.rs index cb5d78367..345bfa2d5 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, decode_base10, encode_base10, generate_id}; pub use path::{expand_path, join_config_path}; -pub use token_list::{DrkTokenList, SolTokenList}; +pub use token_list::{DrkTokenList, TokenList}; diff --git a/src/util/parse.rs b/src/util/parse.rs index 334818c15..a4b6c3fa3 100644 --- a/src/util/parse.rs +++ b/src/util/parse.rs @@ -6,7 +6,7 @@ use sha2::{Digest, Sha256}; use crate::{ serial::{deserialize, serialize}, - util::{NetworkName, SolTokenList}, + util::{NetworkName, TokenList}, 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: &SolTokenList) -> Result { +pub fn assign_id(network: &str, token: &str, _tokenlist: &TokenList) -> Result { let token = token.to_lowercase(); let _token = token.as_str(); match NetworkName::from_str(network)? { @@ -66,7 +66,7 @@ pub fn assign_id(network: &str, token: &str, _tokenlist: &SolTokenList) -> Resul } } -pub fn symbol_to_id(token: &str, tokenlist: &SolTokenList) -> Result { +pub fn symbol_to_id(token: &str, tokenlist: &TokenList) -> 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 efc4f2fa8..5f09b599c 100644 --- a/src/util/token_list.rs +++ b/src/util/token_list.rs @@ -8,19 +8,17 @@ use crate::{ }; #[derive(Debug, Clone)] -pub struct SolTokenList { +pub struct TokenList { tokens: Vec, } -impl SolTokenList { - pub fn new() -> Result { - let file_contents = include_bytes!("../../token/solanatokenlist.json"); - let sol_tokenlist: Value = serde_json::from_slice(file_contents)?; - let tokens = sol_tokenlist["tokens"] +impl TokenList { + pub fn new(data: &[u8]) -> Result { + let tokenlist: Value = serde_json::from_slice(data)?; + let tokens = tokenlist["tokens"] .as_array() .ok_or(Error::TokenParseError)? .clone(); - Ok(Self { tokens }) } @@ -28,12 +26,7 @@ impl SolTokenList { let mut symbols: Vec = Vec::new(); for item in self.tokens.iter() { let symbol = item["symbol"].as_str().unwrap(); - // FIXME: Change Sollet BTC to SBTC? - if symbol == "BTC" { - symbols.push("SBTC".to_string()); - } else { - symbols.push(symbol.to_string()); - } + symbols.push(symbol.to_string()); } Ok(symbols) } @@ -68,7 +61,7 @@ pub struct DrkTokenList { } impl DrkTokenList { - pub fn new(sol_list: SolTokenList) -> Result { + pub fn new(sol_list: TokenList) -> Result { let sol_symbols = sol_list.get_symbols()?; let mut tokens: HashMap = sol_symbols @@ -84,7 +77,7 @@ impl DrkTokenList { Ok(Self { tokens }) } - fn generate_hash_pair(sol_list: &SolTokenList, symbol: &str) -> Result<(String, jubjub::Fr)> { + fn generate_hash_pair(sol_list: &TokenList, symbol: &str) -> Result<(String, jubjub::Fr)> { if let Some(token_id) = &sol_list.search_id(symbol)? { Ok(( symbol.to_string(), @@ -110,10 +103,10 @@ impl DrkTokenList { #[allow(unused_imports)] mod tests { use super::*; - use crate::util::{DrkTokenList, SolTokenList}; + use crate::util::{DrkTokenList, TokenList}; use crate::Result; - fn _get_tokens() -> Result { + fn _get_tokens() -> Result { let file_contents = include_bytes!("../../token/solanatokenlisttest.json"); let sol_tokenlist: Value = serde_json::from_slice(file_contents)?; @@ -122,7 +115,7 @@ mod tests { .ok_or(Error::TokenParseError)? .clone(); - let sol_tokenlist = SolTokenList { tokens }; + let sol_tokenlist = TokenList { tokens }; Ok(sol_tokenlist) }