From 4a29c6f5520507fcae6642e71fe92cf1ad358dda Mon Sep 17 00:00:00 2001 From: Caleb Date: Fri, 19 Nov 2021 21:40:42 -0800 Subject: [PATCH] readme nits --- Cargo.toml | 2 +- README.md | 4 ++-- src/lib.rs | 32 ++++++++++++++++++++------------ src/main.rs | 22 ++++++---------------- src/utils.rs | 11 ++--------- tests/integration.rs | 2 +- 6 files changed, 32 insertions(+), 41 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bae9a3d..15c9194 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "arloader" authors = ["calebeverett "] description = "Command line application and library for uploading files to Arweave." -version = "0.1.16" +version = "0.1.17" edition = "2021" license = "Apache-2.0" repository = "https://github.com/CalebEverett/arloader" diff --git a/README.md b/README.md index a1817da..7f74ccc 100644 --- a/README.md +++ b/README.md @@ -98,8 +98,8 @@ and that will print the number of pending transctions every second for one minut 128 | ▥▥▥ ``` -Given that Arloader bundles by default, your transaction is hopefully relatively attractive and you don't need to increase the reward to get it written in a timely fashion. However, if you see that there are a lot of transaction pending and you want to be sure your transaction goes through quickly, you can adjust the reward with `--reward-multipler` followed by something tha can be parsed as a float between `1.0` and `10.0`. The reward included in your transaction will then be multiplied by this factor when it gets submitted. Similar to the `--with-sol` flag, you can add `--reward-multipler` to both `estimate` and `upload` commands. +Given that Arloader bundles by default, your transaction is hopefully relatively attractive and you don't need to increase the reward to get it written in a timely fashion. However, if you see that there are a lot of transactions pending and you want to be sure your transaction goes through quickly, you can adjust the reward with `--reward-multipler` followed by something tha can be parsed as a float between `1.0` and `10.0`. The reward included in your transaction will then be multiplied by this factor when it gets submitted. Similar to the `--with-sol` flag, you can add `--reward-multiplier` to both `estimate` and `upload` commands. ## Usage without Bundles -You can add the `--no-bundle` flag if for some reason you want to create individual transactions. This works with both `estimate` and `upload` commands. In that case individual status objects are written to `LOG_DIR` and you can run `update` status to update them from the network and `status-report` for a count of transactions by status. \ No newline at end of file +You can add the `--no-bundle` flag if for some reason you want to create individual transactions. This works with both `estimate` and `upload` commands. In that case individual status objects are written to `LOG_DIR` and you can run `update-status` to update them from the network and `status-report` for a count of transactions by status. \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index cd4fa20..af94ed7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -828,7 +828,6 @@ impl Arweave { &self, paths_iter: IP, tags: Vec>, - log_dir: Option, price_terms: (u64, u64), ) -> Result<(Transaction, Value), Error> where @@ -884,13 +883,14 @@ mod tests { use crate::{ error::Error, transaction::{Base64, FromUtf8Strs, Tag}, - utils::{TempDir, TempFrom}, + utils::TempDir, Arweave, Status, }; + use futures::future::try_join_all; use glob::glob; use matches::assert_matches; - use serde_json; use std::{path::PathBuf, str::FromStr}; + use tokio::fs; #[tokio::test] async fn test_cannot_post_unsigned_transaction() -> Result<(), Error> { @@ -964,7 +964,7 @@ mod tests { } #[tokio::test] - async fn test_deserialize_bundle() -> Result<(), Error> { + async fn test_create_and_deserialize_large_bundle() -> Result<(), Error> { let arweave = Arweave::from_keypair_path( PathBuf::from( "tests/fixtures/arweave-key-7eV1qae4qVNqsNChg3Scdi-DpOLJPCogct4ixoq1WNg.json", @@ -973,20 +973,28 @@ mod tests { ) .await?; - let paths_iter = glob("tests/fixtures/[0-1]*.png")?.filter_map(Result::ok); + let file_path = PathBuf::from("tests/fixtures/1mb.bin"); + let temp_dir = TempDir::from_str("./tests/").await?; + + let _ = try_join_all((0..100).map(|i| { + fs::copy( + file_path.clone(), + temp_dir.0.join(format!("{}", i)).with_extension("bin"), + ) + })) + .await?; + + let glob_str = format!("{}/*.bin", temp_dir.0.display().to_string()); + + let paths_iter = glob(&glob_str)?.filter_map(Result::ok); let pre_data_items = arweave .create_data_items_from_file_paths(paths_iter, Vec::new()) .await?; - let (bundle, manifest_object) = - arweave.create_bundle_from_data_items(pre_data_items.clone())?; + let (bundle, _) = arweave.create_bundle_from_data_items(pre_data_items.clone())?; - println!( - "manifest_obj: {}", - serde_json::to_string_pretty(&manifest_object).unwrap() - ); let post_data_items = arweave.deserialize_bundle(bundle)?; - assert_eq!(post_data_items.len(), 3); + assert_eq!(post_data_items.len(), 101); Ok(()) } diff --git a/src/main.rs b/src/main.rs index 8a2f5e5..476b4da 100644 --- a/src/main.rs +++ b/src/main.rs @@ -745,12 +745,7 @@ async fn command_upload_bundle( } else { let paths_iter = glob(glob_str)?.filter_map(Result::ok); let (transaction, manifest_object) = arweave - .create_bundle_transaction_from_file_paths( - paths_iter, - tags, - log_dir.clone(), - price_terms, - ) + .create_bundle_transaction_from_file_paths(paths_iter, tags, price_terms) .await?; let signed_transaction = arweave.sign_transaction(transaction)?; @@ -777,8 +772,8 @@ async fn command_upload_bundle( id ); println!( - "\nFiles will be available at https://arweave.net/ once the bundle transaction has been confirmed. - \nThey will also be available at https://arweave.net/{manifest_id}/. + "\nFiles will be available at https://arweave.net/ once the bundle transaction has been confirmed. + \nThey will also be available at https://arweave.net/{manifest_id}/. \nReview {logdir}manifest_{manifest_id}.json for bundle item ids and file paths.", logdir=log_dir.unwrap().display().to_string(), manifest_id = manifest_object["id"].as_str().unwrap() ) @@ -873,12 +868,7 @@ async fn command_upload_bundle_with_sol( } else { let paths_iter = glob(glob_str)?.filter_map(Result::ok); let (transaction, manifest_object) = arweave - .create_bundle_transaction_from_file_paths( - paths_iter, - tags, - log_dir.clone(), - price_terms, - ) + .create_bundle_transaction_from_file_paths(paths_iter, tags, price_terms) .await?; let (signed_transaction, sig_response) = arweave @@ -907,8 +897,8 @@ async fn command_upload_bundle_with_sol( id ); println!( - "\nFiles will be available at https://arweave.net/ once the bundle transaction has been confirmed. - \nThey will also be available at https://arweave.net/{manifest_id}/. + "\nFiles will be available at https://arweave.net/ once the bundle transaction has been confirmed. + \nThey will also be available at https://arweave.net/{manifest_id}/. \nReview {logdir}manifest_{manifest_id}.json for bundle item ids and file paths.", logdir=log_dir.unwrap().display().to_string(), manifest_id = manifest_object["id"].as_str().unwrap() ) diff --git a/src/utils.rs b/src/utils.rs index d9ed4ab..f9e6a74 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,7 +1,6 @@ //! Async [`TempDir`] for testing. use crate::error::Error; -use async_trait::async_trait; use base64::{self, encode_config}; use ring::rand::{SecureRandom, SystemRandom}; use std::{fs as fsstd, path::PathBuf}; @@ -13,14 +12,8 @@ pub struct TempDir(pub PathBuf); /// Implemented to create a temporary directory with a random 8 byte /// base64 url string as a name. Drop implemented to remove directory /// when [`TempDir`] goes out of scope. -#[async_trait] -pub trait TempFrom { - async fn from_str(path_str: &str) -> Result; -} - -#[async_trait] -impl TempFrom for TempDir { - async fn from_str(path_str: &str) -> Result { +impl TempDir { + pub async fn from_str(path_str: &str) -> Result { if path_str.chars().last().unwrap() != '/' { return Err(Error::MissingTrailingSlash); } diff --git a/tests/integration.rs b/tests/integration.rs index 5aff5ca..987e115 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -4,7 +4,7 @@ use arloader::{ status::{OutputFormat, OutputHeader, Status, StatusCode}, transaction::{Base64, Tag}, upload_files_stream, - utils::{TempDir, TempFrom}, + utils::TempDir, Arweave, }; use futures::{future::try_join_all, StreamExt};