Skip to content

Commit

Permalink
chore: polishes
Browse files Browse the repository at this point in the history
  • Loading branch information
grumbach committed Oct 2, 2024
1 parent 37c9a7a commit 6ac576a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 28 deletions.
2 changes: 1 addition & 1 deletion autonomi/src/client/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl Client {
}

let cost_map = self.get_store_quotes(content_addrs.into_iter()).await?;
let total_cost = AttoTokens::from_atto(cost_map.iter().map(|(_, quote)| quote.2.cost.as_atto()).sum::<Amount>());
let total_cost = AttoTokens::from_atto(cost_map.values().map(|quote| quote.2.cost.as_atto()).sum::<Amount>());
Ok(total_cost)
}

Expand Down
8 changes: 4 additions & 4 deletions autonomi_cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ pub async fn handle_subcommand(opt: Opt) -> Result<()> {
FileCmd::List => file::list(peers),
},
SubCmd::Register { command } => match command {
RegisterCmd::Cost { name } => register::cost(&name, peers).await,
RegisterCmd::Create { name, value } => register::create(&name, &value, peers).await,
RegisterCmd::Edit { name, value } => register::edit(&name, &value, peers).await,
RegisterCmd::Get { name } => register::get(&name, peers).await,
RegisterCmd::Cost { name } => register::cost(&name, peers),
RegisterCmd::Create { name, value } => register::create(&name, &value, peers),
RegisterCmd::Edit { name, value } => register::edit(&name, &value, peers),
RegisterCmd::Get { name } => register::get(&name, peers),
RegisterCmd::List => register::list(peers),
},
SubCmd::Vault { command } => match command {
Expand Down
2 changes: 1 addition & 1 deletion autonomi_cli/src/commands/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ pub async fn download(addr: &str, dest_path: &str, peers: Vec<Multiaddr>) -> Res
}

pub fn list(_peers: Vec<Multiaddr>) -> Result<()> {
println!("Listing previous uploads...");
println!("The file list feature is coming soon!");
Ok(())
}
30 changes: 14 additions & 16 deletions autonomi_cli/src/commands/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,37 @@ use autonomi::Multiaddr;
use color_eyre::eyre::Context;
use color_eyre::eyre::Result;

pub async fn cost(name: &str, _peers: Vec<Multiaddr>) -> Result<()> {
let register_key = crate::utils::get_register_signing_key()
pub fn cost(_name: &str, _peers: Vec<Multiaddr>) -> Result<()> {
let _register_key = crate::utils::get_register_signing_key()
.wrap_err("The register key is required to perform this action")?;
println!("Estimate cost to register name: {name} with register key: {register_key}");
println!("The register feature is coming soon!");
Ok(())
}

pub async fn create(name: &str, value: &str, _peers: Vec<Multiaddr>) -> Result<()> {
let secret_key = crate::utils::get_secret_key()
pub fn create(_name: &str, _value: &str, _peers: Vec<Multiaddr>) -> Result<()> {
let _secret_key = crate::utils::get_secret_key()
.wrap_err("The secret key is required to perform this action")?;
let register_key = crate::utils::get_register_signing_key()
let _register_key = crate::utils::get_register_signing_key()
.wrap_err("The register key is required to perform this action")?;
println!(
"Creating register: {name} with value: {value} using secret key: {secret_key} and register key: {register_key}"
);
println!("The register feature is coming soon!");
Ok(())
}

pub async fn edit(name: &str, value: &str, _peers: Vec<Multiaddr>) -> Result<()> {
let register_key = crate::utils::get_register_signing_key()
pub fn edit(_name: &str, _value: &str, _peers: Vec<Multiaddr>) -> Result<()> {
let _register_key = crate::utils::get_register_signing_key()
.wrap_err("The register key is required to perform this action")?;
println!("Editing register: {name} with value: {value} using register key: {register_key}");
println!("The register feature is coming soon!");
Ok(())
}

pub async fn get(name: &str, _peers: Vec<Multiaddr>) -> Result<()> {
let register_key = crate::utils::get_register_signing_key()
pub fn get(_name: &str, _peers: Vec<Multiaddr>) -> Result<()> {
let _register_key = crate::utils::get_register_signing_key()
.wrap_err("The register key is required to perform this action")?;
println!("Getting value of register: {name} with register key: {register_key}");
println!("The register feature is coming soon!");
Ok(())
}

pub fn list(_peers: Vec<Multiaddr>) -> Result<()> {
println!("Listing previous registers...");
println!("The register feature is coming soon!");
Ok(())
}
10 changes: 5 additions & 5 deletions autonomi_cli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn get_secret_key() -> Result<String> {
// load the key from file
let key_path = dir.join(SECRET_KEY_FILE);
fs::read_to_string(&key_path)
.wrap_err("Failed to read secret key from file".to_string())
.wrap_err("Failed to read secret key from file")
.with_suggestion(|| format!("make sure you've provided the {SECRET_KEY} env var or have the key in a file at {key_path:?}"))
}

Expand All @@ -63,7 +63,7 @@ pub fn get_register_signing_key() -> Result<String> {
// load the key from file
let key_path = dir.join(REGISTER_SIGNING_KEY_FILE);
fs::read_to_string(&key_path)
.wrap_err("Failed to read secret key from file".to_string())
.wrap_err("Failed to read secret key from file")
.with_suggestion(|| format!("make sure you've provided the {REGISTER_SIGNING_KEY} env var or have the key in a file at {key_path:?}"))
}

Expand All @@ -73,15 +73,15 @@ pub fn get_client_data_dir_path() -> Result<PathBuf> {
home_dirs.push("safe");
home_dirs.push("client");
std::fs::create_dir_all(home_dirs.as_path())
.wrap_err("Failed to create data dir".to_string())?;
.wrap_err("Failed to create data dir")?;
Ok(home_dirs)
}

pub async fn get_peers(peers: PeersArgs) -> Result<Vec<Multiaddr>> {
peers.get_peers().await
.wrap_err(format!("Please provide valid Network peers to connect to"))
.wrap_err("Please provide valid Network peers to connect to")
.with_suggestion(|| format!("make sure you've provided network peers using the --peers option or the {SAFE_PEERS_ENV} env var"))
.with_suggestion(|| format!("a peer address looks like this: /ip4/42.42.42.42/udp/4242/quic-v1/p2p/B64nodePeerIDvdjb3FAJF4ks3moreBase64CharsHere"))
.with_suggestion(|| "a peer address looks like this: /ip4/42.42.42.42/udp/4242/quic-v1/p2p/B64nodePeerIDvdjb3FAJF4ks3moreBase64CharsHere")
}

pub(crate) fn get_evm_network() -> Result<Network> {
Expand Down
1 change: 0 additions & 1 deletion evmlib/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ pub async fn pay_for_quotes<T: IntoIterator<Item = QuotePayment>>(
mod tests {
use crate::common::Amount;
use crate::testnet::Testnet;
use crate::utils::dummy_address;
use crate::wallet::{from_private_key, Wallet};
use alloy::network::{Ethereum, EthereumWallet, NetworkWallet};
use alloy::primitives::address;
Expand Down

0 comments on commit 6ac576a

Please sign in to comment.