aleo-setup icon indicating copy to clipboard operation
aleo-setup copied to clipboard

Code redundancy in operator.rs

Open apruden2008 opened this issue 4 years ago • 0 comments

Interface for the contributor/verifier to upload a challenge/response currently creates a parent directory for the file, which is redundant. Furthermore, much of the code used is the same between challenge / response pub functions is the same. This could potentially be re-implemented in a simpler way.

operator.rs

    #[inline]
    pub fn upload_response(
        &self,
        participant: &Participant,
        response_file: &[u8],
        signature_file: &[u8],
        response_path: PathBuf,
        signature_path: PathBuf,
    ) -> anyhow::Result<()> {
        // Acquire the coordinator write lock.
        let coordinator = self.coordinator.write().unwrap();

        // Check that the participant is an active contributor in the current round.
        if !Self::is_active_contributor(&coordinator, participant) {
            error!("Participant {} is not authorized", participant);
            return Err(CoordinatorError::ParticipantUnauthorized.into());
        }

        // TODO (howardwu): Remove this operation.
        // Create the parent directory for the response file, if it does not exist.
        crate::utils::create_parent_directory(response_path.to_str().unwrap());

        if let Err(error) = io::copy(&mut &response_file[..], &mut File::create(&response_path)?) {
            fs::remove_file(response_path)?;
            return Err(error.into());
        }

        if let Err(error) = io::copy(&mut &signature_file[..], &mut File::create(&signature_path)?) {
            fs::remove_file(signature_path)?;
            return Err(error.into());
        }

        Ok(())
    }

apruden2008 avatar Feb 28 '21 00:02 apruden2008