get_state_for_commitments_root mut and immut version
This commit is contained in:
parent
d2d586f996
commit
e0647610db
@ -335,7 +335,25 @@ impl Process {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_state_for_commitments_root(&mut self, merkle_root: [u8; 32]) -> anyhow::Result<&mut ProcessState> {
|
pub fn get_state_for_commitments_root(&self, merkle_root: &str) -> anyhow::Result<&ProcessState> {
|
||||||
|
if self.get_number_of_states() == 0 {
|
||||||
|
// This should never happen, but we better get rid of it now
|
||||||
|
return Err(anyhow::Error::msg("process is empty".to_owned()));
|
||||||
|
}
|
||||||
|
|
||||||
|
for p in self.get_latest_concurrent_states()? {
|
||||||
|
if p.is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if merkle_root == p.merkle_root.as_str() {
|
||||||
|
return Ok(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Err(anyhow::Error::msg("No state for this merkle root"));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_state_for_commitments_root_mut(&mut self, merkle_root: &str) -> anyhow::Result<&mut ProcessState> {
|
||||||
if self.get_number_of_states() == 0 {
|
if self.get_number_of_states() == 0 {
|
||||||
// This should never happen, but we better get rid of it now
|
// This should never happen, but we better get rid of it now
|
||||||
return Err(anyhow::Error::msg("process is empty".to_owned()));
|
return Err(anyhow::Error::msg("process is empty".to_owned()));
|
||||||
@ -345,8 +363,7 @@ impl Process {
|
|||||||
if p.is_empty() {
|
if p.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let root = <Value as Pcd>::create_merkle_tree(&p.pcd_commitment).unwrap().root().unwrap();
|
if merkle_root == p.merkle_root.as_str() {
|
||||||
if merkle_root == root {
|
|
||||||
return Ok(p);
|
return Ok(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user