fn add_subgraph_to_ipfs(
    client: IpfsClient,
    subgraph: &str,
) -> impl Future<Item = String, Error = Error> {
    /// Adds string to IPFS and returns link of the form `/ipfs/`.
    fn add(client: IpfsClient, data: String) -> impl Future<Item = String, Error = Error> {
        Box::pin(async move {
            client
                .add(Cursor::new(data))
                .map_ok(|res| format!("/ipfs/{}", res.hash))
                .map_err(|err| format_err!("error adding to IPFS {}", err))
                .await
        })
        .compat()
    }

    let dir = format!("tests/subgraphs/{}", subgraph);
    let subgraph_string = std::fs::read_to_string(format!("{}/{}.yaml", dir, subgraph)).unwrap();
    let mut ipfs_upload = Box::new(future::ok(subgraph_string.clone()))
        as Box<dyn Future<Item = String, Error = Error> + Send>;
    // Search for files linked by the subgraph, upload and update the sugraph
    // with their link.
    for file in WalkDir::new(&dir)
        .into_iter()
        .filter_map(Result::ok)
        .filter(|entry| {
            subgraph_string.contains(&format!("link to {}", entry.file_name().to_str().unwrap()))
        })
    {
        let client = client.clone();
        ipfs_upload = Box::new(ipfs_upload.and_then(move |subgraph_string| {
            add(client.clone(), read_to_string(file.path()).unwrap()).map(move |link| {
                subgraph_string.replace(
                    &format!("link to {}", file.file_name().to_str().unwrap()),
                    &link,
                )
            })
        }))
    }
    let add_client = client.clone();
    ipfs_upload.and_then(move |subgraph_string| add(add_client, subgraph_string))
}
/// Adds subgraph located in `test/subgraphs/`, replacing "link to" placeholders
/// in the subgraph manifest with links to files just added into a local IPFS
/// daemon on port 5001.
Adds subgraph located in `test/subgraphs/`, replacing "link to" placeholders
in the subgraph manifest with links to files just added into a local IPFS
daemon on port 5001.
Adds subgraph located in ` test / subgraphs / ` replacing " link to " placeholders in the subgraph manifest with links to files just added into a local IPFS daemon on port 5001 .
fn add_subgraph_to_ipfs(
    client: IpfsClient,
    subgraph: &str,
) -> impl Future<Item = String, Error = Error> {
    /// Adds string to IPFS and returns link of the form `/ipfs/`.
    fn add(client: IpfsClient, data: String) -> impl Future<Item = String, Error = Error> {
        Box::pin(async move {
            client
                .add(Cursor::new(data))
                .map_ok(|res| format!("/ipfs/{}", res.hash))
                .map_err(|err| format_err!("error adding to IPFS {}", err))
                .await
        })
        .compat()
    }
    let dir = format!("tests/subgraphs/{}", subgraph);
    let subgraph_string = std::fs::read_to_string(format!("{}/{}.yaml", dir, subgraph)).unwrap();
    let mut ipfs_upload = Box::new(future::ok(subgraph_string.clone()))
        as Box<dyn Future<Item = String, Error = Error> + Send>;
    // Search for files linked by the subgraph, upload and update the sugraph
    // with their link.
    for file in WalkDir::new(&dir)
        .into_iter()
        .filter_map(Result::ok)
        .filter(|entry| {
            subgraph_string.contains(&format!("link to {}", entry.file_name().to_str().unwrap()))
        })
    {
        let client = client.clone();
        ipfs_upload = Box::new(ipfs_upload.and_then(move |subgraph_string| {
            add(client.clone(), read_to_string(file.path()).unwrap()).map(move |link| {
                subgraph_string.replace(
                    &format!("link to {}", file.file_name().to_str().unwrap()),
                    &link,
                )
            })
        }))
    }
    let add_client = client.clone();
    ipfs_upload.and_then(move |subgraph_string| add(add_client, subgraph_string))
}
fn add_subgraph_to_ipfs ( client : IpfsClient , subgraph : & str , ) -> impl Future < Item = String , Error = Error > { /// Adds string to IPFS and returns link of the form `/ipfs/`. fn add ( client : IpfsClient , data : String ) -> impl Future < Item = String , Error = Error > { Box :: pin ( async move { client . add ( Cursor :: new ( data ) ) . map_ok ( | res | format ! ( " " res hash ) ) . map_err ( | err | format_err ! ( " " err ) ) . await } ) . compat ( ) } let dir = format ! ( " " subgraph ) ; let subgraph_string = std :: fs :: read_to_string ( format ! ( " " dir subgraph ) ) . unwrap ( ) ; let mut ipfs_upload = Box :: new ( future :: ok ( subgraph_string . clone ( ) ) ) as Box < dyn Future < Item = String , Error = Error > + Send > ; // Search for files linked by the subgraph, upload and update the sugraph // with their link. for file in WalkDir :: new ( & dir ) . into_iter ( ) . filter_map ( Result :: ok ) . filter ( | entry | { subgraph_string . contains ( & format ! ( " " entry file_name ( ) to_str ( ) unwrap ( ) ) ) } ) { let client = client . clone ( ) ; ipfs_upload = Box :: new ( ipfs_upload . and_then ( move | subgraph_string | { add ( client . clone ( ) , read_to_string ( file . path ( ) ) . unwrap ( ) ) . map ( move | link | { subgraph_string . replace ( & format ! ( " " file file_name ( ) to_str ( ) unwrap ( ) ) , & link , ) } ) } ) ) } let add_client = client . clone ( ) ; ipfs_upload . and_then ( move | subgraph_string | add ( add_client , subgraph_string ) ) }
Adds subgraph located in `test/subgraphs/`, replacing "link to" placeholders
in the subgraph manifest with links to files just added into a local IPFS
daemon on port 5001.
Adds subgraph located in ` test / subgraphs / ` replacing " link to " placeholders in the subgraph manifest with links to files just added into a local IPFS daemon on port 5001 .
client
IpfsClient
subgraph
&str
client
IpfsClient
subgraph
&str