Bläddra i källkod

tau: Update for new serial module.

Luther Blissett 3 år sedan
förälder
incheckning
11f86e0d56

+ 1 - 1
bin/tau/tau-cli/src/primitives.rs

@@ -1,6 +1,6 @@
 use std::{fmt, str::FromStr};
 
-use darkfi::{util::Timestamp, Error, Result};
+use darkfi::{util::time::Timestamp, Error, Result};
 
 use crate::due_as_timestamp;
 

+ 1 - 1
bin/tau/tau-cli/src/util.rs

@@ -8,7 +8,7 @@ use std::{
 use chrono::{Datelike, Local, NaiveDate};
 use log::error;
 
-use darkfi::{util::Timestamp, Result};
+use darkfi::{util::time::Timestamp, Result};
 
 /// Parse due date (e.g. "1503" for 15 March) as i64 timestamp.
 pub fn due_as_timestamp(due: &str) -> Option<i64> {

+ 11 - 0
bin/tau/taud/src/error.rs

@@ -16,6 +16,8 @@ pub enum TaudError {
     SerdeJsonError(String),
     #[error("Encryption error: `{0}`")]
     EncryptionError(String),
+    #[error("IO Error: `{0}`")]
+    IoError(String),
 }
 
 pub type TaudResult<T> = std::result::Result<T, TaudError>;
@@ -32,6 +34,12 @@ impl From<crypto_box::aead::Error> for TaudError {
     }
 }
 
+impl From<std::io::Error> for TaudError {
+    fn from(err: std::io::Error) -> TaudError {
+        TaudError::IoError(err.to_string())
+    }
+}
+
 pub fn to_json_result(res: TaudResult<Value>, id: Value) -> JsonResult {
     match res {
         Ok(v) => JsonResponse::new(v, id).into(),
@@ -51,6 +59,9 @@ pub fn to_json_result(res: TaudResult<Value>, id: Value) -> JsonResult {
             TaudError::Darkfi(e) => {
                 JsonError::new(ErrorCode::InternalError, Some(e.to_string()), id).into()
             }
+            TaudError::IoError(e) => {
+                JsonError::new(ErrorCode::InternalError, Some(e.to_string()), id).into()
+            }
         },
     }
 }

+ 2 - 2
bin/tau/taud/src/jsonrpc.rs

@@ -1,6 +1,6 @@
-use async_std::sync::Mutex;
 use std::{fs::create_dir_all, path::PathBuf};
 
+use async_std::sync::Mutex;
 use async_trait::async_trait;
 use crypto_box::SalsaBox;
 use fxhash::FxHashMap;
@@ -14,7 +14,7 @@ use darkfi::{
         jsonrpc::{ErrorCode, JsonError, JsonRequest, JsonResult},
         server::RequestHandler,
     },
-    util::{expand_path, Timestamp},
+    util::{path::expand_path, time::Timestamp},
     Error,
 };
 

+ 3 - 4
bin/tau/taud/src/main.rs

