|
|
@@ -22,7 +22,7 @@ use drk::{
|
|
|
serial::serialize,
|
|
|
util::join_config_path,
|
|
|
wallet::WalletDb,
|
|
|
- Error,
|
|
|
+ Error, Result,
|
|
|
};
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
@@ -30,21 +30,25 @@ struct Darkfid {
|
|
|
verbose: bool,
|
|
|
config: DarkfidConfig,
|
|
|
wallet: Arc<WalletDb>,
|
|
|
+ tokenlist: Value,
|
|
|
// clientdb:
|
|
|
// mint_params:
|
|
|
// spend_params:
|
|
|
}
|
|
|
|
|
|
impl Darkfid {
|
|
|
- fn new(verbose: bool, config_path: PathBuf) -> Result<Self, Error> {
|
|
|
+ fn new(verbose: bool, config_path: PathBuf) -> Result<Self> {
|
|
|
let config: DarkfidConfig = Config::<DarkfidConfig>::load(config_path)?;
|
|
|
let wallet_path = join_config_path(&PathBuf::from("walletdb.db"))?;
|
|
|
let wallet = WalletDb::new(&PathBuf::from(wallet_path.clone()), config.password.clone())?;
|
|
|
+ let file_contents = fs::read_to_string("token/solanatokenlist.json")?;
|
|
|
+ let tokenlist: Value = serde_json::from_str(&file_contents)?;
|
|
|
|
|
|
Ok(Self {
|
|
|
verbose,
|
|
|
config,
|
|
|
wallet,
|
|
|
+ tokenlist,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -137,11 +141,7 @@ impl Darkfid {
|
|
|
// TODO: proper error handling here
|
|
|
fn search_id(self, symbol: &str) -> Value {
|
|
|
debug!(target: "DARKFID", "SEARCHING FOR {}", symbol);
|
|
|
- let file_contents =
|
|
|
- fs::read_to_string("token/solanatokenlist.json").expect("Can't find tokenlist file");
|
|
|
- let root: Value =
|
|
|
- serde_json::from_str(&file_contents).expect("Can't parse file into valid json");
|
|
|
- let tokens = root["tokens"]
|
|
|
+ let tokens = self.tokenlist["tokens"]
|
|
|
.as_array()
|
|
|
.expect("Can't find 'tokens' in file");
|
|
|
for item in tokens {
|
|
|
@@ -289,7 +289,7 @@ impl Darkfid {
|
|
|
}
|
|
|
|
|
|
#[tokio::main]
|
|
|
-async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
+async fn main() -> Result<()> {
|
|
|
let args = clap_app!(darkfid =>
|
|
|
(@arg CONFIG: -c --config +takes_value "Sets a custom config file")
|
|
|
(@arg verbose: -v --verbose "Increase verbosity")
|