update_process also return commit_msg

This commit is contained in:
NicolasCantu 2025-01-24 12:44:05 +01:00
parent 060f1689af
commit 04b467cc97

View File

@ -1294,6 +1294,7 @@ pub fn create_new_process(
} }
#[wasm_bindgen] #[wasm_bindgen]
/// TODO allow modifications from user that doesn't have read access to all attributes
pub fn update_process( pub fn update_process(
process_id: String, process_id: String,
new_state_str: String, new_state_str: String,
@ -1314,7 +1315,10 @@ pub fn update_process(
let roles = clear_new_state.extract_roles()?; let roles = clear_new_state.extract_roles()?;
let new_state = ProcessState::new(prev_state.commited_in, clear_new_state.to_value_object()?, last_state_descriptions.clone())?; // We expect the whole set of attributes for now, even if value does'nt change since previous state
// We rehash everything with the new txid, so we need the clear value
// eventually we would like to be able to create partial states even if we don't have read access to some attributes
let new_state = ProcessState::new(process.get_process_tip()?, clear_new_state.to_value_object()?, last_state_descriptions.clone())?;
// We compare the new state with the previous one // We compare the new state with the previous one
let last_state_merkle_root = &prev_state.state_id; let last_state_merkle_root = &prev_state.state_id;
@ -1337,13 +1341,16 @@ pub fn update_process(
let updated_process = UpdatedProcess { let updated_process = UpdatedProcess {
commitment_tx: outpoint, commitment_tx: outpoint,
current_process: process.clone(), current_process: process.clone(),
up_to_date_roles: roles, up_to_date_roles: roles.clone(),
new_diffs: diffs, new_diffs: diffs,
..Default::default() ..Default::default()
}; };
let commit_msg = CommitMessage::new_update_commitment(outpoint, new_state.pcd_commitment, roles);
Ok(ApiReturn { Ok(ApiReturn {
updated_process: Some(updated_process), updated_process: Some(updated_process),
commit_to_send: Some(commit_msg),
..Default::default() ..Default::default()
}) })
} }
@ -1502,7 +1509,6 @@ fn add_validation_token(init_commitment: String, merkle_root_hex: String, approv
// if the state is valid we also add a commit msg // if the state is valid we also add a commit msg
let update_is_valid = update_state.is_valid(process.get_parent_state(&update_state.commited_in)); let update_is_valid = update_state.is_valid(process.get_parent_state(&update_state.commited_in));
if update_is_valid.is_ok() { if update_is_valid.is_ok() {
debug!("Adding the commit msg to return value");
let roles = match update_state.encrypted_pcd.extract_roles() { let roles = match update_state.encrypted_pcd.extract_roles() {
Ok(roles) => roles, Ok(roles) => roles,
Err(_) => { Err(_) => {