@@ -1,4 +1,3 @@
-use async_std::sync::{Arc, Mutex};
 use std::{
     env,
     fs::{create_dir_all, remove_dir_all},
@@ -7,6 +6,7 @@ use std::{
 };
 
 use async_executor::Executor;
+use async_std::sync::{Arc, Mutex};
 use crypto_box::{
     aead::{Aead, AeadCore},
     SalsaBox, SecretKey,
@@ -21,11 +21,10 @@ use darkfi::{
     async_daemonize, net,
     raft::{NetMsg, ProtocolRaft, Raft, RaftSettings},
     rpc::server::listen_and_serve,
+    serial::{deserialize, serialize, SerialDecodable, SerialEncodable},
     util::{
         cli::{get_log_config, get_log_level, spawn_config},
-        expand_path,
-        path::get_config_path,
-        serial::{deserialize, serialize, SerialDecodable, SerialEncodable},
+        path::{expand_path, get_config_path},
     },
     Error, Result,
 };

+ 1 - 1
bin/tau/taud/src/month_tasks.rs

@@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
 
 use darkfi::util::{
     file::{load_json_file, save_json_file},
-    Timestamp,
+    time::Timestamp,
 };
 
 use crate::{

+ 13 - 90
bin/tau/taud/src/task_info.rs

@@ -1,16 +1,15 @@
-use std::{
-    io,
-    path::{Path, PathBuf},
-};
+use std::path::{Path, PathBuf};
 
 use log::debug;
 use serde::{Deserialize, Serialize};
 
-use darkfi::util::{
-    file::{load_json_file, save_json_file},
-    gen_id,
-    serial::{Decodable, Encodable, SerialDecodable, SerialEncodable, VarInt},
-    Timestamp,
+use darkfi::{
+    serial::{SerialDecodable, SerialEncodable},
+    util::{
+        file::{load_json_file, save_json_file},
+        gen_id,
+        time::Timestamp,
+    },
 };
 
 use crate::{
@@ -50,15 +49,15 @@ impl Comment {
     }
 }
 
-#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
+#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, SerialEncodable, SerialDecodable)]
 pub struct TaskEvents(Vec<TaskEvent>);
-#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
+#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, SerialEncodable, SerialDecodable)]
 pub struct TaskComments(Vec<Comment>);
-#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
+#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, SerialEncodable, SerialDecodable)]
 pub struct TaskProjects(Vec<String>);
-#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
+#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, SerialEncodable, SerialDecodable)]
 pub struct TaskAssigns(Vec<String>);
-#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
+#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, SerialEncodable, SerialDecodable)]
 pub struct TaskTags(Vec<String>);
 
 #[derive(Clone, Debug, Serialize, Deserialize, SerialEncodable, SerialDecodable, PartialEq)]
@@ -263,79 +262,3 @@ impl TaskInfo {
         self.set_event("state", &state);
     }
 }
-
-impl Encodable for TaskEvents {
-    fn encode<S: io::Write>(&self, s: S) -> darkfi::Result<usize> {
-        encode_vec(&self.0, s)
-    }
-}
-
-impl Decodable for TaskEvents {
-    fn decode<D: io::Read>(d: D) -> darkfi::Result<Self> {
-        Ok(Self(decode_vec(d)?))
-    }
-}
-impl Encodable for TaskComments {
-    fn encode<S: io::Write>(&self, s: S) -> darkfi::Result<usize> {
-        encode_vec(&self.0, s)
-    }
-}
-
-impl Decodable for TaskComments {
-    fn decode<D: io::Read>(d: D) -> darkfi::Result<Self> {
-        Ok(Self(decode_vec(d)?))
-    }
-}
-impl Encodable for TaskProjects {
-    fn encode<S: io::Write>(&self, s: S) -> darkfi::Result<usize> {
-        encode_vec(&self.0, s)
-    }
-}
-
-impl Decodable for TaskProjects {
-    fn decode<D: io::Read>(d: D) -> darkfi::Result<Self> {
-        Ok(Self(decode_vec(d)?))
-    }
-}
-
-impl Encodable for TaskAssigns {
-    fn encode<S: io::Write>(&self, s: S) -> darkfi::Result<usize> {
-        encode_vec(&self.0, s)
-    }
-}
-
-impl Decodable for TaskAssigns {
-    fn decode<D: io::Read>(d: D) -> darkfi::Result<Self> {
-        Ok(Self(decode_vec(d)?))
-    }
-}
-
-impl Encodable for TaskTags {
-    fn encode<S: io::Write>(&self, s: S) -> darkfi::Result<usize> {
-        encode_vec(&self.0, s)
-    }
-}
-
-impl Decodable for TaskTags {
-    fn decode<D: io::Read>(d: D) -> darkfi::Result<Self> {
-        Ok(Self(decode_vec(d)?))
-    }
-}
-
-fn encode_vec<T: Encodable, S: io::Write>(vec: &[T], mut s: S) -> darkfi::Result<usize> {
-    let mut len = 0;
-    len += VarInt(vec.len() as u64).encode(&mut s)?;
-    for c in vec.iter() {
-        len += c.encode(&mut s)?;
-    }
-    Ok(len)
-}
-
-fn decode_vec<T: Decodable, D: io::Read>(mut d: D) -> darkfi::Result<Vec<T>> {
-    let len = VarInt::decode(&mut d)?.0;
-    let mut ret = Vec::with_capacity(len as usize);
-    for _ in 0..len {
-        ret.push(Decodable::decode(&mut d)?);
-    }
-    Ok(ret)
-}