Skip to content

Commit

Permalink
readme nits
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebEverett committed Nov 20, 2021
1 parent dbc1ac2 commit 4a29c6f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "arloader"
authors = ["calebeverett <[email protected]>"]
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"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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.
32 changes: 20 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,6 @@ impl Arweave {
&self,
paths_iter: IP,
tags: Vec<Tag<String>>,
log_dir: Option<PathBuf>,
price_terms: (u64, u64),
) -> Result<(Transaction, Value), Error>
where
Expand Down Expand Up @@ -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> {
Expand Down Expand Up @@ -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",
Expand All @@ -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(())
}
Expand Down
22 changes: 6 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand All @@ -777,8 +772,8 @@ async fn command_upload_bundle(
id
);
println!(
"\nFiles will be available at https://arweave.net/<bundle_item_id> once the bundle transaction has been confirmed.
\nThey will also be available at https://arweave.net/{manifest_id}/<file_path>.
"\nFiles will be available at https://arweave.net/<BUNDLE_ITEM_ID> once the bundle transaction has been confirmed.
\nThey will also be available at https://arweave.net/{manifest_id}/<FILE_PATH>.
\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()
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -907,8 +897,8 @@ async fn command_upload_bundle_with_sol(
id
);
println!(
"\nFiles will be available at https://arweave.net/<bundle_item_id> once the bundle transaction has been confirmed.
\nThey will also be available at https://arweave.net/{manifest_id}/<file_path>.
"\nFiles will be available at https://arweave.net/<BUNDLE_ITEM_ID> once the bundle transaction has been confirmed.
\nThey will also be available at https://arweave.net/{manifest_id}/<FILE_PATH>.
\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()
)
Expand Down
11 changes: 2 additions & 9 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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<T> {
async fn from_str(path_str: &str) -> Result<T, Error>;
}

#[async_trait]
impl TempFrom<TempDir> for TempDir {
async fn from_str(path_str: &str) -> Result<Self, Error> {
impl TempDir {
pub async fn from_str(path_str: &str) -> Result<Self, Error> {
if path_str.chars().last().unwrap() != '/' {
return Err(Error::MissingTrailingSlash);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down

0 comments on commit 4a29c6f

Please sign in to comment.