Skip to content

Commit

Permalink
handle unspecified response status in get_status
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebEverett committed Mar 8, 2022
2 parents 2241220 + a3a2b99 commit c2c0c48
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ All notable changes starting with v0.1.34 to this project will be documented in
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

# v0.1.60 (2022-03-08)
- **changed:** `get_status` no longer panics on unspecified arweave response status, but instead returns and error containing the unspecified status.

# v0.1.59 (2022-02-26)
- **added:** add logic to retry uploading chunks until they receive a status 200 response.
- **changed:** increase upload buffer size to 5 now that chunks are retried if not 200 response.
Expand Down
45 changes: 45 additions & 0 deletions examples/create_tx.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use arloader::Arweave;
use std::{path::PathBuf, time::Instant};

fn is_valid_file_path(path_str: &str) -> Result<(), String> {
match path_str.parse::<PathBuf>() {
Ok(p) => {
if p.exists() {
if p.is_file() {
Ok(())
} else {
return Err("Path is not file.".to_string());
}
} else {
return Err("Path does not exist.".to_string());
}
}
Err(_) => return Err("Not a valid path.".to_string()),
}
}

#[tokio::main]
async fn main() -> Result<(), String> {
let args: Vec<String> = std::env::args().collect();
let arweave = Arweave::default();

println!("{:?}", args);

if args.len() != 2 {
return Err("must provide exactly one existing file path argument".to_string());
}
is_valid_file_path(&args[1]).unwrap();

let bytes = tokio::fs::read(args[1].clone()).await.unwrap();

let start = Instant::now();
arweave
.create_transaction(bytes, None, None, (0, 0), true)
.await
.unwrap();
let duration = start.elapsed();

println!("Transaction created in: {:?}", duration);

Ok(())
}
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub enum Error {
ArweaveGetPriceError(reqwest::Error),
#[error("error posting arweave transaction: {0}")]
ArweavePostError(reqwest::Error),
#[error("Arweave network error: {0}")]
ArweaveNetworkError(reqwest::StatusCode),
#[error("avro deserialize: {0}")]
AvroDeError(#[from] avro_rs::DeError),
#[error("base64 decode: {0}")]
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,9 @@ impl Arweave {
ResponseStatusCode::NOT_FOUND => {
status.status = StatusCode::NotFound;
}
_ => unreachable!(),
other_status => {
return Err(Error::ArweaveNetworkError(other_status));
}
}
Ok(status)
}
Expand Down

0 comments on commit c2c0c48

Please sign in to comment.