Parcourir la source

Miscellaneous cleanups.

parazyd il y a 4 ans
Parent
commit
9abf62c980
4 fichiers modifiés avec 20 ajouts et 42 suppressions
  1. 1 0
      Cargo.lock
  2. 6 3
      bin/taud/src/main.rs
  3. 4 30
      example/net.rs
  4. 9 9
      src/lib.rs

+ 1 - 0
Cargo.lock

@@ -1557,6 +1557,7 @@ dependencies = [
  "blake3",
  "bs58",
  "bytes",
+ "chrono",
  "clap 3.1.6",
  "crypto_api_chachapoly",
  "darkfi-derive",

+ 6 - 3
bin/taud/src/main.rs

@@ -99,14 +99,15 @@ mod tests {
         path::PathBuf,
     };
 
+    use super::*;
     use crate::{month_tasks::MonthTasks, task_info::TaskInfo, util::get_current_time};
 
-    use super::*;
+    const TEST_DATA_PATH: &str = "/tmp/test_tau_data";
 
     fn get_path() -> Result<PathBuf> {
-        remove_dir_all("/tmp/test_tau_data").ok();
+        remove_dir_all(TEST_DATA_PATH).ok();
 
-        let path = PathBuf::from("/tmp/test_tau_data");
+        let path = PathBuf::from(TEST_DATA_PATH);
 
         // mkdir dataset_path if not exists
         create_dir_all(path.join("month"))?;
@@ -175,6 +176,8 @@ mod tests {
 
         assert!(mt_load.get_task_tks().contains(&task.get_ref_id()));
 
+        remove_dir_all(TEST_DATA_PATH).ok();
+
         Ok(())
     }
 }

+ 4 - 30
example/net.rs

@@ -2,8 +2,9 @@ use std::{net::SocketAddr, str::FromStr, sync::Arc};
 
 use async_executor::Executor;
 use clap::Parser;
+use simplelog::*;
 
-use darkfi::{net, Result};
+use darkfi::{net, util::cli::log_config, Result};
 
 async fn start(executor: Arc<Executor<'_>>, options: ProgramOptions) -> Result<()> {
     let p2p = net::P2p::new(options.network_settings).await;
@@ -93,38 +94,11 @@ impl ProgramOptions {
 }
 
 fn main() -> Result<()> {
-    use simplelog::*;
-
     let options = ProgramOptions::load()?;
 
-    let logger_config = ConfigBuilder::new().set_time_format_str("%T%.6f").build();
-
-    CombinedLogger::init(vec![
-        TermLogger::new(LevelFilter::Debug, logger_config, TerminalMode::Mixed, ColorChoice::Auto),
-        WriteLogger::new(
-            LevelFilter::Debug,
-            Config::default(),
-            std::fs::File::create(options.log_path.as_path()).unwrap(),
-        ),
-    ])
-    .unwrap();
+    let (lvl, conf) = log_config(1)?;
+    TermLogger::init(lvl, conf, TerminalMode::Mixed, ColorChoice::Auto)?;
 
     let ex = Arc::new(Executor::new());
     smol::block_on(ex.run(start(ex.clone(), options)))
-
-    /*
-       let (_, result) = Parallel::new()
-    // Run four executor threads.
-    .each(0..3, |_| smol::future::block_on(ex.run(shutdown.recv())))
-    // Run the main future on the current thread.
-    .finish(|| {
-    smol::future::block_on(async move {
-    start(ex2, options).await?;
-    drop(signal);
-    Ok::<(), drk::Error>(())
-    })
-    });
-
-    result
-    */
 }

+ 9 - 9
src/lib.rs

@@ -1,6 +1,15 @@
 pub mod error;
 pub use error::{Error, Result};
 
+#[cfg(feature = "blockchain")]
+pub mod blockchain;
+
+#[cfg(feature = "blockchain")]
+pub mod consensus;
+
+#[cfg(feature = "wasm-runtime")]
+pub mod runtime;
+
 #[cfg(feature = "crypto")]
 pub mod crypto;
 
@@ -16,23 +25,14 @@ pub mod tx;
 #[cfg(feature = "net")]
 pub mod net;
 
-#[cfg(feature = "blockchain")]
-pub mod blockchain;
-
 #[cfg(feature = "system")]
 pub mod system;
 
 #[cfg(feature = "util")]
 pub mod util;
 
-#[cfg(feature = "wasm-runtime")]
-pub mod runtime;
-
 #[cfg(feature = "rpc")]
 pub mod rpc;
 
 #[cfg(feature = "zkas")]
 pub mod zkas;
-
-#[cfg(feature = "blockchain")]
-pub mod consensus;