PcdCommitments new refactor
This commit is contained in:
parent
77618c4061
commit
f69fc1587e
22
src/pcd.rs
22
src/pcd.rs
@ -192,29 +192,25 @@ impl Tsify for PcdCommitments {
|
|||||||
|
|
||||||
impl PcdCommitments {
|
impl PcdCommitments {
|
||||||
/// Creates a new commitments map with both permissioned and public data, + roles
|
/// Creates a new commitments map with both permissioned and public data, + roles
|
||||||
pub fn new(commited_in: &OutPoint, clear_state: &Pcd, public_data: &Pcd, roles: &Roles) -> Result<Self> {
|
pub fn new(commited_in: &OutPoint, attributes: &Pcd, roles: &Roles) -> Result<Self> {
|
||||||
let serialized_outpoint = serialize(commited_in);
|
let serialized_outpoint = serialize(commited_in);
|
||||||
let mut field2hash: BTreeMap<String, [u8; 32]> = BTreeMap::new();
|
let mut field2hash: BTreeMap<String, [u8; 32]> = BTreeMap::new();
|
||||||
for (field, value) in clear_state.iter() {
|
for (field, value) in attributes.iter() {
|
||||||
let mut value_bin = serde_json::to_string(&value)?.into_bytes();
|
let mut value_bin = serde_json::to_string(&value)?.into_bytes();
|
||||||
value_bin.extend_from_slice(field.as_bytes());
|
value_bin.extend_from_slice(field.as_bytes());
|
||||||
let tagged_hash = AnkPcdHash::from_value_with_outpoint(&value_bin, &serialized_outpoint);
|
let tagged_hash = AnkPcdHash::from_value_with_outpoint(&value_bin, &serialized_outpoint);
|
||||||
field2hash.insert(field.to_owned(), tagged_hash.to_byte_array());
|
field2hash.insert(field.to_owned(), tagged_hash.to_byte_array());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (field, value) in public_data.iter() {
|
if roles.len() > 0 {
|
||||||
let mut value_bin = serde_json::to_string(&value)?.into_bytes();
|
// This should be very rare, but just in case
|
||||||
value_bin.extend_from_slice(field.as_bytes());
|
let serialized_roles = roles.to_bytes()?;
|
||||||
let tagged_hash = AnkPcdHash::from_value_with_outpoint(&value_bin, &serialized_outpoint);
|
|
||||||
field2hash.insert(field.to_owned(), tagged_hash.to_byte_array());
|
let roles_hash = AnkPcdHash::from_value_with_outpoint(&serialized_roles, &serialized_outpoint);
|
||||||
|
|
||||||
|
field2hash.insert("roles".to_owned(), roles_hash.to_byte_array());
|
||||||
}
|
}
|
||||||
|
|
||||||
let serialized_roles = roles.to_bytes()?;
|
|
||||||
|
|
||||||
let roles_hash = AnkPcdHash::from_value_with_outpoint(&serialized_roles, &serialized_outpoint);
|
|
||||||
|
|
||||||
field2hash.insert("roles".to_owned(), roles_hash.to_byte_array());
|
|
||||||
|
|
||||||
Ok(Self(field2hash))
|
Ok(Self(field2hash))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user