Skip to content

Commit

Permalink
Merge pull request #35 from Bundlr-Network/fix/update-dependencies
Browse files Browse the repository at this point in the history
fix - update dependencies
  • Loading branch information
mikonieminen authored Sep 25, 2023
2 parents 0a1b2c0 + b1a3109 commit 43dad5f
Show file tree
Hide file tree
Showing 15 changed files with 657 additions and 900 deletions.
1,351 changes: 578 additions & 773 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ async-recursion = "0.3.2"
async-stream = "0.3.2"
async-trait = "0.1.57"
avro-rs = "0.13.0"
arweave-rs = { version = "0.1.2", optional = true }
arweave-rs = { version = "0.2.0", optional = true }
bs58 = "0.4.0"
bytes = "1.1.0"
clap = { version = "3.1.2", features = ["derive", "env"], optional = true }
clap = { version = "4.4.4", features = ["derive", "env"], optional = true }
data-encoding = "2.3.2"
derive_builder = "0.10.2"
derive_more = "0.99.17"
Expand All @@ -34,7 +34,7 @@ pipe = "0.4.0"
primitive-types = "0.11.1"
rand = "0.8.5"
regex = "1.8.1"
reqwest = { version = "0.11.11", default-features = false, features = ["hyper-rustls", "tokio-rustls", "json"] }
reqwest = { version = "0.11.20", default-features = false, features = ["rustls-tls", "json"] }
ring = "0.16.20"
rustc-hex = "2.1.0"
secp256k1 = { version = "0.22.1", optional = true, features = [ "recovery" ] }
Expand All @@ -47,7 +47,7 @@ thiserror = "1.0.30"
tokio = { version = "1.14.0", features = [ "fs" ]}
tokio-util = "0.6.9"
validator = { version = "0.16", features = ["derive"] }
web3 = { version = "0.18.0", optional = true }
web3 = { version = "0.19.0", optional = true, default-features = false, features = ["http-rustls-tls", "signing"]}

[dev-dependencies]
tokio-test = "0.4.2"
Expand Down
8 changes: 2 additions & 6 deletions examples/fund.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use std::{path::PathBuf, str::FromStr};

use bundlr_sdk::{
bundlr::BundlrBuilder,
currency::arweave::{Arweave, ArweaveBuilder},
error::BundlrError,
};
use bundlr_sdk::{bundlr::BundlrBuilder, currency::arweave::ArweaveBuilder, error::BundlrError};
use reqwest::Url;

