get_state_for_commitments_root mut and immut version

This commit is contained in:
Sosthene 2024-12-11 23:27:52 +01:00
parent d2d586f996
commit e0647610db

View File

@ -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 {
// This should never happen, but we better get rid of it now
return Err(anyhow::Error::msg("process is empty".to_owned()));
@ -345,8 +363,7 @@ impl Process {
if p.is_empty() {
continue;
}
let root = <Value as Pcd>::create_merkle_tree(&p.pcd_commitment).unwrap().root().unwrap();
if merkle_root == root {
if merkle_root == p.merkle_root.as_str() {
return Ok(p);
}
}