diff --git a/Cargo.toml b/Cargo.toml index 1ac9f59..e7a9eb9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] +anyhow = "1.0.90" base64 = "0.22.1" serde = { version = "1.0.210", features = ["derive"] } serde_json = "1.0" diff --git a/src/lib.rs b/src/lib.rs index ee4ebc7..77cc209 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,2 +1,2 @@ -mod tasks; -mod utils; +pub mod tasks; +pub mod utils; diff --git a/src/main.rs b/src/main.rs index e7a11a9..514ba13 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,19 @@ -fn main() { - println!("Hello, world!"); +use std::{ + env::{self, args}, + fs, +}; + +use anyhow::Result; + +fn main() -> Result<()> { + let args: Vec = env::args().collect(); + let path_to_workload = &args[1]; + + let json = fs::read_to_string(path_to_workload).unwrap(); + let workload = kauma::utils::parse::parse_json(json)?; + + let response = kauma::tasks::task_distrubute(&workload); + println!("{}", serde_json::to_string(&response)?); + + Ok(()) } diff --git a/src/tasks/mod.rs b/src/tasks/mod.rs index d925b53..2c05297 100644 --- a/src/tasks/mod.rs +++ b/src/tasks/mod.rs @@ -23,16 +23,7 @@ pub fn task_deploy(testcase: &Testcase) -> Result { match testcase.action.as_str() { "poly2block" => { - let coefficients: Vec = args["coefficients"] - .as_array() - .unwrap() - .into_iter() - .map(|x| x.as_u64().unwrap() as u8) - .collect(); - //eprintln!("{:?}", &args["coefficients"]); - //eprintln!("{:?}", testcase); - //eprintln!("{:?}", coefficients); - let result = poly2block(coefficients); + let result = poly2block(args); let json = json!({"block" : result}); Ok(json) } @@ -43,7 +34,6 @@ pub fn task_deploy(testcase: &Testcase) -> Result { } } -// TODO: Is this obsolete? Might delete later. pub fn task_distrubute(testcases: &Testcases) -> Responses { let mut responses: HashMap = HashMap::new(); diff --git a/src/tasks/tasks01/poly2block.rs b/src/tasks/tasks01/poly2block.rs index e1d2ac8..5d64250 100644 --- a/src/tasks/tasks01/poly2block.rs +++ b/src/tasks/tasks01/poly2block.rs @@ -2,7 +2,12 @@ use crate::utils::poly::{self, coefficient_to_binary}; use base64::prelude::*; use serde_json::Value; -pub fn poly2block(coefficients: Vec) -> String { +pub fn poly2block(args: &Value) -> String { + let coefficients: Vec = args["coefficients"] + .as_array() + .unwrap() + .into_iter() + .map(|x| x.as_u64().unwrap() as u8) + .collect(); BASE64_STANDARD.encode(poly::coefficient_to_binary(coefficients).to_ne_bytes()) } -