From b8b158acbcbc0daf91398b064d687316ffff234f Mon Sep 17 00:00:00 2001 From: grumbach Date: Thu, 6 Feb 2025 14:44:59 +0900 Subject: [PATCH] feat: API cleanup for release --- ant-cli/src/actions/download.rs | 8 +-- ant-cli/src/commands/file.rs | 4 +- ant-node/src/put_validation.rs | 10 ++-- ant-node/tests/data_with_churn.rs | 10 ++-- ant-protocol/src/storage/chunks.rs | 7 ++- ant-protocol/src/storage/pointer.rs | 10 ++-- ant-protocol/src/storage/scratchpad.rs | 4 +- autonomi/examples/data_and_archive.rs | 11 ++-- autonomi/examples/put_and_dir_upload.rs | 8 +-- autonomi/src/client/data_types/chunk.rs | 9 ++-- autonomi/src/client/data_types/graph.rs | 4 +- autonomi/src/client/data_types/pointer.rs | 13 ++--- autonomi/src/client/data_types/scratchpad.rs | 6 +-- .../src/client/high_level/data/private.rs | 31 ++++++----- autonomi/src/client/high_level/data/public.rs | 27 +++++----- .../high_level/files/archive_private.rs | 5 +- .../client/high_level/files/archive_public.rs | 12 ++--- .../src/client/high_level/files/fs_private.rs | 49 ++++++++++------- .../src/client/high_level/files/fs_public.rs | 53 +++++++++++-------- autonomi/src/client/high_level/files/mod.rs | 3 ++ .../src/client/high_level/register/mod.rs | 11 ++-- autonomi/src/client/high_level/vault/mod.rs | 4 +- autonomi/src/lib.rs | 7 --- autonomi/src/python.rs | 38 ++++++++----- autonomi/src/self_encryption.rs | 2 +- autonomi/tests/chunk.rs | 2 +- autonomi/tests/external_signer.rs | 19 ++++--- autonomi/tests/fs.rs | 8 +-- autonomi/tests/graph.rs | 4 +- autonomi/tests/pointer.rs | 12 ++--- autonomi/tests/put.rs | 4 +- 31 files changed, 218 insertions(+), 177 deletions(-) diff --git a/ant-cli/src/actions/download.rs b/ant-cli/src/actions/download.rs index cb9826398f..758c2ba7a4 100644 --- a/ant-cli/src/actions/download.rs +++ b/ant-cli/src/actions/download.rs @@ -43,7 +43,7 @@ async fn download_private( client: &Client, ) -> Result<()> { let archive = client - .archive_get(private_address) + .archive_get(&private_address) .await .wrap_err("Failed to fetch data from address")?; @@ -51,7 +51,7 @@ async fn download_private( let mut all_errs = vec![]; for (path, access, _meta) in archive.iter() { progress_bar.println(format!("Fetching file: {path:?}...")); - let bytes = match client.data_get(access.clone()).await { + let bytes = match client.data_get(access).await { Ok(bytes) => bytes, Err(e) => { let err = format!("Failed to fetch file {path:?}: {e}"); @@ -89,7 +89,7 @@ async fn download_public( client: &Client, ) -> Result<()> { let archive = client - .archive_get_public(address) + .archive_get_public(&address) .await .wrap_err("Failed to fetch data from address")?; @@ -97,7 +97,7 @@ async fn download_public( let mut all_errs = vec![]; for (path, addr, _meta) in archive.iter() { progress_bar.println(format!("Fetching file: {path:?}...")); - let bytes = match client.data_get_public(*addr).await { + let bytes = match client.data_get_public(addr).await { Ok(bytes) => bytes, Err(e) => { let err = format!("Failed to fetch file {path:?}: {e}"); diff --git a/ant-cli/src/commands/file.rs b/ant-cli/src/commands/file.rs index c250e6c7fb..d9f52c6a13 100644 --- a/ant-cli/src/commands/file.rs +++ b/ant-cli/src/commands/file.rs @@ -64,14 +64,14 @@ pub async fn upload( // upload dir let local_addr; let archive = if public { - let xor_name = client + let (_cost, xor_name) = client .dir_and_archive_upload_public(dir_path, &wallet) .await .wrap_err("Failed to upload file")?; local_addr = addr_to_str(xor_name); local_addr.clone() } else { - let private_data_access = client + let (_cost, private_data_access) = client .dir_and_archive_upload(dir_path, &wallet) .await .wrap_err("Failed to upload dir and archive")?; diff --git a/ant-node/src/put_validation.rs b/ant-node/src/put_validation.rs index 679087c3ed..ef368edc2f 100644 --- a/ant-node/src/put_validation.rs +++ b/ant-node/src/put_validation.rs @@ -251,14 +251,14 @@ impl Node { } RecordKind::DataOnly(DataTypes::Pointer) => { let pointer = try_deserialize_record::(&record)?; - let net_addr = NetworkAddress::from_pointer_address(pointer.network_address()); + let net_addr = NetworkAddress::from_pointer_address(pointer.address()); let pretty_key = PrettyPrintRecordKey::from(&record.key); let already_exists = self .validate_key_and_existence(&net_addr, &record.key) .await?; if !already_exists { - warn!("Pointer at address: {:?}, key: {:?} does not exist locally, rejecting PUT without payment", pointer.network_address(), pretty_key); + warn!("Pointer at address: {:?}, key: {:?} does not exist locally, rejecting PUT without payment", pointer.address(), pretty_key); return Err(Error::InvalidPutWithoutPayment( PrettyPrintRecordKey::from(&record.key).into_owned(), )); @@ -283,7 +283,7 @@ impl Node { let (payment, pointer) = try_deserialize_record::<(ProofOfPayment, Pointer)>(&record)?; - let net_addr = NetworkAddress::from_pointer_address(pointer.network_address()); + let net_addr = NetworkAddress::from_pointer_address(pointer.address()); let pretty_key = PrettyPrintRecordKey::from(&record.key); let already_exists = self .validate_key_and_existence(&net_addr, &record.key) @@ -797,14 +797,14 @@ impl Node { } // Check if the pointer's address matches the record key - let net_addr = NetworkAddress::from_pointer_address(pointer.network_address()); + let net_addr = NetworkAddress::from_pointer_address(pointer.address()); if key != net_addr.to_record_key() { warn!("Pointer address does not match record key"); return Err(Error::RecordKeyMismatch); } // Keep the pointer with the highest counter - if let Some(local_pointer) = self.get_local_pointer(pointer.network_address()).await { + if let Some(local_pointer) = self.get_local_pointer(pointer.address()).await { if pointer.counter() <= local_pointer.counter() { info!( "Ignoring Pointer PUT at {key:?} with counter less than or equal to the current counter ({} <= {})", diff --git a/ant-node/tests/data_with_churn.rs b/ant-node/tests/data_with_churn.rs index 1fa3b2b28c..9e6871df99 100644 --- a/ant-node/tests/data_with_churn.rs +++ b/ant-node/tests/data_with_churn.rs @@ -447,7 +447,7 @@ fn create_graph_entry_task( let mut retries = 1; loop { - match client.graph_entry_get(*addr).await { + match client.graph_entry_get(addr).await { Ok(graph_entry) => { println!("Fetched graph_entry at {addr:?}"); @@ -683,7 +683,7 @@ fn store_chunks_task( println!("Error to put chunk: {err:?}"); error!("Error to put chunk: {err:?}") }) { - Ok(data_map) => { + Ok((_cost, data_map)) => { println!("Stored Chunk/s at {data_map:?} after a delay of: {delay:?}"); info!("Stored Chunk/s at {data_map:?} after a delay of: {delay:?}"); @@ -872,15 +872,15 @@ async fn final_retry_query_content( async fn query_content(client: &Client, net_addr: &NetworkAddress) -> Result<()> { match net_addr { NetworkAddress::ChunkAddress(addr) => { - client.data_get_public(*addr.xorname()).await?; + client.data_get_public(addr.xorname()).await?; Ok(()) } NetworkAddress::PointerAddress(addr) => { - let _ = client.pointer_get(*addr).await?; + let _ = client.pointer_get(addr).await?; Ok(()) } NetworkAddress::GraphEntryAddress(addr) => { - let _ = client.graph_entry_get(*addr).await?; + let _ = client.graph_entry_get(addr).await?; Ok(()) } NetworkAddress::ScratchpadAddress(addr) => { diff --git a/ant-protocol/src/storage/chunks.rs b/ant-protocol/src/storage/chunks.rs index 2b1926fab2..a97ce92937 100644 --- a/ant-protocol/src/storage/chunks.rs +++ b/ant-protocol/src/storage/chunks.rs @@ -57,9 +57,14 @@ impl Chunk { } /// Returns size of this chunk after serialisation. - pub fn serialised_size(&self) -> usize { + pub fn size(&self) -> usize { self.value.len() } + + /// Returns true if the chunk is too big + pub fn is_too_big(&self) -> bool { + self.size() > Self::DEFAULT_MAX_SIZE + } } impl Serialize for Chunk { diff --git a/ant-protocol/src/storage/pointer.rs b/ant-protocol/src/storage/pointer.rs index 995d15fbb2..31730126e8 100644 --- a/ant-protocol/src/storage/pointer.rs +++ b/ant-protocol/src/storage/pointer.rs @@ -91,6 +91,11 @@ impl Pointer { PointerAddress::from_owner(self.owner) } + /// Get the owner of the pointer + pub fn owner(&self) -> &PublicKey { + &self.owner + } + /// Get the target of the pointer pub fn target(&self) -> &PointerTarget { &self.target @@ -111,11 +116,6 @@ impl Pointer { self.counter } - /// Get the network address for this pointer - pub fn network_address(&self) -> PointerAddress { - PointerAddress::from_owner(self.owner) - } - /// Verifies if the pointer has a valid signature pub fn verify_signature(&self) -> bool { let bytes = self.bytes_for_signature(); diff --git a/ant-protocol/src/storage/scratchpad.rs b/ant-protocol/src/storage/scratchpad.rs index 1f818d12b5..e1e76f660c 100644 --- a/ant-protocol/src/storage/scratchpad.rs +++ b/ant-protocol/src/storage/scratchpad.rs @@ -156,12 +156,12 @@ impl Scratchpad { XorName::from_content(&self.encrypted_data) } - /// Returns the owner. + /// Returns the owner of the scratchpad pub fn owner(&self) -> &PublicKey { self.address.owner() } - /// Returns the address. + /// Returns the address of the scratchpad pub fn address(&self) -> &ScratchpadAddress { &self.address } diff --git a/autonomi/examples/data_and_archive.rs b/autonomi/examples/data_and_archive.rs index 07fddd560f..6072d563dd 100644 --- a/autonomi/examples/data_and_archive.rs +++ b/autonomi/examples/data_and_archive.rs @@ -1,4 +1,5 @@ -use autonomi::{Bytes, Client, Metadata, PrivateArchive}; +use autonomi::files::{Metadata, PrivateArchive}; +use autonomi::{Bytes, Client}; use test_utils::evm::get_funded_wallet; use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; @@ -14,8 +15,8 @@ async fn main() -> eyre::Result<()> { // Upload 10MiB of random data and verify it by fetching it back. let data = Bytes::from("Hello, World!"); - let data_map = client.data_put(data.clone(), (&wallet).into()).await?; - let data_fetched = client.data_get(data_map.clone()).await?; + let (_cost, data_map) = client.data_put(data.clone(), (&wallet).into()).await?; + let data_fetched = client.data_get(&data_map).await?; assert_eq!(data, data_fetched); // Upload the data as part of an archive, giving it the name `test.txt`. @@ -27,8 +28,8 @@ async fn main() -> eyre::Result<()> { ); // Upload the archive to the network. - let archive_data_map = client.archive_put(&archive, (&wallet).into()).await?; - let archive_fetched = client.archive_get(archive_data_map).await?; + let (_cost, archive_data_map) = client.archive_put(&archive, (&wallet).into()).await?; + let archive_fetched = client.archive_get(&archive_data_map).await?; assert_eq!(archive, archive_fetched); println!("Archive uploaded successfully"); diff --git a/autonomi/examples/put_and_dir_upload.rs b/autonomi/examples/put_and_dir_upload.rs index 4af5e20b11..55ede2d89a 100644 --- a/autonomi/examples/put_and_dir_upload.rs +++ b/autonomi/examples/put_and_dir_upload.rs @@ -13,17 +13,17 @@ async fn main() -> Result<(), Box> { let wallet = get_funded_wallet(); // Put and fetch data. - let data_addr = client + let (_cost, data_addr) = client .data_put_public(Bytes::from("Hello, World"), (&wallet).into()) .await?; - let _data_fetched = client.data_get_public(data_addr).await?; + let _data_fetched = client.data_get_public(&data_addr).await?; // Put and fetch directory from local file system. - let dir_addr = client + let (_cost, dir_addr) = client .dir_and_archive_upload_public("files/to/upload".into(), &wallet) .await?; client - .dir_download_public(dir_addr, "files/downloaded".into()) + .dir_download_public(&dir_addr, "files/downloaded".into()) .await?; Ok(()) diff --git a/autonomi/src/client/data_types/chunk.rs b/autonomi/src/client/data_types/chunk.rs index d5cc9615a0..06626599a2 100644 --- a/autonomi/src/client/data_types/chunk.rs +++ b/autonomi/src/client/data_types/chunk.rs @@ -71,6 +71,7 @@ pub static CHUNK_DOWNLOAD_BATCH_SIZE: LazyLock = LazyLock::new(|| { }); /// Private data on the network can be accessed with this +/// Uploading this data in a chunk makes it publicly accessible from the address of that Chunk #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct DataMapChunk(pub(crate) Chunk); @@ -105,10 +106,10 @@ fn hash_to_short_string(input: &str) -> String { impl Client { /// Get a chunk from the network. - pub async fn chunk_get(&self, addr: ChunkAddress) -> Result { + pub async fn chunk_get(&self, addr: &ChunkAddress) -> Result { info!("Getting chunk: {addr:?}"); - let key = NetworkAddress::from_chunk_address(addr).to_record_key(); + let key = NetworkAddress::from_chunk_address(*addr).to_record_key(); debug!("Fetching chunk from network at: {key:?}"); let get_cfg = self.config.chunks.get_cfg(); @@ -146,7 +147,7 @@ impl Client { let (payment_proofs, _skipped_payments) = self .pay_for_content_addrs( DataTypes::Chunk, - std::iter::once((xor_name, chunk.serialised_size())), + std::iter::once((xor_name, chunk.size())), payment_option, ) .await @@ -366,7 +367,7 @@ impl Client { for info in data_map.infos() { download_tasks.push(async move { match self - .chunk_get(ChunkAddress::new(info.dst_hash)) + .chunk_get(&ChunkAddress::new(info.dst_hash)) .await .inspect_err(|err| { error!( diff --git a/autonomi/src/client/data_types/graph.rs b/autonomi/src/client/data_types/graph.rs index 3f34fc94b9..f86c004022 100644 --- a/autonomi/src/client/data_types/graph.rs +++ b/autonomi/src/client/data_types/graph.rs @@ -54,9 +54,9 @@ impl Client { /// Fetches a GraphEntry from the network. pub async fn graph_entry_get( &self, - address: GraphEntryAddress, + address: &GraphEntryAddress, ) -> Result { - let key = NetworkAddress::from_graph_entry_address(address).to_record_key(); + let key = NetworkAddress::from_graph_entry_address(*address).to_record_key(); let get_cfg = self.config.graph_entry.get_cfg(); let record = self .network diff --git a/autonomi/src/client/data_types/pointer.rs b/autonomi/src/client/data_types/pointer.rs index 2aaa8a3eda..c074df242a 100644 --- a/autonomi/src/client/data_types/pointer.rs +++ b/autonomi/src/client/data_types/pointer.rs @@ -48,8 +48,8 @@ pub enum PointerError { impl Client { /// Get a pointer from the network - pub async fn pointer_get(&self, address: PointerAddress) -> Result { - let key = NetworkAddress::from_pointer_address(address).to_record_key(); + pub async fn pointer_get(&self, address: &PointerAddress) -> Result { + let key = NetworkAddress::from_pointer_address(*address).to_record_key(); debug!("Fetching pointer from network at: {key:?}"); let get_cfg = self.config.pointer.get_cfg(); @@ -117,7 +117,7 @@ impl Client { pointer: Pointer, payment_option: PaymentOption, ) -> Result<(AttoTokens, PointerAddress), PointerError> { - let address = pointer.network_address(); + let address = pointer.address(); // pay for the pointer storage let xor_name = *address.xorname(); @@ -203,13 +203,14 @@ impl Client { /// Update an existing pointer to point to a new target on the network /// The pointer needs to be created first with [`Client::pointer_put`] /// This operation is free as the pointer was already paid for at creation + /// Only the latest version of the pointer is kept on the Network, previous versions will be overwritten and unrecoverable pub async fn pointer_update( &self, owner: &SecretKey, target: PointerTarget, ) -> Result<(), PointerError> { let address = PointerAddress::from_owner(owner.public_key()); - let current = match self.pointer_get(address).await { + let current = match self.pointer_get(&address).await { Ok(pointer) => Some(pointer), Err(PointerError::Network(NetworkError::GetRecordError( GetRecordError::RecordNotFound, @@ -257,10 +258,10 @@ impl Client { } /// Calculate the cost of storing a pointer - pub async fn pointer_cost(&self, key: PublicKey) -> Result { + pub async fn pointer_cost(&self, key: &PublicKey) -> Result { trace!("Getting cost for pointer of {key:?}"); - let address = PointerAddress::from_owner(key); + let address = PointerAddress::from_owner(*key); let xor = *address.xorname(); let store_quote = self .get_store_quotes(DataTypes::Pointer, std::iter::once((xor, Pointer::size()))) diff --git a/autonomi/src/client/data_types/scratchpad.rs b/autonomi/src/client/data_types/scratchpad.rs index f66992973d..24709383dd 100644 --- a/autonomi/src/client/data_types/scratchpad.rs +++ b/autonomi/src/client/data_types/scratchpad.rs @@ -48,7 +48,7 @@ pub enum ScratchpadError { impl Client { /// Get Scratchpad from the Network - /// It is stored at the owner's public key + /// A Scratchpad is stored at the owner's public key so we can derive the address from it pub async fn scratchpad_get_from_public_key( &self, public_key: &PublicKey, @@ -58,7 +58,6 @@ impl Client { } /// Get Scratchpad from the Network - /// It is stored at the owner's public key pub async fn scratchpad_get( &self, address: &ScratchpadAddress, @@ -252,7 +251,8 @@ impl Client { } /// Update an existing scratchpad to the network - /// This operation is free but requires the scratchpad to be already created on the network + /// The scratchpad needs to be created first with [`Client::scratchpad_create`] + /// This operation is free as the scratchpad was already paid for at creation /// Only the latest version of the scratchpad is kept on the Network, previous versions will be overwritten and unrecoverable pub async fn scratchpad_update( &self, diff --git a/autonomi/src/client/high_level/data/private.rs b/autonomi/src/client/high_level/data/private.rs index a7be3a51d5..c2f4dfcbbe 100644 --- a/autonomi/src/client/high_level/data/private.rs +++ b/autonomi/src/client/high_level/data/private.rs @@ -6,15 +6,17 @@ // KIND, either express or implied. Please review the Licences for the specific language governing // permissions and limitations relating to use of the SAFE Network Software. -use ant_evm::Amount; use ant_protocol::storage::DataTypes; -use bytes::Bytes; -use crate::client::data_types::chunk::DataMapChunk; use crate::client::payment::PaymentOption; use crate::client::{ClientEvent, GetError, PutError, UploadSummary}; +use crate::Amount; +use crate::AttoTokens; use crate::{self_encryption::encrypt, Client}; +pub use crate::client::data_types::chunk::DataMapChunk; +pub use crate::Bytes; + impl Client { /// Fetch a blob of (private) data from the network /// @@ -26,11 +28,11 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::init().await?; /// # let data_map = todo!(); - /// let data_fetched = client.data_get(data_map).await?; + /// let data_fetched = client.data_get(&data_map).await?; /// # Ok(()) /// # } /// ``` - pub async fn data_get(&self, data_map: DataMapChunk) -> Result { + pub async fn data_get(&self, data_map: &DataMapChunk) -> Result { info!( "Fetching private data from Data Map {:?}", data_map.0.address() @@ -55,7 +57,7 @@ impl Client { /// # let client = Client::init().await?; /// # let wallet = todo!(); /// let data = Bytes::from("Hello, World"); - /// let data_map = client.data_put(data, wallet).await?; + /// let (total_cost, data_map) = client.data_put(data, wallet).await?; /// let data_fetched = client.data_get(data_map).await?; /// assert_eq!(data, data_fetched); /// # Ok(()) @@ -65,7 +67,7 @@ impl Client { &self, data: Bytes, payment_option: PaymentOption, - ) -> Result { + ) -> Result<(AttoTokens, DataMapChunk), PutError> { let now = ant_networking::time::Instant::now(); let (data_map_chunk, chunks) = encrypt(data)?; debug!("Encryption took: {:.2?}", now.elapsed()); @@ -73,7 +75,7 @@ impl Client { // Pay for all chunks let xor_names: Vec<_> = chunks .iter() - .map(|chunk| (*chunk.name(), chunk.serialised_size())) + .map(|chunk| (*chunk.name(), chunk.size())) .collect(); info!("Paying for {} addresses", xor_names.len()); let (receipt, skipped_payments) = self @@ -100,13 +102,14 @@ impl Client { let record_count = chunks.len().saturating_sub(skipped_payments); + let tokens_spent = receipt + .values() + .map(|(_, cost)| cost.as_atto()) + .sum::(); + let total_cost = AttoTokens::from_atto(tokens_spent); + // Reporting if let Some(channel) = self.client_event_sender.as_ref() { - let tokens_spent = receipt - .values() - .map(|(_, cost)| cost.as_atto()) - .sum::(); - let summary = UploadSummary { records_paid: record_count, records_already_paid: skipped_payments, @@ -117,7 +120,7 @@ impl Client { } } - Ok(DataMapChunk(data_map_chunk)) + Ok((total_cost, DataMapChunk(data_map_chunk))) } } diff --git a/autonomi/src/client/high_level/data/public.rs b/autonomi/src/client/high_level/data/public.rs index 7b4fb0f3b7..eece1d567a 100644 --- a/autonomi/src/client/high_level/data/public.rs +++ b/autonomi/src/client/high_level/data/public.rs @@ -19,9 +19,9 @@ use super::DataAddr; impl Client { /// Fetch a blob of data from the network - pub async fn data_get_public(&self, addr: DataAddr) -> Result { + pub async fn data_get_public(&self, addr: &DataAddr) -> Result { info!("Fetching data from Data Address: {addr:?}"); - let data_map_chunk = self.chunk_get(ChunkAddress::new(addr)).await?; + let data_map_chunk = self.chunk_get(&ChunkAddress::new(*addr)).await?; let data = self .fetch_from_data_map_chunk(data_map_chunk.value()) .await?; @@ -37,7 +37,7 @@ impl Client { &self, data: Bytes, payment_option: PaymentOption, - ) -> Result { + ) -> Result<(AttoTokens, DataAddr), PutError> { let now = ant_networking::time::Instant::now(); let (data_map_chunk, chunks) = encrypt(data)?; let data_map_addr = data_map_chunk.address(); @@ -45,10 +45,10 @@ impl Client { info!("Uploading datamap chunk to the network at: {data_map_addr:?}"); let map_xor_name = *data_map_chunk.address().xorname(); - let mut xor_names = vec![(map_xor_name, data_map_chunk.serialised_size())]; + let mut xor_names = vec![(map_xor_name, data_map_chunk.size())]; for chunk in &chunks { - xor_names.push((*chunk.name(), chunk.serialised_size())); + xor_names.push((*chunk.name(), chunk.size())); } // Pay for all chunks + data map chunk @@ -83,13 +83,14 @@ impl Client { let record_count = (chunks.len() + 1) - skipped_payments; + let tokens_spent = receipt + .values() + .map(|(_proof, price)| price.as_atto()) + .sum::(); + let total_cost = AttoTokens::from_atto(tokens_spent); + // Reporting if let Some(channel) = self.client_event_sender.as_ref() { - let tokens_spent = receipt - .values() - .map(|(_proof, price)| price.as_atto()) - .sum::(); - let summary = UploadSummary { records_paid: record_count, records_already_paid: skipped_payments, @@ -100,7 +101,7 @@ impl Client { } } - Ok(map_xor_name) + Ok((total_cost, map_xor_name)) } /// Get the estimated cost of storing a piece of data. @@ -111,10 +112,10 @@ impl Client { debug!("Encryption took: {:.2?}", now.elapsed()); let map_xor_name = *data_map_chunks.address().xorname(); - let mut content_addrs = vec![(map_xor_name, data_map_chunks.serialised_size())]; + let mut content_addrs = vec![(map_xor_name, data_map_chunks.size())]; for chunk in &chunks { - content_addrs.push((*chunk.name(), chunk.serialised_size())); + content_addrs.push((*chunk.name(), chunk.size())); } info!( diff --git a/autonomi/src/client/high_level/files/archive_private.rs b/autonomi/src/client/high_level/files/archive_private.rs index 2a9225bb0d..f52d5b4e73 100644 --- a/autonomi/src/client/high_level/files/archive_private.rs +++ b/autonomi/src/client/high_level/files/archive_private.rs @@ -11,6 +11,7 @@ use std::{ path::{Path, PathBuf}, }; +use ant_evm::AttoTokens; use ant_networking::time::{Duration, SystemTime, UNIX_EPOCH}; use crate::{ @@ -130,7 +131,7 @@ impl Client { /// Fetch a [`PrivateArchive`] from the network pub async fn archive_get( &self, - addr: PrivateArchiveAccess, + addr: &PrivateArchiveAccess, ) -> Result { let data = self.data_get(addr).await?; Ok(PrivateArchive::from_bytes(data)?) @@ -141,7 +142,7 @@ impl Client { &self, archive: &PrivateArchive, payment_option: PaymentOption, - ) -> Result { + ) -> Result<(AttoTokens, PrivateArchiveAccess), PutError> { let bytes = archive .to_bytes() .map_err(|e| PutError::Serialization(format!("Failed to serialize archive: {e:?}")))?; diff --git a/autonomi/src/client/high_level/files/archive_public.rs b/autonomi/src/client/high_level/files/archive_public.rs index fec5320444..ad802dfa33 100644 --- a/autonomi/src/client/high_level/files/archive_public.rs +++ b/autonomi/src/client/high_level/files/archive_public.rs @@ -13,7 +13,7 @@ use std::{ use ant_networking::time::{Duration, SystemTime, UNIX_EPOCH}; -use ant_evm::{AttoTokens, EvmWallet}; +use crate::{AttoTokens, Wallet}; use bytes::Bytes; use serde::{Deserialize, Serialize}; use xor_name::XorName; @@ -139,7 +139,7 @@ impl Client { /// # Ok(()) /// # } /// ``` - pub async fn archive_get_public(&self, addr: ArchiveAddr) -> Result { + pub async fn archive_get_public(&self, addr: &ArchiveAddr) -> Result { let data = self.data_get_public(addr).await?; Ok(PublicArchive::from_bytes(data)?) } @@ -159,15 +159,15 @@ impl Client { /// # let wallet = todo!(); /// let mut archive = PublicArchive::new(); /// archive.add_file(PathBuf::from("file.txt"), DataAddr::random(&mut rand::thread_rng()), Metadata::new_with_size(0)); - /// let address = client.archive_put_public(&archive, &wallet).await?; + /// let (cost, address) = client.archive_put_public(&archive, &wallet).await?; /// # Ok(()) /// # } /// ``` pub async fn archive_put_public( &self, archive: &PublicArchive, - wallet: &EvmWallet, - ) -> Result { + wallet: &Wallet, + ) -> Result<(AttoTokens, ArchiveAddr), PutError> { let bytes = archive .to_bytes() .map_err(|e| PutError::Serialization(format!("Failed to serialize archive: {e:?}")))?; @@ -184,7 +184,7 @@ impl Client { } /// Get the cost to upload an archive - pub async fn archive_cost(&self, archive: PublicArchive) -> Result { + pub async fn archive_cost(&self, archive: &PublicArchive) -> Result { let bytes = archive .to_bytes() .map_err(|e| CostError::Serialization(format!("Failed to serialize archive: {e:?}")))?; diff --git a/autonomi/src/client/high_level/files/fs_private.rs b/autonomi/src/client/high_level/files/fs_private.rs index 54f6f40693..413dd375e6 100644 --- a/autonomi/src/client/high_level/files/fs_private.rs +++ b/autonomi/src/client/high_level/files/fs_private.rs @@ -20,7 +20,7 @@ use super::{DownloadError, UploadError}; use crate::client::Client; use crate::client::{data_types::chunk::DataMapChunk, utils::process_tasks_with_max_concurrency}; -use ant_evm::EvmWallet; +use crate::{AttoTokens, Wallet}; use bytes::Bytes; use std::path::PathBuf; @@ -28,7 +28,7 @@ impl Client { /// Download a private file from network to local file system pub async fn file_download( &self, - data_access: DataMapChunk, + data_access: &DataMapChunk, to_dest: PathBuf, ) -> Result<(), DownloadError> { let data = self.data_get(data_access).await?; @@ -44,12 +44,12 @@ impl Client { /// Download a private directory from network to local file system pub async fn dir_download( &self, - archive_access: PrivateArchiveAccess, + archive_access: &PrivateArchiveAccess, to_dest: PathBuf, ) -> Result<(), DownloadError> { let archive = self.archive_get(archive_access).await?; for (path, addr, _meta) in archive.iter() { - self.file_download(addr.clone(), to_dest.join(path)).await?; + self.file_download(addr, to_dest.join(path)).await?; } debug!("Downloaded directory to {to_dest:?}"); Ok(()) @@ -60,8 +60,8 @@ impl Client { pub async fn dir_upload( &self, dir_path: PathBuf, - wallet: &EvmWallet, - ) -> Result { + wallet: &Wallet, + ) -> Result<(AttoTokens, PrivateArchive), UploadError> { info!("Uploading directory as private: {dir_path:?}"); let start = tokio::time::Instant::now(); @@ -76,8 +76,8 @@ impl Client { let metadata = super::fs_public::metadata_from_entry(&entry); let path = entry.path().to_path_buf(); upload_tasks.push(async move { - let file = self.file_upload(path.clone(), wallet).await; - (path, metadata, file) + let res = self.file_upload(path.clone(), wallet).await; + (path, metadata, res) }); } @@ -90,11 +90,18 @@ impl Client { start.elapsed() ); let mut archive = PrivateArchive::new(); + let mut total_cost = AttoTokens::zero(); for (path, metadata, maybe_file) in uploads.into_iter() { let rel_path = get_relative_file_path_from_abs_file_and_folder_path(&path, &dir_path); match maybe_file { - Ok(file) => archive.add_file(rel_path, file, metadata), + Ok((cost, file)) => { + archive.add_file(rel_path, file, metadata); + total_cost = total_cost.checked_add(cost).unwrap_or_else(|| { + error!("Total cost overflowed: {total_cost:?} + {cost:?}"); + total_cost + }); + } Err(err) => { error!("Failed to upload file: {path:?}: {err:?}"); return Err(err); @@ -104,7 +111,7 @@ impl Client { #[cfg(feature = "loud")] println!("Upload completed in {:?}", start.elapsed()); - Ok(archive) + Ok((total_cost, archive)) } /// Same as [`Client::dir_upload`] but also uploads the archive (privately) to the network. @@ -113,11 +120,15 @@ impl Client { pub async fn dir_and_archive_upload( &self, dir_path: PathBuf, - wallet: &EvmWallet, - ) -> Result { - let archive = self.dir_upload(dir_path, wallet).await?; - let archive_addr = self.archive_put(&archive, wallet.into()).await?; - Ok(archive_addr) + wallet: &Wallet, + ) -> Result<(AttoTokens, PrivateArchiveAccess), UploadError> { + let (cost1, archive) = self.dir_upload(dir_path, wallet).await?; + let (cost2, archive_addr) = self.archive_put(&archive, wallet.into()).await?; + let total_cost = cost1.checked_add(cost2).unwrap_or_else(|| { + error!("Total cost overflowed: {cost1:?} + {cost2:?}"); + cost1 + }); + Ok((total_cost, archive_addr)) } /// Upload a private file to the network. @@ -125,16 +136,16 @@ impl Client { async fn file_upload( &self, path: PathBuf, - wallet: &EvmWallet, - ) -> Result { + wallet: &Wallet, + ) -> Result<(AttoTokens, DataMapChunk), UploadError> { info!("Uploading file: {path:?}"); #[cfg(feature = "loud")] println!("Uploading file: {path:?}"); let data = tokio::fs::read(path).await?; let data = Bytes::from(data); - let addr = self.data_put(data, wallet.into()).await?; + let (total_cost, addr) = self.data_put(data, wallet.into()).await?; debug!("Uploaded file successfully in the privateAchive: {addr:?}"); - Ok(addr) + Ok((total_cost, addr)) } } diff --git a/autonomi/src/client/high_level/files/fs_public.rs b/autonomi/src/client/high_level/files/fs_public.rs index 48578903db..a7935b0eaa 100644 --- a/autonomi/src/client/high_level/files/fs_public.rs +++ b/autonomi/src/client/high_level/files/fs_public.rs @@ -13,7 +13,7 @@ use crate::client::high_level::files::{ }; use crate::client::Client; use crate::client::{high_level::data::DataAddr, utils::process_tasks_with_max_concurrency}; -use ant_evm::EvmWallet; +use crate::{Amount, AttoTokens, Wallet}; use ant_networking::time::{Duration, SystemTime}; use bytes::Bytes; use std::path::PathBuf; @@ -22,7 +22,7 @@ impl Client { /// Download file from network to local file system pub async fn file_download_public( &self, - data_addr: DataAddr, + data_addr: &DataAddr, to_dest: PathBuf, ) -> Result<(), DownloadError> { let data = self.data_get_public(data_addr).await?; @@ -38,13 +38,13 @@ impl Client { /// Download directory from network to local file system pub async fn dir_download_public( &self, - archive_addr: ArchiveAddr, + archive_addr: &ArchiveAddr, to_dest: PathBuf, ) -> Result<(), DownloadError> { let archive = self.archive_get_public(archive_addr).await?; debug!("Downloaded archive for the directory from the network at {archive_addr:?}"); for (path, addr, _meta) in archive.iter() { - self.file_download_public(*addr, to_dest.join(path)).await?; + self.file_download_public(addr, to_dest.join(path)).await?; } debug!( "All files in the directory downloaded to {:?} from the network address {:?}", @@ -62,8 +62,8 @@ impl Client { pub async fn dir_upload_public( &self, dir_path: PathBuf, - wallet: &EvmWallet, - ) -> Result { + wallet: &Wallet, + ) -> Result<(AttoTokens, PublicArchive), UploadError> { info!("Uploading directory: {dir_path:?}"); let start = tokio::time::Instant::now(); @@ -78,8 +78,8 @@ impl Client { let metadata = metadata_from_entry(&entry); let path = entry.path().to_path_buf(); upload_tasks.push(async move { - let file = self.file_upload_public(path.clone(), wallet).await; - (path, metadata, file) + let res = self.file_upload_public(path.clone(), wallet).await; + (path, metadata, res) }); } @@ -92,11 +92,18 @@ impl Client { start.elapsed() ); let mut archive = PublicArchive::new(); + let mut total_cost = AttoTokens::zero(); for (path, metadata, maybe_file) in uploads.into_iter() { let rel_path = get_relative_file_path_from_abs_file_and_folder_path(&path, &dir_path); match maybe_file { - Ok(file) => archive.add_file(rel_path, file, metadata), + Ok((cost, file)) => { + archive.add_file(rel_path, file, metadata); + total_cost = total_cost.checked_add(cost).unwrap_or_else(|| { + error!("Total cost overflowed: {total_cost:?} + {cost:?}"); + total_cost + }); + } Err(err) => { error!("Failed to upload file: {path:?}: {err:?}"); return Err(err); @@ -106,7 +113,7 @@ impl Client { #[cfg(feature = "loud")] println!("Upload completed in {:?}", start.elapsed()); - Ok(archive) + Ok((total_cost, archive)) } /// Same as [`Client::dir_upload_public`] but also uploads the archive to the network. @@ -115,11 +122,15 @@ impl Client { pub async fn dir_and_archive_upload_public( &self, dir_path: PathBuf, - wallet: &EvmWallet, - ) -> Result { - let archive = self.dir_upload_public(dir_path, wallet).await?; - let archive_addr = self.archive_put_public(&archive, wallet).await?; - Ok(archive_addr) + wallet: &Wallet, + ) -> Result<(AttoTokens, ArchiveAddr), UploadError> { + let (cost1, archive) = self.dir_upload_public(dir_path, wallet).await?; + let (cost2, archive_addr) = self.archive_put_public(&archive, wallet).await?; + let total_cost = cost1.checked_add(cost2).unwrap_or_else(|| { + error!("Total cost overflowed: {cost1:?} + {cost2:?}"); + cost1 + }); + Ok((total_cost, archive_addr)) } /// Upload a file to the network. @@ -127,24 +138,24 @@ impl Client { async fn file_upload_public( &self, path: PathBuf, - wallet: &EvmWallet, - ) -> Result { + wallet: &Wallet, + ) -> Result<(AttoTokens, DataAddr), UploadError> { info!("Uploading file: {path:?}"); #[cfg(feature = "loud")] println!("Uploading file: {path:?}"); let data = tokio::fs::read(path.clone()).await?; let data = Bytes::from(data); - let addr = self.data_put_public(data, wallet.into()).await?; + let (cost, addr) = self.data_put_public(data, wallet.into()).await?; debug!("File {path:?} uploaded to the network at {addr:?}"); - Ok(addr) + Ok((cost, addr)) } /// Get the cost to upload a file/dir to the network. /// quick and dirty implementation, please refactor once files are cleanly implemented - pub async fn file_cost(&self, path: &PathBuf) -> Result { + pub async fn file_cost(&self, path: &PathBuf) -> Result { let mut archive = PublicArchive::new(); - let mut total_cost = ant_evm::Amount::ZERO; + let mut total_cost = Amount::ZERO; for entry in walkdir::WalkDir::new(path) { let entry = entry?; diff --git a/autonomi/src/client/high_level/files/mod.rs b/autonomi/src/client/high_level/files/mod.rs index 5ce0832eb6..8a26a67d96 100644 --- a/autonomi/src/client/high_level/files/mod.rs +++ b/autonomi/src/client/high_level/files/mod.rs @@ -13,6 +13,9 @@ pub mod archive_public; pub mod fs_private; pub mod fs_public; +pub use archive_private::PrivateArchive; +pub use archive_public::PublicArchive; + /// Number of files to upload in parallel. /// /// Can be overridden by the `FILE_UPLOAD_BATCH_SIZE` environment variable. diff --git a/autonomi/src/client/high_level/register/mod.rs b/autonomi/src/client/high_level/register/mod.rs index 58dbeeb2e2..59746154ec 100644 --- a/autonomi/src/client/high_level/register/mod.rs +++ b/autonomi/src/client/high_level/register/mod.rs @@ -168,6 +168,7 @@ impl Client { } /// Update the value of a register + /// The register needs to be created first with [`Client::register_create`] pub async fn register_update( &self, owner: &SecretKey, @@ -180,7 +181,7 @@ impl Client { }; let pointer_addr = self.register_head_pointer_address(&addr); debug!("Getting pointer of register head at {pointer_addr:?}"); - let pointer = match self.pointer_get(pointer_addr).await { + let pointer = match self.pointer_get(&pointer_addr).await { Ok(pointer) => pointer, Err(PointerError::Network(NetworkError::GetRecordError( GetRecordError::RecordNotFound, @@ -241,7 +242,7 @@ impl Client { // get the pointer of the register head let pointer_addr = self.register_head_pointer_address(addr); debug!("Getting pointer of register head at {pointer_addr:?}"); - let pointer = self.pointer_get(pointer_addr).await?; + let pointer = self.pointer_get(&pointer_addr).await?; let graph_entry_addr = match pointer.target() { PointerTarget::GraphEntryAddress(addr) => addr, other => return Err(RegisterError::InvalidHeadPointer(other.clone())), @@ -249,7 +250,7 @@ impl Client { // get the entry from the graph debug!("Getting register head graph entry at {graph_entry_addr:?}"); - let entry = match self.graph_entry_get(*graph_entry_addr).await { + let entry = match self.graph_entry_get(graph_entry_addr).await { Ok(entry) => entry, Err(GraphError::Fork(entries)) => { let values = entries.iter().map(|e| e.content).collect::>(); @@ -268,7 +269,7 @@ impl Client { pub async fn register_cost(&self, owner: &PublicKey) -> Result { let pointer_pk = self.register_head_pointer_pk(&RegisterAddress { owner: *owner }); let graph_entry_cost = self.graph_entry_cost(owner); - let pointer_cost = self.pointer_cost(pointer_pk); + let pointer_cost = self.pointer_cost(&pointer_pk); let (graph_entry_cost, pointer_cost) = futures::future::join(graph_entry_cost, pointer_cost).await; graph_entry_cost? @@ -307,7 +308,7 @@ impl Client { &self, graph_entry_addr: &GraphEntryAddress, ) -> Result<(GraphEntry, DerivationIndex), RegisterError> { - let entry = match self.graph_entry_get(*graph_entry_addr).await { + let entry = match self.graph_entry_get(graph_entry_addr).await { Ok(e) => e, Err(GraphError::Fork(entries)) => { warn!("Forked register, multiple entries found: {entries:?}, choosing the one with the smallest derivation index for the next entry"); diff --git a/autonomi/src/client/high_level/vault/mod.rs b/autonomi/src/client/high_level/vault/mod.rs index 0eee70b231..c955850b87 100644 --- a/autonomi/src/client/high_level/vault/mod.rs +++ b/autonomi/src/client/high_level/vault/mod.rs @@ -90,7 +90,7 @@ impl Client { let mut has_end_reached = false; while !has_end_reached { - let graph_entry = self.graph_entry_get(cur_graph_entry_addr).await?; + let graph_entry = self.graph_entry_get(&cur_graph_entry_addr).await?; // The first descendant is reserved for `expand GraphEntry`. match graph_entry.descendants.split_first() { @@ -344,7 +344,7 @@ impl Client { .public_key(); let cur_graph_entry_addr = GraphEntryAddress::from_owner(public_key.into()); - match self.graph_entry_get(cur_graph_entry_addr).await { + match self.graph_entry_get(&cur_graph_entry_addr).await { Ok(entry) => { // A GraphEntry was created with all NUM_OF_SCRATCHPADS_PER_GRAPHENTRY // scratchpad claimed: diff --git a/autonomi/src/lib.rs b/autonomi/src/lib.rs index e6bac2d80c..8954bb4714 100644 --- a/autonomi/src/lib.rs +++ b/autonomi/src/lib.rs @@ -94,21 +94,14 @@ pub use client::{ // Native data types data_types::chunk::Chunk, - // Addresses for the native data types data_types::chunk::ChunkAddress, data_types::graph::GraphEntry, data_types::graph::GraphEntryAddress, data_types::pointer::Pointer, data_types::pointer::PointerAddress, data_types::scratchpad::Scratchpad, - data_types::scratchpad::ScratchpadAddress, - // Files - files::archive_private::PrivateArchive, - files::archive_public::PublicArchive, - files::Metadata, - // Client Client, }; diff --git a/autonomi/src/python.rs b/autonomi/src/python.rs index cddc9fb34b..8895948032 100644 --- a/autonomi/src/python.rs +++ b/autonomi/src/python.rs @@ -45,9 +45,13 @@ impl Client { Ok(Self { inner: client }) } - fn data_put(&self, data: Vec, payment: &PaymentOption) -> PyResult { + fn data_put( + &self, + data: Vec, + payment: &PaymentOption, + ) -> PyResult<(String, PyDataMapChunk)> { let rt = tokio::runtime::Runtime::new().expect("Could not start tokio runtime"); - let access = rt + let (cost, access) = rt .block_on( self.inner .data_put(Bytes::from(data), payment.inner.clone()), @@ -56,22 +60,26 @@ impl Client { pyo3::exceptions::PyValueError::new_err(format!("Failed to put data: {e}")) })?; - Ok(PyDataMapChunk { inner: access }) + Ok((cost.to_string(), PyDataMapChunk { inner: access })) } fn data_get(&self, access: &PyDataMapChunk) -> PyResult> { let rt = tokio::runtime::Runtime::new().expect("Could not start tokio runtime"); let data = rt - .block_on(self.inner.data_get(access.inner.clone())) + .block_on(self.inner.data_get(&access.inner)) .map_err(|e| { pyo3::exceptions::PyValueError::new_err(format!("Failed to get data: {e}")) })?; Ok(data.to_vec()) } - fn data_put_public(&self, data: Vec, payment: &PaymentOption) -> PyResult { + fn data_put_public( + &self, + data: Vec, + payment: &PaymentOption, + ) -> PyResult<(String, String)> { let rt = tokio::runtime::Runtime::new().expect("Could not start tokio runtime"); - let addr = rt + let (cost, addr) = rt .block_on( self.inner .data_put_public(bytes::Bytes::from(data), payment.inner.clone()), @@ -80,7 +88,7 @@ impl Client { pyo3::exceptions::PyValueError::new_err(format!("Failed to put data: {e}")) })?; - Ok(crate::client::address::addr_to_str(addr)) + Ok((cost.to_string(), crate::client::address::addr_to_str(addr))) } fn data_get_public(&self, addr: &str) -> PyResult> { @@ -89,9 +97,11 @@ impl Client { pyo3::exceptions::PyValueError::new_err(format!("Invalid address: {e}")) })?; - let data = rt.block_on(self.inner.data_get_public(addr)).map_err(|e| { - pyo3::exceptions::PyValueError::new_err(format!("Failed to get data: {e}")) - })?; + let data = rt + .block_on(self.inner.data_get_public(&addr)) + .map_err(|e| { + pyo3::exceptions::PyValueError::new_err(format!("Failed to get data: {e}")) + })?; Ok(data.to_vec()) } @@ -175,7 +185,7 @@ impl Client { })?); let address = RustPointerAddress::new(xorname); - let pointer = rt.block_on(self.inner.pointer_get(address)).map_err(|e| { + let pointer = rt.block_on(self.inner.pointer_get(&address)).map_err(|e| { pyo3::exceptions::PyValueError::new_err(format!("Failed to get pointer: {e}")) })?; @@ -203,7 +213,7 @@ impl Client { fn pointer_cost(&self, key: &PyPublicKey) -> PyResult { let rt = tokio::runtime::Runtime::new().expect("Could not start tokio runtime"); let cost = rt - .block_on(self.inner.pointer_cost(key.inner)) + .block_on(self.inner.pointer_cost(&key.inner)) .map_err(|e| { pyo3::exceptions::PyValueError::new_err(format!("Failed to get pointer cost: {e}")) })?; @@ -251,9 +261,9 @@ impl PyPointer { }) } - pub fn network_address(&self) -> PyPointerAddress { + pub fn address(&self) -> PyPointerAddress { PyPointerAddress { - inner: self.inner.network_address(), + inner: self.inner.address(), } } diff --git a/autonomi/src/self_encryption.rs b/autonomi/src/self_encryption.rs index d7be081f29..e15213ab11 100644 --- a/autonomi/src/self_encryption.rs +++ b/autonomi/src/self_encryption.rs @@ -59,7 +59,7 @@ fn pack_data_map(data_map: DataMap) -> Result<(Chunk, Vec), Error> { debug!("Max chunk size: {}", *MAX_CHUNK_SIZE); let chunk = Chunk::new(chunk_content); // If datamap chunk is less than `MAX_CHUNK_SIZE` return it so it can be directly sent to the network. - if *MAX_CHUNK_SIZE >= chunk.serialised_size() { + if *MAX_CHUNK_SIZE >= chunk.size() { chunks.reverse(); // Returns the last datamap, and all the chunks produced. break (chunk, chunks); diff --git a/autonomi/tests/chunk.rs b/autonomi/tests/chunk.rs index 0a5d6a1ba3..45881cbc2f 100644 --- a/autonomi/tests/chunk.rs +++ b/autonomi/tests/chunk.rs @@ -37,7 +37,7 @@ async fn chunk_put_manual() -> Result<()> { tokio::time::sleep(tokio::time::Duration::from_secs(5)).await; // check that the chunk is stored - let got = client.chunk_get(addr).await?; + let got = client.chunk_get(&addr).await?; assert_eq!(got, chunk.clone()); println!("chunk got 1"); diff --git a/autonomi/tests/external_signer.rs b/autonomi/tests/external_signer.rs index fae2ebfe52..8359c6ab90 100644 --- a/autonomi/tests/external_signer.rs +++ b/autonomi/tests/external_signer.rs @@ -25,10 +25,10 @@ async fn pay_for_data(client: &Client, wallet: &Wallet, data: Bytes) -> eyre::Re let (data_map_chunk, chunks) = encrypt_data(data)?; let map_xor_name = *data_map_chunk.address().xorname(); - let mut xor_names = vec![(map_xor_name, data_map_chunk.serialised_size())]; + let mut xor_names = vec![(map_xor_name, data_map_chunk.size())]; for chunk in chunks { - xor_names.push((*chunk.name(), chunk.serialised_size())); + xor_names.push((*chunk.name(), chunk.size())); } pay_for_content_addresses(client, wallet, DataTypes::Chunk, xor_names.into_iter()).await @@ -114,7 +114,7 @@ async fn external_signer_put() -> eyre::Result<()> { sleep(Duration::from_secs(5)).await; - let private_data_access = client.data_put(data.clone(), receipt.into()).await?; + let (_cost, private_data_access) = client.data_put(data.clone(), receipt.into()).await?; let mut private_archive = PrivateArchive::new(); private_archive.add_file( @@ -129,16 +129,15 @@ async fn external_signer_put() -> eyre::Result<()> { sleep(Duration::from_secs(5)).await; - let private_archive_access = client.archive_put(&private_archive, receipt.into()).await?; + let (_cost, private_archive_access) = + client.archive_put(&private_archive, receipt.into()).await?; let vault_key = VaultSecretKey::random(); let mut user_data = UserData::default(); - user_data.add_private_file_archive_with_name( - private_archive_access.clone(), - "test-archive".to_string(), - ); + user_data + .add_private_file_archive_with_name(private_archive_access, "test-archive".to_string()); let scratchpad = Scratchpad::new( &vault_key, @@ -172,7 +171,7 @@ async fn external_signer_put() -> eyre::Result<()> { .expect("No private archive present in the UserData") .clone(); - let fetched_private_archive = client.archive_get(fetched_private_archive_access).await?; + let fetched_private_archive = client.archive_get(&fetched_private_archive_access).await?; let (_, (fetched_private_file_access, _)) = fetched_private_archive .map() @@ -180,7 +179,7 @@ async fn external_signer_put() -> eyre::Result<()> { .next() .expect("No file present in private archive"); - let fetched_private_file = client.data_get(fetched_private_file_access.clone()).await?; + let fetched_private_file = client.data_get(fetched_private_file_access).await?; assert_eq!( fetched_private_file, data, diff --git a/autonomi/tests/fs.rs b/autonomi/tests/fs.rs index 9951872f8f..ebeba12f7a 100644 --- a/autonomi/tests/fs.rs +++ b/autonomi/tests/fs.rs @@ -29,14 +29,14 @@ async fn dir_upload_download() -> Result<()> { let client = Client::init_local().await?; let wallet = get_funded_wallet(); - let addr = client + let (_cost, addr) = client .dir_and_archive_upload_public("tests/file/test_dir".into(), &wallet) .await?; sleep(Duration::from_secs(10)).await; client - .dir_download_public(addr, "tests/file/test_dir_fetched".into()) + .dir_download_public(&addr, "tests/file/test_dir_fetched".into()) .await?; // compare the two directories @@ -85,12 +85,12 @@ async fn file_into_vault() -> Result<()> { let wallet = get_funded_wallet(); let client_sk = bls::SecretKey::random(); - let addr = client + let (_cost, addr) = client .dir_and_archive_upload_public("tests/file/test_dir".into(), &wallet) .await?; sleep(Duration::from_secs(2)).await; - let archive = client.archive_get_public(addr).await?; + let archive = client.archive_get_public(&addr).await?; let set_version = 0; client .write_bytes_to_vault(archive.to_bytes()?, wallet.into(), &client_sk, set_version) diff --git a/autonomi/tests/graph.rs b/autonomi/tests/graph.rs index 47efb091bd..c2f3a87465 100644 --- a/autonomi/tests/graph.rs +++ b/autonomi/tests/graph.rs @@ -45,7 +45,7 @@ async fn graph_entry_put() -> Result<()> { tokio::time::sleep(tokio::time::Duration::from_secs(5)).await; // check that the graph_entry is stored - let txs = client.graph_entry_get(graph_entry.address()).await?; + let txs = client.graph_entry_get(&graph_entry.address()).await?; assert_eq!(txs, graph_entry.clone()); println!("graph_entry got 1"); @@ -75,7 +75,7 @@ async fn graph_entry_put() -> Result<()> { tokio::time::sleep(tokio::time::Duration::from_secs(5)).await; // check that the graph_entry is stored - let txs = client.graph_entry_get(graph_entry3.address()).await?; + let txs = client.graph_entry_get(&graph_entry3.address()).await?; assert_eq!(txs, graph_entry3.clone()); println!("graph_entry got 2"); diff --git a/autonomi/tests/pointer.rs b/autonomi/tests/pointer.rs index e339c1a2a9..b354f2506e 100644 --- a/autonomi/tests/pointer.rs +++ b/autonomi/tests/pointer.rs @@ -34,7 +34,7 @@ async fn pointer_put_manual() -> Result<()> { let pointer = Pointer::new(&key, 0, target); // estimate the cost of the pointer - let cost = client.pointer_cost(public_key).await?; + let cost = client.pointer_cost(&public_key).await?; println!("pointer cost: {cost}"); // put the pointer @@ -47,7 +47,7 @@ async fn pointer_put_manual() -> Result<()> { tokio::time::sleep(tokio::time::Duration::from_secs(5)).await; // check that the pointer is stored - let got = client.pointer_get(addr).await?; + let got = client.pointer_get(&addr).await?; assert_eq!(got, pointer.clone()); println!("pointer got 1"); @@ -63,7 +63,7 @@ async fn pointer_put_manual() -> Result<()> { tokio::time::sleep(tokio::time::Duration::from_secs(5)).await; // check that the pointer is updated - let got = client.pointer_get(addr).await?; + let got = client.pointer_get(&addr).await?; assert_eq!(got, pointer2.clone()); println!("pointer got 2"); @@ -84,7 +84,7 @@ async fn pointer_put() -> Result<()> { PointerTarget::ChunkAddress(ChunkAddress::new(XorName::random(&mut rand::thread_rng()))); // estimate the cost of the pointer - let cost = client.pointer_cost(public_key).await?; + let cost = client.pointer_cost(&public_key).await?; println!("pointer cost: {cost}"); // put the pointer @@ -98,7 +98,7 @@ async fn pointer_put() -> Result<()> { tokio::time::sleep(tokio::time::Duration::from_secs(5)).await; // check that the pointer is stored - let got = client.pointer_get(addr).await?; + let got = client.pointer_get(&addr).await?; assert_eq!(got, Pointer::new(&key, 0, target)); println!("pointer got 1"); @@ -110,7 +110,7 @@ async fn pointer_put() -> Result<()> { tokio::time::sleep(tokio::time::Duration::from_secs(5)).await; // check that the pointer is updated - let got = client.pointer_get(addr).await?; + let got = client.pointer_get(&addr).await?; assert_eq!(got, Pointer::new(&key, 1, target2)); println!("pointer got 2"); diff --git a/autonomi/tests/put.rs b/autonomi/tests/put.rs index df9a9fbce8..570ab06658 100644 --- a/autonomi/tests/put.rs +++ b/autonomi/tests/put.rs @@ -19,9 +19,9 @@ async fn put() -> Result<()> { let wallet = get_funded_wallet(); let data = gen_random_data(1024 * 1024 * 10); - let addr = client.data_put_public(data.clone(), wallet.into()).await?; + let (_cost, addr) = client.data_put_public(data.clone(), wallet.into()).await?; - let data_fetched = client.data_get_public(addr).await?; + let data_fetched = client.data_get_public(&addr).await?; assert_eq!(data, data_fetched, "data fetched should match data put"); Ok(())