src/util: made TokenList struct called in darkfid::main()

This commit is contained in:
lunar-mining
2021-09-29 08:56:56 +02:00
parent 0b6fe5811b
commit 873d259bd2
2 changed files with 37 additions and 2 deletions

View File

@@ -17,7 +17,9 @@ use drk::{
rpcserver::{listen_and_serve, RequestHandler, RpcServerConfig},
},
serial::{deserialize, serialize},
util::{expand_path, join_config_path, parse_network, parse_wrapped_token, search_id},
util::{
expand_path, join_config_path, parse_network, parse_wrapped_token, search_id, TokenList,
},
wallet::WalletDb,
Result,
};
@@ -349,6 +351,8 @@ impl Darkfid {
#[async_std::main]
async fn main() -> Result<()> {
let _tokens = TokenList::new()?;
let args = clap_app!(darkfid =>
(@arg CONFIG: -c --config +takes_value "Sets a custom config file")
(@arg verbose: -v --verbose "Increase verbosity")

View File

@@ -6,9 +6,22 @@ use crate::{
use log::debug;
use sha2::{Digest, Sha256};
use serde_json::Value;
use std::path::{Path, PathBuf};
use std::str::FromStr;
pub struct TokenList {
tokenlist: Value,
}
impl TokenList {
pub fn new() -> Result<Self> {
let file_contents = std::fs::read_to_string("token/solanatokenlist.json")?;
let tokenlist: serde_json::Value = serde_json::from_str(&file_contents)?;
Ok(Self { tokenlist })
}
}
pub fn expand_path(path: &str) -> Result<PathBuf> {
let ret: PathBuf;
@@ -39,7 +52,6 @@ pub fn join_config_path(file: &Path) -> Result<PathBuf> {
Ok(path)
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum NetworkName {
Solana,
@@ -205,6 +217,25 @@ pub fn search_id(symbol: &str) -> Result<String> {
unreachable!();
}
// TODO: implement this
//pub fn search_decimals(symbol: &str) -> Result<String> {
// // TODO: FIXME
// let file_contents = std::fs::read_to_string("token/solanatokenlist.json")?;
// let tokenlist: serde_json::Value = serde_json::from_str(&file_contents)?;
// let tokens = tokenlist["tokens"]
// .as_array()
// .ok_or_else(|| Error::TokenParseError)?;
// for item in tokens {
// if item["symbol"] == symbol.to_uppercase() {
// let address = item["address"].clone();
// let address = address.as_str().ok_or_else(|| Error::TokenParseError)?;
// return Ok(address.to_string());
// }
// }
// unreachable!();
//}
#[cfg(test)]
mod tests {
use crate::serial::{deserialize, serialize};