Skip to content

Commit

Permalink
Merge pull request #2 from starcoinorg/schema
Browse files Browse the repository at this point in the history
Implement schema for HashValue
  • Loading branch information
sanlee42 authored Mar 7, 2022
2 parents b4887ba + 2c95387 commit d871dfb
Show file tree
Hide file tree
Showing 3 changed files with 236 additions and 0 deletions.
217 changes: 217 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/diem-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ aes-gcm = "0.8.0"
diem-crypto-derive = { path = "../diem-crypto-derive", version = "0.0.3" }
bcs = "0.1.2"
libc = "^0.2"
schemars = {git = "https://github.com/starcoinorg/schemars", rev= "6972da92f4360e1779168bb3fe0274c521d324e2"}

[dev-dependencies]
bitvec = "0.19.4"
Expand Down
18 changes: 18 additions & 0 deletions crates/diem-crypto/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ use std::{
fmt,
str::FromStr,
};
use schemars::gen::SchemaGenerator;
use schemars::JsonSchema;
use schemars::schema::{InstanceType, Schema, SchemaObject};
#[cfg(not(feature = "avx512f"))]
use tiny_keccak::{Hasher, Sha3};

Expand Down Expand Up @@ -777,6 +780,21 @@ impl<T: ser::Serialize + ?Sized> TestOnlyHash for T {
hasher.finish()
}
}
impl JsonSchema for HashValue {

fn schema_name() -> String {
"HashValue".to_owned()
}

fn json_schema(_: &mut SchemaGenerator) -> Schema {
SchemaObject {
instance_type: Some(InstanceType::String.into()),
format: Some("HashValue".to_owned()),
..Default::default()
}
.into()
}
}

#[cfg(test)]
mod tests {
Expand Down

0 comments on commit d871dfb

Please sign in to comment.