pub(super) async fn genesis_cells(
        &self,
        cell_ids_with_proofs: Vec<(CellId, Option<MembraneProof>)>,
        conductor_handle: ConductorHandle,
    ) -> ConductorResult<()> {
        let root_env_dir = std::path::PathBuf::from(self.root_env_dir.clone());

        let cells_tasks = cell_ids_with_proofs
            .into_iter()
            .map(|(cell_id, proof)| async {
                let root_env_dir = root_env_dir.clone();
                let keystore = self.keystore.clone();
                let conductor_handle = conductor_handle.clone();
                let cell_id_inner = cell_id.clone();
                let ribosome = conductor_handle
                    .get_ribosome(cell_id.saf_hash())
                    .await
                    .map_err(Box::new)?;
                tokio::spawn(async move {
                    let env = EnvWrite::open(
                        &root_env_dir,
                        DbKind::Cell(cell_id_inner.clone()),
                        keystore.clone(),
                    )?;
                    Cell::genesis(cell_id_inner, conductor_handle, env, ribosome, proof).await
                })
                .map_err(CellError::from)
                .and_then(|result| async move { result.map(|_| cell_id) })
                .await
            });
        let (success, errors): (Vec<_>, Vec<_>) = futures::future::join_all(cells_tasks)
            .await
            .into_iter()
            .partition(Result::is_ok);

        // unwrap safe because of the partition
        let success = success.into_iter().map(Result::unwrap);

        // If there were errors, cleanup and return the errors
        if !errors.is_empty() {
            for cell_id in success {
                let db = DbWrite::open(&root_env_dir, DbKind::Cell(cell_id))?;
                db.remove().await?;
            }

            // match needed to avoid Debug requirement on unwrap_err
            let errors = errors
                .into_iter()
                .map(|e| match e {
                    Err(e) => e,
                    Ok(_) => unreachable!("Safe because of the partition"),
                })
                .collect();

            Err(ConductorError::GenesisFailed { errors })
        } else {
            // No errors so return the cells
            Ok(())
        }
    }
/// Perform Genesis on the source chains for each of the specified CellIds.
///
/// If genesis fails for any cell, this entire function fails, and all other
/// partial or complete successes are rolled back.
Perform Genesis on the source chains for each of the specified CellIds.
If genesis fails for any cell, this entire function fails, and all other
partial or complete successes are rolled back.
Perform Genesis on the source chains for each of the specified CellIds . If genesis fails for any cell this entire function fails and all other partial or complete successes are rolled back .
pub(super) async fn genesis_cells(
        &self,
        cell_ids_with_proofs: Vec<(CellId, Option<MembraneProof>)>,
        conductor_handle: ConductorHandle,
    ) -> ConductorResult<()> {
        let root_env_dir = std::path::PathBuf::from(self.root_env_dir.clone());
        let cells_tasks = cell_ids_with_proofs
            .into_iter()
            .map(|(cell_id, proof)| async {
                let root_env_dir = root_env_dir.clone();
                let keystore = self.keystore.clone();
                let conductor_handle = conductor_handle.clone();
                let cell_id_inner = cell_id.clone();
                let ribosome = conductor_handle
                    .get_ribosome(cell_id.saf_hash())
                    .await
                    .map_err(Box::new)?;
                tokio::spawn(async move {
                    let env = EnvWrite::open(
                        &root_env_dir,
                        DbKind::Cell(cell_id_inner.clone()),
                        keystore.clone(),
                    )?;
                    Cell::genesis(cell_id_inner, conductor_handle, env, ribosome, proof).await
                })
                .map_err(CellError::from)
                .and_then(|result| async move { result.map(|_| cell_id) })
                .await
            });
        let (success, errors): (Vec<_>, Vec<_>) = futures::future::join_all(cells_tasks)
            .await
            .into_iter()
            .partition(Result::is_ok);
        // unwrap safe because of the partition
        let success = success.into_iter().map(Result::unwrap);
        // If there were errors, cleanup and return the errors
        if !errors.is_empty() {
            for cell_id in success {
                let db = DbWrite::open(&root_env_dir, DbKind::Cell(cell_id))?;
                db.remove().await?;
            }
            // match needed to avoid Debug requirement on unwrap_err
            let errors = errors
                .into_iter()
                .map(|e| match e {
                    Err(e) => e,
                    Ok(_) => unreachable!("Safe because of the partition"),
                })
                .collect();
            Err(ConductorError::GenesisFailed { errors })
        } else {
            // No errors so return the cells
            Ok(())
        }
    }
pub ( super ) async fn genesis_cells ( & self , cell_ids_with_proofs : Vec < ( CellId , Option < MembraneProof > ) > , conductor_handle : ConductorHandle , ) -> ConductorResult < ( ) > { let root_env_dir = std :: path :: PathBuf :: from ( self . root_env_dir . clone ( ) ) ; let cells_tasks = cell_ids_with_proofs . into_iter ( ) . map ( | ( cell_id , proof ) | async { let root_env_dir = root_env_dir . clone ( ) ; let keystore = self . keystore . clone ( ) ; let conductor_handle = conductor_handle . clone ( ) ; let cell_id_inner = cell_id . clone ( ) ; let ribosome = conductor_handle . get_ribosome ( cell_id . saf_hash ( ) ) . await . map_err ( Box :: new ) ? ; tokio :: spawn ( async move { let env = EnvWrite :: open ( & root_env_dir , DbKind :: Cell ( cell_id_inner . clone ( ) ) , keystore . clone ( ) , ) ? ; Cell :: genesis ( cell_id_inner , conductor_handle , env , ribosome , proof ) . await } ) . map_err ( CellError :: from ) . and_then ( | result | async move { result . map ( | _ | cell_id ) } ) . await } ) ; let ( success , errors ) : ( Vec < _ > , Vec < _ > ) = futures :: future :: join_all ( cells_tasks ) . await . into_iter ( ) . partition ( Result :: is_ok ) ; // unwrap safe because of the partition let success = success . into_iter ( ) . map ( Result :: unwrap ) ; // If there were errors, cleanup and return the errors if ! errors . is_empty ( ) { for cell_id in success { let db = DbWrite :: open ( & root_env_dir , DbKind :: Cell ( cell_id ) ) ? ; db . remove ( ) . await ? ; } // match needed to avoid Debug requirement on unwrap_err let errors = errors . into_iter ( ) . map ( | e | match e { Err ( e ) => e , Ok ( _ ) => unreachable ! ( " " ) , } ) . collect ( ) ; Err ( ConductorError :: GenesisFailed { errors } ) } else { // No errors so return the cells Ok ( ( ) ) } }
Perform Genesis on the source chains for each of the specified CellIds.
Perform Genesis on the source chains for each of the specified CellIds .
&self
cell_ids_with_proofs
Vec<(CellId, Option<MembraneProof>)>
conductor_handle
ConductorHandle
&self
cell_ids_with_proofs
Vec<(CellId, Option<MembraneProof>)>
conductor_handle
ConductorHandle