Update to latest common
This commit is contained in:
parent
93ae65ece7
commit
0d522182d6
37
src/api.rs
37
src/api.rs
@ -904,8 +904,14 @@ fn handle_pcd(pcd: Value) -> AnyhowResult<ApiReturn> {
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
debug!("Updating process states with {:#?}", updated_prd);
|
||||
process.insert_state(&updated_prd)?;
|
||||
let new_state = ProcessState {
|
||||
commited_in: *outpoint,
|
||||
pcd_commitment: updated_prd.pcd_commitments,
|
||||
encrypted_pcd: pcd,
|
||||
keys: updated_prd.keys,
|
||||
validation_tokens: vec![]
|
||||
};
|
||||
process.insert_concurrent_state(new_state)?;
|
||||
process.prune_impending_requests();
|
||||
return Ok(ApiReturn {
|
||||
updated_process: Some((outpoint.to_string(), process.clone())),
|
||||
@ -1151,8 +1157,8 @@ pub fn update_process(
|
||||
let new_state_val = Value::from_str(&new_state)?;
|
||||
|
||||
// We hash all the new values
|
||||
let pcd_commitment = new_state_val.hash_fields(outpoint)?;
|
||||
let new_state_merkle_root = <Value as Pcd>::create_merkle_tree(&Value::Object(pcd_commitment))?.root().unwrap();
|
||||
let pcd_commitment = Value::Object(new_state_val.hash_fields(outpoint)?);
|
||||
let new_state_merkle_root = <Value as Pcd>::create_merkle_tree(&pcd_commitment)?.root().unwrap();
|
||||
|
||||
// We compare the new state with the previous one
|
||||
let last_state_merkle_root = <Value as Pcd>::create_merkle_tree(last_state_commitments)?.root().unwrap();
|
||||
@ -1172,25 +1178,26 @@ pub fn update_process(
|
||||
.collect();
|
||||
new_state_val.encrypt_fields(&fields_to_encrypt, &mut fields2keys, &mut fields2cipher);
|
||||
|
||||
let encrypted_pcd = Value::Object(fields2cipher);
|
||||
|
||||
// We create an encrypted values merkle root
|
||||
let new_state_encrypted_commitments = Value::Object(fields2cipher).hash_fields(OutPoint::null())?;
|
||||
let new_state_encrypted_commitments = encrypted_pcd.hash_fields(OutPoint::null())?;
|
||||
let new_state_encrypted_root = <Value as Pcd>::create_merkle_tree(&Value::Object(new_state_encrypted_commitments.clone()))?.root().unwrap();
|
||||
|
||||
let to_update = process.get_latest_state().unwrap(); // This is an empty state with `commited_in` set as the last unspent output
|
||||
|
||||
let device = lock_local_device()?;
|
||||
let sender = device.to_member();
|
||||
|
||||
let update_prd = Prd::new_update(
|
||||
outpoint,
|
||||
serde_json::to_string(&sender)?,
|
||||
new_state_encrypted_root.to_lower_hex_string(),
|
||||
fields2keys,
|
||||
Value::Object(new_state_encrypted_commitments),
|
||||
);
|
||||
|
||||
let new_state = ProcessState {
|
||||
commited_in: outpoint,
|
||||
pcd_commitment: pcd_commitment,
|
||||
encrypted_pcd: encrypted_pcd,
|
||||
keys: fields2keys,
|
||||
validation_tokens: vec![]
|
||||
};
|
||||
|
||||
// Add the new state to the process
|
||||
process.insert_state(&update_prd);
|
||||
process.insert_concurrent_state(new_state)?;
|
||||
|
||||
Ok(ApiReturn {
|
||||
updated_process: Some((init_commitment, process.clone())),
|
||||
|
Loading…
x
Reference in New Issue
Block a user