#[tokio::main]
Expand All @@ -15,7 +11,7 @@ async fn main() -> Result<(), BundlrError> {
.keypair_path(wallet)
.build()
.expect("Could not create currency instance");
let bundlr = BundlrBuilder::<Arweave>::new()
let bundlr = BundlrBuilder::new()
.url(url)
.currency(currency)
.fetch_pub_info()
Expand Down
8 changes: 2 additions & 6 deletions examples/upload.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use std::{path::PathBuf, str::FromStr};

use bundlr_sdk::{
bundlr::BundlrBuilder,
currency::solana::{Solana, SolanaBuilder},
error::BundlrError,
};
use bundlr_sdk::{bundlr::BundlrBuilder, currency::solana::SolanaBuilder, error::BundlrError};
use reqwest::Url;

#[tokio::main]
Expand All @@ -14,7 +10,7 @@ async fn main() -> Result<(), BundlrError> {
"kNykCXNxgePDjFbDWjPNvXQRa8U12Ywc19dFVaQ7tebUj3m7H4sF4KKdJwM7yxxb3rqxchdjezX9Szh8bLcQAjb")
.build()
.expect("Could not create Solana instance");
let mut bundlr = BundlrBuilder::<Solana>::new()
let mut bundlr = BundlrBuilder::new()
.url(url)
.currency(currency)
.fetch_pub_info()
Expand Down
8 changes: 2 additions & 6 deletions examples/withdraw.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use std::{path::PathBuf, str::FromStr};

use bundlr_sdk::{
bundlr::BundlrBuilder,
currency::arweave::{Arweave, ArweaveBuilder},
error::BundlrError,
};
use bundlr_sdk::{bundlr::BundlrBuilder, currency::arweave::ArweaveBuilder, error::BundlrError};
use reqwest::Url;

#[tokio::main]
Expand All @@ -15,7 +11,7 @@ async fn main() -> Result<(), BundlrError> {
.keypair_path(wallet)
.build()
.expect("Could not create currency instance");
let bundlr = BundlrBuilder::<Arweave>::new()
let bundlr = BundlrBuilder::new()
.url(url)
.currency(currency)
.fetch_pub_info()
Expand Down
90 changes: 39 additions & 51 deletions src/bundlr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,34 +59,25 @@ pub struct WithdrawBody {

#[derive(Default)]

pub struct BundlrBuilder<Currency>
where
Currency: currency::Currency,
{
pub struct BundlrBuilder<Currency = ()> {
url: Option<Url>,
currency: Option<Currency>,
currency: Currency,
client: Option<reqwest::Client>,
pub_info: Option<PubInfo>,
}

impl<Currency> BundlrBuilder<Currency>
where
Currency: currency::Currency + Default,
{
pub fn new() -> BundlrBuilder<Currency> {
impl BundlrBuilder {
pub fn new() -> BundlrBuilder {
Default::default()
}
}

impl<Currency> BundlrBuilder<Currency> {
pub fn url(mut self, url: Url) -> BundlrBuilder<Currency> {
self.url = Some(url);
self
}

pub fn currency(mut self, currency: Currency) -> BundlrBuilder<Currency> {
self.currency = Some(currency);
self
}

pub fn client(mut self, client: reqwest::Client) -> BundlrBuilder<Currency> {
self.client = Some(client);
self
Expand All @@ -111,13 +102,28 @@ where
self.pub_info = Some(pub_info);
self
}
}

impl BundlrBuilder<()> {
pub fn currency<Currency>(self, currency: Currency) -> BundlrBuilder<Currency>
where
Currency: currency::Currency,
{
BundlrBuilder {
currency,
url: self.url,
client: self.client,
pub_info: self.pub_info,
}
}
}

impl<Currency> BundlrBuilder<Currency>
where
Currency: currency::Currency,
{
pub fn build(self) -> Result<Bundlr<Currency>, BuilderError> {
let url = self.url.unwrap_or(Url::parse(BUNDLR_DEFAULT_URL).unwrap());
let currency = match self.currency {
Some(c) => c,
None => return Err(BuilderError::MissingField("currency".to_owned())),
};

let client = self.client.unwrap_or_else(reqwest::Client::new);

Expand All @@ -126,11 +132,11 @@ where
None => return Err(BuilderError::MissingField("currency".to_owned())),
};

let uploader = Uploader::new(url.clone(), client.clone(), currency.get_type());
let uploader = Uploader::new(url.clone(), client.clone(), self.currency.get_type());

Ok(Bundlr {
url,
currency,
currency: self.currency,
client,
pub_info,
uploader,
Expand Down Expand Up @@ -232,10 +238,7 @@ where
/// # use bundlr_sdk::{
/// # currency::CurrencyType,
/// # BundlrBuilder,
/// # currency::arweave::{
/// # Arweave,
/// # ArweaveBuilder
/// # },
/// # currency::arweave::ArweaveBuilder,
/// # tags::Tag,
/// # error::BuilderError
/// # };
Expand All @@ -249,7 +252,7 @@ where
/// # .keypair_path(wallet)
/// # .build()
/// # .expect("Could not create currency instance");
/// # let mut bundlr = BundlrBuilder::<Arweave>::new()
/// # let mut bundlr = BundlrBuilder::new()
/// # .url(url)
/// # .currency(currency)
/// # .fetch_pub_info()
Expand Down Expand Up @@ -277,10 +280,7 @@ where
/// # use bundlr_sdk::{
/// # currency::CurrencyType,
/// # BundlrBuilder,
/// # currency::arweave::{
/// # Arweave,
/// # ArweaveBuilder
/// # },
/// # currency::arweave::ArweaveBuilder,
/// # tags::Tag,
/// # error::BuilderError
/// # };
Expand All @@ -294,7 +294,7 @@ where
/// # .keypair_path(wallet)
/// # .build()
/// # .expect("Could not create currency instance");
/// # let mut bundlr = BundlrBuilder::<Arweave>::new()
/// # let mut bundlr = BundlrBuilder::new()
/// # .url(url)
/// # .currency(currency)
/// # .fetch_pub_info()
Expand All @@ -321,10 +321,7 @@ where
/// # use bundlr_sdk::{
/// # currency::CurrencyType,
/// # BundlrBuilder,
/// # currency::arweave::{
/// # Arweave,
/// # ArweaveBuilder
/// # },
/// # currency::arweave::ArweaveBuilder,
/// # tags::Tag,
/// # error::BuilderError
/// # };
Expand All @@ -338,7 +335,7 @@ where
/// # .keypair_path(wallet)
/// # .build()
/// # .expect("Could not create currency instance");
/// # let mut bundlr = BundlrBuilder::<Arweave>::new()
/// # let mut bundlr = BundlrBuilder::new()
/// # .url(url)
/// # .currency(currency)
/// # .fetch_pub_info()
Expand Down Expand Up @@ -379,10 +376,7 @@ where
/// # use bundlr_sdk::{
/// # currency::CurrencyType,
/// # BundlrBuilder,
/// # currency::arweave::{
/// # Arweave,
/// # ArweaveBuilder
/// # },
/// # currency::arweave::ArweaveBuilder,
/// # tags::Tag,
/// # error::BuilderError
/// # };
Expand All @@ -396,7 +390,7 @@ where
/// # .keypair_path(wallet)
/// # .build()
/// # .expect("Could not create currency instance");
/// # let bundlr = BundlrBuilder::<Arweave>::new()
/// # let bundlr = BundlrBuilder::new()
/// # .url(url)
/// # .currency(currency)
/// # .fetch_pub_info()
Expand Down Expand Up @@ -444,10 +438,7 @@ where
/// # use bundlr_sdk::{
/// # currency::CurrencyType,
/// # BundlrBuilder,
/// # currency::arweave::{
/// # Arweave,
/// # ArweaveBuilder
/// # },
/// # currency::arweave::ArweaveBuilder,
/// # tags::Tag,
/// # error::BuilderError
/// # };
Expand All @@ -461,7 +452,7 @@ where
/// # .keypair_path(wallet)
/// # .build()
/// # .expect("Could not create currency instance");
/// # let bundlr = BundlrBuilder::<Arweave>::new()
/// # let bundlr = BundlrBuilder::new()
/// # .url(url)
/// # .currency(currency)
/// # .fetch_pub_info()
Expand Down Expand Up @@ -523,10 +514,7 @@ where
/// # use bundlr_sdk::{
/// # currency::CurrencyType,
/// # BundlrBuilder,
/// # currency::arweave::{
/// # Arweave,
/// # ArweaveBuilder
/// # },
/// # currency::arweave::ArweaveBuilder,
/// # tags::Tag,
/// # error::BuilderError
/// # };
Expand All @@ -540,7 +528,7 @@ where
/// # .keypair_path(wallet)
/// # .build()
/// # .expect("Could not create currency instance");
/// # let mut bundlr = BundlrBuilder::<Arweave>::new()
/// # let mut bundlr = BundlrBuilder::new()
/// # .url(url)
/// # .currency(currency)
/// # .fetch_pub_info()
Expand Down
2 changes: 1 addition & 1 deletion src/client/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub async fn run_balance(
currency: CurrencyType,
) -> Result<String, BundlrError> {
let client = reqwest::Client::new();
get_balance(&url, currency, &address, &client)
get_balance(&url, currency, address, &client)
.await
.map(|balance| balance.to_string())
}
10 changes: 5 additions & 5 deletions src/client/bin/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl Command {
Ok(ok) => println!("[Ok] {}", ok),
Err(err) => println!("[Err] {}", err),
},
Err(err) => println!("Error running task: {}", err.to_string()),
Err(err) => println!("Error running task: {}", err),
}
}
Command::Fund {
Expand All @@ -160,7 +160,7 @@ impl Command {
Ok(ok) => println!("[Ok] {}", ok),
Err(err) => println!("[Err] {}", err),
},
Err(err) => println!("Error running task: {}", err.to_string()),
Err(err) => println!("Error running task: {}", err),
}
}
Command::Withdraw {
Expand All @@ -177,7 +177,7 @@ impl Command {
Ok(ok) => println!("[Ok] {}", ok),
Err(err) => println!("[Err] {}", err),
},
Err(err) => println!("Error running task: {}", err.to_string()),
Err(err) => println!("Error running task: {}", err),
}
}
Command::Upload {
Expand All @@ -194,7 +194,7 @@ impl Command {
Ok(ok) => println!("[Ok] {}", ok),
Err(err) => println!("[Err] {}", err),
},
Err(err) => println!("Error running task: {}", err.to_string()),
Err(err) => println!("Error running task: {}", err),
}
}
Command::UploadDir {} => todo!(),
Expand All @@ -212,7 +212,7 @@ impl Command {
Ok(ok) => println!("[Ok] {}", ok),
Err(err) => println!("[Err] {}", err),
},
Err(err) => println!("Error running task: {}", err.to_string()),
Err(err) => println!("Error running task: {}", err),
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/client/fund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use std::{path::PathBuf, str::FromStr};
use crate::{
bundlr::BundlrBuilder,
consts::USE_JS_SDK,
currency::{
arweave::{Arweave, ArweaveBuilder},
CurrencyType,
},
currency::{arweave::ArweaveBuilder, CurrencyType},
error::BundlrError,
};
use num_traits::Zero;
Expand All @@ -26,7 +23,7 @@ pub async fn run_fund(
match currency {
CurrencyType::Arweave => {
let currency = ArweaveBuilder::new().keypair_path(wallet).build()?;
let bundlr = BundlrBuilder::<Arweave>::new()
let bundlr = BundlrBuilder::new()
.url(url)
.currency(currency)
.fetch_pub_info()
Expand Down
4 changes: 1 addition & 3 deletions src/client/price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ pub async fn run_price(
.map(|balance| {
format!(
"{} bytes in {} is {} base units", //TODO: refactor this to show base unit name
byte_amount,
currency,
balance.to_string(),
byte_amount, currency, balance,
)
})
}
Loading

0 comments on commit 43dad5f

Please sign in to comment.