diff --git a/src/bin/cashierd.rs b/src/bin/cashierd.rs index 7ab5600a4..bd05e4159 100644 --- a/src/bin/cashierd.rs +++ b/src/bin/cashierd.rs @@ -1,7 +1,7 @@ use async_std::sync::Arc; use std::net::SocketAddr; -use std::{path::Path, path::PathBuf}; +use std::path::PathBuf; use drk::cli::{CashierdCli, CashierdConfig, Config}; use drk::service::CashierService; @@ -63,11 +63,7 @@ fn main() -> Result<()> { let path = join_config_path(&PathBuf::from("cashierd.toml")).unwrap(); - let config: CashierdConfig = if Path::new(&path).exists() { - Config::::load(path)? - } else { - Config::::load_default(path)? - }; + let config: CashierdConfig = Config::::load(path)?; let config = Arc::new(config); diff --git a/src/bin/darkfid.rs b/src/bin/darkfid.rs index 996d7a955..128aff165 100644 --- a/src/bin/darkfid.rs +++ b/src/bin/darkfid.rs @@ -11,7 +11,6 @@ use easy_parallel::Parallel; use async_std::sync::Arc; use std::net::SocketAddr; -use std::path::Path; use std::path::PathBuf; async fn start(executor: Arc>, config: Arc) -> Result<()> { @@ -70,11 +69,7 @@ fn main() -> Result<()> { } } - let config: DarkfidConfig = if Path::new(&config_path).exists() { - Config::::load(config_path)? - } else { - Config::::load_default(config_path)? - }; + let config: DarkfidConfig = Config::::load(config_path)?; let config = Arc::new(config); diff --git a/src/bin/drk.rs b/src/bin/drk.rs index caacc0df7..61cbd65c0 100644 --- a/src/bin/drk.rs +++ b/src/bin/drk.rs @@ -1,4 +1,4 @@ -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use serde_json::json; @@ -153,11 +153,17 @@ fn main() -> Result<()> { } } - let config: DrkConfig = if Path::new(&config_path).exists() { - Config::::load(config_path)? - } else { - Config::::load_default(config_path)? - }; + let config: DrkConfig = Config::::load(config_path)?; + //let config: DrkConfig = if Path::new(&config_path).exists() { + // Config::::load(config_path)? + //}; + + //if Path::new(&config_path).exists() { + // let config: DrkConfig = Config::::load(config_path)? + //} + //else { + // Error::NoConfigError + //}; { use simplelog::*; diff --git a/src/bin/gatewayd.rs b/src/bin/gatewayd.rs index feb29d2d2..77a5b59ca 100644 --- a/src/bin/gatewayd.rs +++ b/src/bin/gatewayd.rs @@ -6,7 +6,7 @@ use drk::cli::{Config, GatewaydCli, GatewaydConfig}; use drk::service::GatewayService; use drk::util::join_config_path; use drk::Result; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; extern crate clap; use async_executor::Executor; @@ -33,11 +33,7 @@ fn main() -> Result<()> { let path = join_config_path(&PathBuf::from("gatewayd.toml")).unwrap(); - let config: GatewaydConfig = if Path::new(&path).exists() { - Config::::load(path)? - } else { - Config::::load_default(path)? - }; + let config: GatewaydConfig = Config::::load(path)?; let config_ptr = Arc::new(&config); diff --git a/src/cli/cli_config.rs b/src/cli/cli_config.rs index 5d3af4d24..e5027b326 100644 --- a/src/cli/cli_config.rs +++ b/src/cli/cli_config.rs @@ -1,14 +1,11 @@ -use crate::util::join_config_path; -use crate::Result; +use crate::{Result, Error}; use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; use std::marker::PhantomData; use std::{ - env, fs, - fs::{create_dir_all, File}, - io::Write, - path::PathBuf, + fs, + path::{Path, PathBuf}, str, }; @@ -16,27 +13,17 @@ pub struct Config { config: PhantomData, } -impl Config { +impl Config { pub fn load(path: PathBuf) -> Result { - let toml = fs::read(&path)?; - let str_buff = str::from_utf8(&toml)?; - let config: T = toml::from_str(str_buff.clone())?; - Ok(config) - } - - pub fn load_default(path: PathBuf) -> Result { - let toml = T::default(); - let config_file = toml::to_string(&toml)?; - - if let Some(outdir) = path.parent() { - create_dir_all(outdir)?; + if Path::new(&path).exists() { + let toml = fs::read(&path)?; + let str_buff = str::from_utf8(&toml)?; + let config: T = toml::from_str(str_buff.clone())?; + Ok(config) + } + else { + Err(Error::ConfigNotFound) } - - let mut file = File::create(path.clone())?; - file.write_all(&config_file.into_bytes())?; - - let config = Self::load(path)?; - Ok(config) } } @@ -49,19 +36,6 @@ pub struct DrkConfig { pub log_path: String, } -impl Default for DrkConfig { - fn default() -> Self { - let rpc_url = String::from("http://127.0.0.1:8000"); - - let mut lp = PathBuf::new(); - lp.push(env::temp_dir()); - lp.push("drk_cli.log"); - let log_path = String::from(lp.to_str().unwrap()); - - Self { rpc_url, log_path } - } -} - #[derive(Serialize, Deserialize, Debug)] pub struct DarkfidConfig { #[serde(default)] @@ -97,43 +71,6 @@ pub struct DarkfidConfig { pub password: String, } -impl Default for DarkfidConfig { - fn default() -> Self { - let connect_url = String::from("127.0.0.1:3333"); - let subscriber_url = String::from("127.0.0.1:4444"); - let cashier_url = String::from("127.0.0.1:7777"); - let rpc_url = String::from("127.0.0.1:8000"); - - let database_path = String::from("database_client.db"); - let database_path = join_config_path(&PathBuf::from(database_path)) - .expect("join database_path to config path"); - let database_path = String::from(database_path.to_str().expect("convert Path to String")); - - let walletdb_path = String::from("walletdb.db"); - let walletdb_path = join_config_path(&PathBuf::from(walletdb_path)) - .expect("join walletdb_path to config path"); - let walletdb_path = String::from(walletdb_path.to_str().expect("convert Path to String")); - - let mut lp = PathBuf::new(); - lp.push(env::temp_dir()); - lp.push("darkfid_service_daemon.log"); - let log_path = String::from(lp.to_str().unwrap()); - - let password = String::new(); - - Self { - connect_url, - subscriber_url, - cashier_url, - rpc_url, - database_path, - walletdb_path, - log_path, - password, - } - } -} - #[derive(Serialize, Deserialize, Debug)] pub struct GatewaydConfig { #[serde(default)] @@ -153,26 +90,6 @@ pub struct GatewaydConfig { pub log_path: String, } -impl Default for GatewaydConfig { - fn default() -> Self { - let accept_url = String::from("127.0.0.1:3333"); - let publisher_url = String::from("127.0.0.1:4444"); - let database_path = String::from("gatewayd.db"); - - let mut lp = PathBuf::new(); - lp.push(env::temp_dir()); - lp.push("gatewayd.log"); - let log_path = String::from(lp.to_str().unwrap()); - - Self { - accept_url, - publisher_url, - database_path, - log_path, - } - } -} - #[derive(Serialize, Deserialize, Debug)] pub struct CashierdConfig { #[serde(default)] @@ -215,47 +132,3 @@ pub struct CashierdConfig { #[serde(rename = "client_password")] pub client_password: String, } - -impl Default for CashierdConfig { - fn default() -> Self { - let accept_url = String::from("127.0.0.1:7777"); - let rpc_url = String::from("http://127.0.0.1:8000"); - let gateway_url = String::from("127.0.0.1:3333"); - let client_database_path = String::from("cashier_client_database.db"); - let btc_endpoint = String::from("tcp://electrum.blockstream.info:50001"); - let mut lp = PathBuf::new(); - lp.push(env::temp_dir()); - lp.push("cashierd.log"); - let log_path = String::from(lp.to_str().unwrap()); - - let cashierdb_path = String::from("cashier.db"); - let cashierdb_path = join_config_path(&PathBuf::from(cashierdb_path)) - .expect("join walletdb_path to config path"); - let cashierdb_path = String::from(cashierdb_path.to_str().expect("convert Path to String")); - - let client_walletdb_path = String::from("cashier_client_walletdb.db"); - let client_walletdb_path = join_config_path(&PathBuf::from(client_walletdb_path)) - .expect("join walletdb_path to config path"); - let client_walletdb_path = String::from( - client_walletdb_path - .to_str() - .expect("convert Path to String"), - ); - - let password = String::new(); - let client_password = String::new(); - - Self { - accept_url, - rpc_url, - client_database_path, - btc_endpoint, - gateway_url, - log_path, - cashierdb_path, - client_walletdb_path, - password, - client_password, - } - } -} diff --git a/src/client/client.rs b/src/client/client.rs index 13a07ef76..569033541 100644 --- a/src/client/client.rs +++ b/src/client/client.rs @@ -21,13 +21,13 @@ use super::ClientFailed; use async_executor::Executor; use bellman::groth16; use bls12_381::Bls12; -use log::*; use jsonrpc_core::IoHandler; use async_std::sync::{Arc, Mutex}; use std::net::SocketAddr; use std::path::PathBuf; +use log::*; pub struct Client { pub state: State, diff --git a/src/crypto/mint_proof.rs b/src/crypto/mint_proof.rs index 2b4a8114f..4526e7423 100644 --- a/src/crypto/mint_proof.rs +++ b/src/crypto/mint_proof.rs @@ -118,7 +118,7 @@ impl Decodable for MintRevealedValues { } pub fn setup_mint_prover() -> groth16::Parameters { - println!("Making random params..."); + println!("Mint: Making random params..."); let start = Instant::now(); let params = { let c = MintContract { diff --git a/src/crypto/spend_proof.rs b/src/crypto/spend_proof.rs index 421dc2e47..73ae9859d 100644 --- a/src/crypto/spend_proof.rs +++ b/src/crypto/spend_proof.rs @@ -198,7 +198,7 @@ impl Decodable for SpendRevealedValues { } pub fn setup_spend_prover() -> groth16::Parameters { - println!("Making random params..."); + println!("Spend: Making random params..."); let start = Instant::now(); let params = { let c = SpendContract { diff --git a/src/error.rs b/src/error.rs index 96de7e9c3..1a761d56d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -56,6 +56,7 @@ pub enum Error { Base58DecodeError(String), BadBTCAddress(String), BtcClientError, + ConfigNotFound, } impl std::error::Error for Error {} @@ -108,6 +109,7 @@ impl fmt::Display for Error { Error::CashierNoReply => f.write_str("Cashier did not reply with BTC address"), Error::BadBTCAddress(ref err) => write!(f, "could not parse BTC address: {}", err), Error::BtcClientError => f.write_str("Unable to create Electrum Client"), + Error::ConfigNotFound => f.write_str("No config file detected. Please create a config file"), } } }