Rm handling of prd confirm
This commit is contained in:
parent
3ed94c7538
commit
0c702de953
43
src/api.rs
43
src/api.rs
@ -850,49 +850,6 @@ fn handle_prd(
|
||||
};
|
||||
|
||||
match prd.prd_type {
|
||||
PrdType::Confirm => {
|
||||
// It must match a prd we sent previously
|
||||
// We send the whole data in a pcd
|
||||
debug!("Received confirm prd with commitments {:#?}", prd.pcd_commitments);
|
||||
let relevant_state = relevant_process
|
||||
.get_latest_concurrent_states()?
|
||||
.into_iter()
|
||||
.find(|state| {
|
||||
state.pcd_commitment == prd.pcd_commitments
|
||||
})
|
||||
.ok_or(anyhow::Error::msg("Original request not found"))?;
|
||||
|
||||
let member: Member = serde_json::from_str(&prd.sender)?;
|
||||
|
||||
// We send the data to all addresses of the member we know a secret for
|
||||
let mut ciphers = vec![];
|
||||
for address in member.get_addresses() {
|
||||
if let Some(shared_secret) = lock_shared_secrets()?.get_secret_for_address(address.as_str().try_into()?) {
|
||||
let cipher = encrypt_with_key(shared_secret.as_byte_array(), serde_json::to_string(&relevant_state.encrypted_pcd)?.as_bytes())?;
|
||||
ciphers.push(cipher.to_lower_hex_string());
|
||||
} else {
|
||||
// For now we don't fail if we're missing an address for a member but maybe we should
|
||||
warn!("Failed to find secret for address {}", address);
|
||||
}
|
||||
}
|
||||
|
||||
// This should never happen since we sent a message to get a confirmation back
|
||||
if ciphers.is_empty() {
|
||||
return Err(anyhow::Error::msg(format!("No available secrets for member {:?}", member)));
|
||||
}
|
||||
|
||||
let clear_pcd = relevant_state.decrypt_pcd()?;
|
||||
|
||||
let roles = clear_pcd.extract_roles()?;
|
||||
|
||||
let commit_msg = CommitMessage::new_update_commitment(outpoint, relevant_state.pcd_commitment.clone(), roles);
|
||||
|
||||
return Ok(ApiReturn {
|
||||
ciphers_to_send: ciphers,
|
||||
commit_to_send: Some(commit_msg),
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user