pub async fn command_get_cost(
    arweave: &Arweave,
    glob_str: &str,
    reward_mult: f32,
    with_sol: bool,
    bundle_size: u64,
    no_bundle: bool,
) -> CommandResult {
    let paths_iter = glob(glob_str)?.filter_map(Result::ok);
    let (base, incremental) = arweave.get_price_terms(reward_mult).await?;
    let (_, usd_per_ar, usd_per_sol) = arweave.get_price(&1).await?;

    let units = match with_sol {
        true => "lamports",
        false => "winstons",
    };

    let (num_trans, num_files, cost, bytes) = if no_bundle {
        paths_iter.fold((0, 0, 0, 0), |(n_t, n_f, c, b), p| {
            let data_len = p.metadata().unwrap().len();
            (
                n_t + 1,
                n_f + 1,
                c + {
                    let blocks_len = data_len / BLOCK_SIZE + (data_len % BLOCK_SIZE != 0) as u64;
                    match with_sol {
                        true => {
                            std::cmp::max((base + incremental * (blocks_len - 1)) * 0, FLOOR) + 5000
                        }
                        false => base + incremental * (blocks_len - 1),
                    }
                },
                b + data_len,
            )
        })
    } else {
        let path_chunks = arweave.chunk_file_paths(paths_iter, bundle_size)?;
        path_chunks.iter().fold(
            (0, 0, 0, 0),
            |(n_t, n_f, c, b), PathsChunk(paths, data_len)| {
                (
                    n_t + 1,
                    n_f + paths.len(),
                    c + {
                        let blocks_len =
                            data_len / BLOCK_SIZE + (data_len % BLOCK_SIZE != 0) as u64;
                        match with_sol {
                            true => {
                                std::cmp::max((base + incremental * (blocks_len - 1)) * 0, FLOOR)
                                    + 5000
                            }
                            false => base + incremental * (blocks_len - 1),
                        }
                    },
                    b + data_len,
                )
            },
        )
    };
    if num_files == 0 {
        println!("No files matched glob.");
    } else {
        // get usd cost based on calculated cost
        let usd_cost = match with_sol {
            true => (&cost * &usd_per_sol).to_f32().unwrap() / 1e11_f32,
            false => (&cost * &usd_per_ar).to_f32().unwrap() / 1e14_f32,
        };

        println!(
            "The price to upload {} files with {} total bytes in {} transaction(s) is {} {} (${:.4}).",
            num_files, bytes, num_trans, cost, units, usd_cost
        );
    }
    Ok(())
}
/// Gets cost of uploading a list of files.
Gets cost of uploading a list of files.
Gets cost of uploading a list of files .
pub async fn command_get_cost(
    arweave: &Arweave,
    glob_str: &str,
    reward_mult: f32,
    with_sol: bool,
    bundle_size: u64,
    no_bundle: bool,
) -> CommandResult {
    let paths_iter = glob(glob_str)?.filter_map(Result::ok);
    let (base, incremental) = arweave.get_price_terms(reward_mult).await?;
    let (_, usd_per_ar, usd_per_sol) = arweave.get_price(&1).await?;
    let units = match with_sol {
        true => "lamports",
        false => "winstons",
    };
    let (num_trans, num_files, cost, bytes) = if no_bundle {
        paths_iter.fold((0, 0, 0, 0), |(n_t, n_f, c, b), p| {
            let data_len = p.metadata().unwrap().len();
            (
                n_t + 1,
                n_f + 1,
                c + {
                    let blocks_len = data_len / BLOCK_SIZE + (data_len % BLOCK_SIZE != 0) as u64;
                    match with_sol {
                        true => {
                            std::cmp::max((base + incremental * (blocks_len - 1)) * 0, FLOOR) + 5000
                        }
                        false => base + incremental * (blocks_len - 1),
                    }
                },
                b + data_len,
            )
        })
    } else {
        let path_chunks = arweave.chunk_file_paths(paths_iter, bundle_size)?;
        path_chunks.iter().fold(
            (0, 0, 0, 0),
            |(n_t, n_f, c, b), PathsChunk(paths, data_len)| {
                (
                    n_t + 1,
                    n_f + paths.len(),
                    c + {
                        let blocks_len =
                            data_len / BLOCK_SIZE + (data_len % BLOCK_SIZE != 0) as u64;
                        match with_sol {
                            true => {
                                std::cmp::max((base + incremental * (blocks_len - 1)) * 0, FLOOR)
                                    + 5000
                            }
                            false => base + incremental * (blocks_len - 1),
                        }
                    },
                    b + data_len,
                )
            },
        )
    };
    if num_files == 0 {
        println!("No files matched glob.");
    } else {
        // get usd cost based on calculated cost
        let usd_cost = match with_sol {
            true => (&cost * &usd_per_sol).to_f32().unwrap() / 1e11_f32,
            false => (&cost * &usd_per_ar).to_f32().unwrap() / 1e14_f32,
        };
        println!(
            "The price to upload {} files with {} total bytes in {} transaction(s) is {} {} (${:.4}).",
            num_files, bytes, num_trans, cost, units, usd_cost
        );
    }
    Ok(())
}
pub async fn command_get_cost ( arweave : & Arweave , glob_str : & str , reward_mult : f32 , with_sol : bool , bundle_size : u64 , no_bundle : bool , ) -> CommandResult { let paths_iter = glob ( glob_str ) ? . filter_map ( Result :: ok ) ; let ( base , incremental ) = arweave . get_price_terms ( reward_mult ) . await ? ; let ( _ , usd_per_ar , usd_per_sol ) = arweave . get_price ( & 1 ) . await ? ; let units = match with_sol { true => " " , false => " " , } ; let ( num_trans , num_files , cost , bytes ) = if no_bundle { paths_iter . fold ( ( 0 , 0 , 0 , 0 ) , | ( n_t , n_f , c , b ) , p | { let data_len = p . metadata ( ) . unwrap ( ) . len ( ) ; ( n_t + 1 , n_f + 1 , c + { let blocks_len = data_len / BLOCK_SIZE + ( data_len % BLOCK_SIZE != 0 ) as u64 ; match with_sol { true => { std :: cmp :: max ( ( base + incremental * ( blocks_len - 1 ) ) * 0 , FLOOR ) + 5000 } false => base + incremental * ( blocks_len - 1 ) , } } , b + data_len , ) } ) } else { let path_chunks = arweave . chunk_file_paths ( paths_iter , bundle_size ) ? ; path_chunks . iter ( ) . fold ( ( 0 , 0 , 0 , 0 ) , | ( n_t , n_f , c , b ) , PathsChunk ( paths , data_len ) | { ( n_t + 1 , n_f + paths . len ( ) , c + { let blocks_len = data_len / BLOCK_SIZE + ( data_len % BLOCK_SIZE != 0 ) as u64 ; match with_sol { true => { std :: cmp :: max ( ( base + incremental * ( blocks_len - 1 ) ) * 0 , FLOOR ) + 5000 } false => base + incremental * ( blocks_len - 1 ) , } } , b + data_len , ) } , ) } ; if num_files == 0 { println ! ( " " ) ; } else { // get usd cost based on calculated cost let usd_cost = match with_sol { true => ( & cost * & usd_per_sol ) . to_f32 ( ) . unwrap ( ) / 1e11_f32 , false => ( & cost * & usd_per_ar ) . to_f32 ( ) . unwrap ( ) / 1e14_f32 , } ; println ! ( " " num_files bytes num_trans cost units usd_cost ) ; } Ok ( ( ) ) }
Gets cost of uploading a list of files.
Gets cost of uploading a list of files .
arweave
&Arweave
glob_str
&str
reward_mult
f32
with_sol
bool
bundle_size
u64
no_bundle
bool
arweave
&Arweave
glob_str
&str
reward_mult
f32
with_sol
bool
bundle_size
u64
no_bundle
bool