Rename compute->list_modified_fields, and slight refactor
This commit is contained in:
parent
2fadc2e39c
commit
43459fa0bb
@ -31,26 +31,26 @@ impl ProcessState {
|
||||
Value::Object(fields2plain)
|
||||
}
|
||||
|
||||
fn compute_modified_fields(&self, previous_state: Option<&ProcessState>) -> Vec<String> {
|
||||
fn list_modified_fields(&self, previous_state: Option<&ProcessState>) -> Vec<String> {
|
||||
let new_state = &self.pcd_commitment;
|
||||
|
||||
// Ensure the new state is a JSON object
|
||||
let new_state_obj = new_state
|
||||
let new_state_commitments = new_state
|
||||
.as_object()
|
||||
.expect("New state should be a JSON object");
|
||||
|
||||
if let Some(prev_state) = previous_state {
|
||||
// Previous state exists; compute differences
|
||||
let previous_state_obj = prev_state
|
||||
let previous_state_commitments = prev_state
|
||||
.pcd_commitment
|
||||
.as_object()
|
||||
.expect("Previous state should be a JSON object");
|
||||
|
||||
// Compute modified fields by comparing with previous state
|
||||
new_state_obj
|
||||
new_state_commitments
|
||||
.iter()
|
||||
.filter_map(|(key, value)| {
|
||||
let previous_value = previous_state_obj.get(key);
|
||||
let previous_value = previous_state_commitments.get(key);
|
||||
if previous_value.is_none() || value != previous_value.unwrap() {
|
||||
Some(key.clone())
|
||||
} else {
|
||||
@ -60,7 +60,7 @@ impl ProcessState {
|
||||
.collect()
|
||||
} else {
|
||||
// No previous state; all fields are considered modified
|
||||
new_state_obj.keys().cloned().collect()
|
||||
new_state_commitments.keys().cloned().collect()
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ impl ProcessState {
|
||||
}
|
||||
|
||||
// Compute modified fields
|
||||
let modified_fields = self.compute_modified_fields(previous_state);
|
||||
let modified_fields = self.list_modified_fields(previous_state);
|
||||
|
||||
if modified_fields.is_empty() {
|
||||
return Err(anyhow::anyhow!("State is identical to the previous state"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user