Skip to content

Commit

Permalink
Merge pull request #57 from filecoin-project/add-rayon
Browse files Browse the repository at this point in the history
Add rayon
  • Loading branch information
jbesraa authored Nov 8, 2023
2 parents 437b66a + ae13b03 commit b9fcb18
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 130 deletions.
1 change: 1 addition & 0 deletions fplus-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ reqwest = { version = "0.11.18", features = ["json"] }
futures = "0.3.28"
tokio = { version = "1.32.0", features = ["rt", "macros"] }
uuidv4 = "1.0.0"
rayon = "1.8.0"
22 changes: 21 additions & 1 deletion fplus-lib/src/base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::io::Cursor;

use base64;

use crate::core::application::file::ApplicationFile;
use crate::core::application::file::{ApplicationFile, ValidNotaryList, ValidRKHList};

pub fn decode(i: &str) -> Option<ApplicationFile> {
let mut binding = Cursor::new(i);
Expand All @@ -13,3 +13,23 @@ pub fn decode(i: &str) -> Option<ApplicationFile> {
};
Some(app_file)
}

pub fn decode_notary(i: &str) -> Option<ValidNotaryList> {
let mut binding = Cursor::new(i);
let decoder = base64::read::DecoderReader::new(&mut binding, base64::STANDARD);
let notaries: ValidNotaryList = match serde_json::from_reader(decoder) {
Ok(f) => f,
Err(_) => return None,
};
Some(notaries)
}

pub fn decode_rkh(i: &str) -> Option<ValidRKHList> {
let mut binding = Cursor::new(i);
let decoder = base64::read::DecoderReader::new(&mut binding, base64::STANDARD);
let rkh: ValidRKHList = match serde_json::from_reader(decoder) {
Ok(f) => f,
Err(_) => return None,
};
Some(rkh)
}
22 changes: 22 additions & 0 deletions fplus-lib/src/core/application/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,25 @@ pub struct AllocationRequest {
pub is_active: bool,
pub allocation_amount: String,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ValidNotaryList {
notaries: Vec<String>,
}

impl ValidNotaryList {
pub fn is_valid(&self, notary: &str) -> bool {
self.notaries.contains(&notary.to_string())
}
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ValidRKHList {
rkh: Vec<String>,
}

impl ValidRKHList {
pub fn is_valid(&self, rkh: &str) -> bool {
self.rkh.contains(&rkh.to_string())
}
}
7 changes: 7 additions & 0 deletions fplus-lib/src/core/application/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,10 @@ impl file::ApplicationFile {
}
}
}

impl std::str::FromStr for file::ApplicationFile {
type Err = serde_json::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
serde_json::from_str(s)
}
}
Loading

0 comments on commit b9fcb18

Please sign in to comment.