Skip to content

Commit

Permalink
Minor fixes to prev changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Stentonian committed Jan 31, 2024
1 parent acdf5a1 commit eea57b8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ As seen above, the proof generation can be done via the tree build command, but
dapol -vvv gen-proofs --entity-ids ./examples/entities_example.csv --tree-file <serialized_tree_file>
```

```bash
echo "[email protected]" | dapol -vvv gen-proofs --tree-file examples/my_serialized_tree_for_testing.dapoltree --entitiy-ids -
```

The proof generation command only offers 1 way to inject the tree (deserialization), as apposed to the tree build which offers different options.

#### Proof verification
Expand Down
14 changes: 5 additions & 9 deletions src/entity/entity_ids_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,36 +46,32 @@ impl EntityIdsParser {
/// - Parse the value as a string list using `serde_json`
/// - An error is returned if:
/// a) deserialization using `serde_json` fails
///
/// If neither are set then an error is returned.
pub fn parse(self) -> Result<Vec<EntityId>, EntityIdsParserError> {
if let Some(path) = self.path {
EntityIdsParser::parse_csv(path)
} else if let Some(entity_ids_list) = self.entity_ids_list {
info!("list {:?}", entity_ids_list);
// let mut json_styled = "{".to_string();
// json_styled.push_str(&entity_ids_list);
// json_styled.push_str("}");
EntityIdsParser::parse_list(entity_ids_list)
} else {
Err(EntityIdsParserError::NeitherPathNorListSet)
}
}

fn parse_list(mut entity_ids_list: String) -> Result<Vec<EntityId>, EntityIdsParserError> {
// Remove trailing newline if it exists.
if entity_ids_list.chars().nth_back(0).map_or(false, |c| c == '\n') {
entity_ids_list.pop();
}

// let raw_vec: Vec<String> = serde_json::from_str(entity_ids_json)?;
// Assume the input is a comma-separated list.
let parts = entity_ids_list.split(',');
//let entity_ids = parts.collect::<Vec<&str>>();

let mut entity_ids = Vec::<EntityId>::new();// = Vec::with_capacity(raw_vec.len());
let mut entity_ids = Vec::<EntityId>::new();
for part in parts {
entity_ids.push(EntityId::from_str(&part)?)
}

info!("entity ids {:?}", entity_ids);

Ok(entity_ids)
}

Expand Down
3 changes: 2 additions & 1 deletion src/inclusion_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ impl InclusionProof {
///
/// An error is logged and returned if
/// 1. The file cannot be opened.
/// 2. The [bincode] deserializer fails.
/// 2. The deserializer fails.
/// 3. The file extension is not supported.
pub fn deserialize(file_path: PathBuf) -> Result<InclusionProof, InclusionProofError> {
let ext = file_path.extension().and_then(|s| s.to_str()).ok_or(
InclusionProofError::UnknownFileType(file_path.clone().into_os_string()),
Expand Down

0 comments on commit eea57b8

Please sign in to comment.