From de5eb1b8cd36419d529d35461c529c6717c012c5 Mon Sep 17 00:00:00 2001 From: Sosthene00 Date: Thu, 2 Jan 2025 12:37:34 +0100 Subject: [PATCH] Update to latest common --- src/api.rs | 24 ++++++++++++------------ tests/pairing.rs | 4 +--- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/api.rs b/src/api.rs index 5ce65de..93ba732 100644 --- a/src/api.rs +++ b/src/api.rs @@ -708,7 +708,7 @@ fn create_diffs(process: &Process, new_state: &ProcessState) -> AnyhowResult val, Err(_) => Map::new() @@ -855,7 +855,7 @@ fn handle_prd( PrdType::Update => { // Compute the merkle tree root for the proposed new state to see if we already know about it let update_merkle_root = prd.pcd_commitments.create_merkle_tree()?.root().ok_or(AnyhowError::msg("Invalid merkle tree"))?.to_lower_hex_string(); - if relevant_process.get_state_for_commitments_root(&update_merkle_root).is_ok() { + if relevant_process.get_state_for_id(&update_merkle_root).is_ok() { // We already know about that state return Err(AnyhowError::msg("Received update for a state we already know")); } @@ -870,7 +870,7 @@ fn handle_prd( let new_state = ProcessState { commited_in, pcd_commitment: prd.pcd_commitments, - merkle_root: update_merkle_root.clone(), + state_id: update_merkle_root.clone(), keys: prd.keys, ..Default::default() }; @@ -927,7 +927,7 @@ fn handle_prd( let updated_process = UpdatedProcess { commitment_tx: OutPoint::from_str(&prd.root_commitment)?, current_process: relevant_process.clone(), - modified_state: Some(updated_state.merkle_root), + modified_state: Some(updated_state.state_id), ..Default::default() }; @@ -977,7 +977,7 @@ pub fn update_process_state(init_commitment: String, state_id: String, hash2valu // Get the state let state = process.get_latest_concurrent_states_mut()? .into_iter() - .find(|state| state.merkle_root == state_id) + .find(|state| state.state_id == state_id) .ok_or(ApiError::new("Unknown state".to_owned()))?; // Update each value @@ -1031,7 +1031,7 @@ pub fn update_process_state(init_commitment: String, state_id: String, hash2valu // If every value we can decrypt is valid, then we return the new state and diffs // We borrow it again immutably let process = processes.get(&outpoint).unwrap(); - let state = process.get_latest_concurrent_states()?.into_iter().find(|s| s.merkle_root == state_id).unwrap(); + let state = process.get_latest_concurrent_states()?.into_iter().find(|s| s.state_id == state_id).unwrap(); let diffs = create_diffs(&process, &state)?; let udpated_process = UpdatedProcess { @@ -1273,15 +1273,15 @@ pub fn update_process( let new_state = ProcessState::new(prev_state.commited_in, clear_new_state.to_value_object()?, last_state_descriptions.clone())?; // We compare the new state with the previous one - let last_state_merkle_root = &prev_state.merkle_root; + let last_state_merkle_root = &prev_state.state_id; - if *last_state_merkle_root == new_state.merkle_root { + if *last_state_merkle_root == new_state.state_id { return Err(ApiError::new("new proposed state is identical to the previous commited state".to_owned())); } // We check that we don't have already a similar concurrent state let concurrent_processes = process.get_latest_concurrent_states()?; - if concurrent_processes.iter().any(|p| p.merkle_root == new_state.merkle_root) { + if concurrent_processes.iter().any(|p| p.state_id == new_state.state_id) { return Err(ApiError::new("New state already known".to_owned())); } @@ -1316,7 +1316,7 @@ pub fn create_update_message( let process = processes.get_mut(&outpoint) .ok_or(ApiError::new("Unknown process".to_owned()))?; - let update_state = process.get_state_for_commitments_root(&merkle_root_hex)?; + let update_state = process.get_state_for_id(&merkle_root_hex)?; // We must have at least the key for the roles field, otherwise we don't know who to send the message to let clear_state = update_state.decrypt_pcd()?; @@ -1435,7 +1435,7 @@ fn add_validation_token(init_commitment: String, merkle_root_hex: String, approv .ok_or(ApiError::new("Unknown process".to_owned()))?; { - let update_state: &mut ProcessState = process.get_state_for_commitments_root_mut(&merkle_root_hex)?; + let update_state: &mut ProcessState = process.get_state_for_id_mut(&merkle_root_hex)?; let mut merkle_root = [0u8; 32]; @@ -1476,7 +1476,7 @@ pub fn create_response_prd(init_commitment: String, merkle_root_hex: String) -> let process = processes.get_mut(&outpoint) .ok_or(ApiError::new("Unknown process".to_owned()))?; - let update_state: &mut ProcessState = process.get_state_for_commitments_root_mut(&merkle_root_hex)?; + let update_state: &mut ProcessState = process.get_state_for_id_mut(&merkle_root_hex)?; // We must have at least the key for the roles field, otherwise we don't know who to send the message to let clear_state = update_state.decrypt_pcd()?; diff --git a/tests/pairing.rs b/tests/pairing.rs index e06a5c3..f56f9c2 100644 --- a/tests/pairing.rs +++ b/tests/pairing.rs @@ -8,8 +8,6 @@ use sdk_common::crypto::AnkSharedSecretHash; use sdk_common::log::debug; use sdk_common::pcd::{Member, Pcd, RoleDefinition}; use sdk_common::secrets::SecretsStore; -use sdk_common::sp_client::bitcoin::hex::FromHex; -use sdk_common::sp_client::bitcoin::OutPoint; use serde_json::{json, Map, Value}; use wasm_bindgen_test::*; @@ -234,7 +232,7 @@ fn test_pairing() { // We have to cheat here and let Bob access Alice process cache let process = alice_process_cache.get(&updated_process.commitment_tx).unwrap(); - let state = process.get_state_for_commitments_root(&new_state_id).unwrap(); + let state = process.get_state_for_id(&new_state_id).unwrap(); let hash2values: Map = bob_diff_cache.iter() .filter(|diff| diff.new_state_merkle_root == *new_state_id)