fn collect_contracts(mut contract: Contract, contracts: &mut Vec<Contract>, visits: &mut Vec<Visit>) -> Result<()> {
    for visit in visits.iter() {
        // It is possible for multiple contracts to import the same contract.
        if visit.full_path() == contract.full_path() {
            return Ok(());
        }

        // It is possible for multiple contracts to share the same name.
        if visit.file_name() == contract.file_name() {
            bail!(
                "Found two contracts with the same file name. Please rename one of them:\n\n{:?}\n{:?}",
                visit.full_path(),
                contract.full_path(),
            );
        }
    }

    visits.push(Visit::new(
        OsString::from(contract.file_name()),
        PathBuf::from(contract.full_path()),
    ));

    let source_code = read_source_code(contract.full_path())?;
    let mut multisol_source_code = source_code.clone();

    // Iterate over all imports in the current contract. There is only one item in each capture group,
    // the actual path to the contract.
    for capture_group in IMPORT_REGEX.captures_iter(&source_code) {
        // Skip the first element in the capture group array because that's the full regex match.
        let import_str = &capture_group[1];
        let import_path = PathBuf::from(String::from(import_str));
        let imported_contract = Contract::from_import_path(&contract, &import_path)?;

        // If the import path is not of the form "./Foo.sol", modify the source code so that all imports
        // use paths relative to the same directory.
        if contract.directory() != imported_contract.directory() {
            // Safe to unwrap because all Solidity files are UTF-8 compliant.
            let file_name = imported_contract.file_name().to_str().unwrap();
            let file_name_with_dot = ["./", file_name].join("");
            multisol_source_code = multisol_source_code.replace(import_str, &file_name_with_dot);
        }

        collect_contracts(imported_contract, contracts, visits)?;
    }

    contract.set_source_code(multisol_source_code);
    contracts.push(contract);

    Ok(())
}
/// Starts from the contract provided by the user and finds all the imported contracts recursively.
/// The search is depth-first.
Starts from the contract provided by the user and finds all the imported contracts recursively.
The search is depth-first.
Starts from the contract provided by the user and finds all the imported contracts recursively . The search is depth - first .
fn collect_contracts(mut contract: Contract, contracts: &mut Vec<Contract>, visits: &mut Vec<Visit>) -> Result<()> {
    for visit in visits.iter() {
        // It is possible for multiple contracts to import the same contract.
        if visit.full_path() == contract.full_path() {
            return Ok(());
        }
        // It is possible for multiple contracts to share the same name.
        if visit.file_name() == contract.file_name() {
            bail!(
                "Found two contracts with the same file name. Please rename one of them:\n\n{:?}\n{:?}",
                visit.full_path(),
                contract.full_path(),
            );
        }
    }
    visits.push(Visit::new(
        OsString::from(contract.file_name()),
        PathBuf::from(contract.full_path()),
    ));
    let source_code = read_source_code(contract.full_path())?;
    let mut multisol_source_code = source_code.clone();
    // Iterate over all imports in the current contract. There is only one item in each capture group,
    // the actual path to the contract.
    for capture_group in IMPORT_REGEX.captures_iter(&source_code) {
        // Skip the first element in the capture group array because that's the full regex match.
        let import_str = &capture_group[1];
        let import_path = PathBuf::from(String::from(import_str));
        let imported_contract = Contract::from_import_path(&contract, &import_path)?;
        // If the import path is not of the form "./Foo.sol", modify the source code so that all imports
        // use paths relative to the same directory.
        if contract.directory() != imported_contract.directory() {
            // Safe to unwrap because all Solidity files are UTF-8 compliant.
            let file_name = imported_contract.file_name().to_str().unwrap();
            let file_name_with_dot = ["./", file_name].join("");
            multisol_source_code = multisol_source_code.replace(import_str, &file_name_with_dot);
        }
        collect_contracts(imported_contract, contracts, visits)?;
    }
    contract.set_source_code(multisol_source_code);
    contracts.push(contract);
    Ok(())
}
fn collect_contracts ( mut contract : Contract , contracts : & mut Vec < Contract > , visits : & mut Vec < Visit > ) -> Result < ( ) > { for visit in visits . iter ( ) { // It is possible for multiple contracts to import the same contract. if visit . full_path ( ) == contract . full_path ( ) { return Ok ( ( ) ) ; } // It is possible for multiple contracts to share the same name. if visit . file_name ( ) == contract . file_name ( ) { bail ! ( " \n \n \n " visit full_path ( ) contract full_path ( ) ) ; } } visits . push ( Visit :: new ( OsString :: from ( contract . file_name ( ) ) , PathBuf :: from ( contract . full_path ( ) ) , ) ) ; let source_code = read_source_code ( contract . full_path ( ) ) ? ; let mut multisol_source_code = source_code . clone ( ) ; // Iterate over all imports in the current contract. There is only one item in each capture group, // the actual path to the contract. for capture_group in IMPORT_REGEX . captures_iter ( & source_code ) { // Skip the first element in the capture group array because that's the full regex match. let import_str = & capture_group [ 1 ] ; let import_path = PathBuf :: from ( String :: from ( import_str ) ) ; let imported_contract = Contract :: from_import_path ( & contract , & import_path ) ? ; // If the import path is not of the form "./Foo.sol", modify the source code so that all imports // use paths relative to the same directory. if contract . directory ( ) != imported_contract . directory ( ) { // Safe to unwrap because all Solidity files are UTF-8 compliant. let file_name = imported_contract . file_name ( ) . to_str ( ) . unwrap ( ) ; let file_name_with_dot = [ " " , file_name ] . join ( " " ) ; multisol_source_code = multisol_source_code . replace ( import_str , & file_name_with_dot ) ; } collect_contracts ( imported_contract , contracts , visits ) ? ; } contract . set_source_code ( multisol_source_code ) ; contracts . push ( contract ) ; Ok ( ( ) ) }
Starts from the contract provided by the user and finds all the imported contracts recursively.
Starts from the contract provided by the user and finds all the imported contracts recursively .
contract
Contract
contracts
&mut Vec<Contract>
visits
&mut Vec<Visit>
contract
Contract
contracts
&mut Vec<Contract>
visits
&mut Vec<Visit>