diff --git a/ant-node/tests/data_with_churn.rs b/ant-node/tests/data_with_churn.rs index ffe2a879ab..20047e828c 100644 --- a/ant-node/tests/data_with_churn.rs +++ b/ant-node/tests/data_with_churn.rs @@ -285,7 +285,12 @@ fn create_registers_task( let mut retries = 1; loop { match client - .register_create(random_data.clone(), &random_name, owner.clone(), &wallet) + .register_create( + Some(random_data.clone()), + &random_name, + owner.clone(), + &wallet, + ) .await { Ok(register) => { diff --git a/ant-node/tests/verify_data_location.rs b/ant-node/tests/verify_data_location.rs index db934a4c67..94a18d5de4 100644 --- a/ant-node/tests/verify_data_location.rs +++ b/ant-node/tests/verify_data_location.rs @@ -392,7 +392,12 @@ async fn store_registers( .map(char::from) .collect(); let register = client - .register_create(vec![1, 2, 3, 4].into(), &rand_name, key.clone(), wallet) + .register_create( + Some(vec![1, 2, 3, 4].into()), + &rand_name, + key.clone(), + wallet, + ) .await?; println!("Created Register at {:?}", register.address()); diff --git a/autonomi-cli/src/commands/file.rs b/autonomi-cli/src/commands/file.rs index 6d3f051015..94d31d77ac 100644 --- a/autonomi-cli/src/commands/file.rs +++ b/autonomi-cli/src/commands/file.rs @@ -53,7 +53,7 @@ pub async fn upload(file: &str, public: bool, peers: Vec) -> Result<( let local_addr; let archive = if public { let xor_name = client - .dir_upload(dir_path, &wallet) + .dir_and_archive_upload(dir_path, &wallet) .await .wrap_err("Failed to upload file")?; local_addr = addr_to_str(xor_name); diff --git a/autonomi-cli/src/commands/register.rs b/autonomi-cli/src/commands/register.rs index 0aad3ab844..17c30b2559 100644 --- a/autonomi-cli/src/commands/register.rs +++ b/autonomi-cli/src/commands/register.rs @@ -67,7 +67,7 @@ pub async fn create(name: &str, value: &str, public: bool, peers: Vec let permissions = RegisterPermissions::new_anyone_can_write(); client .register_create_with_permissions( - value.as_bytes().to_vec().into(), + Some(value.as_bytes().to_vec().into()), name, register_key, permissions, @@ -80,7 +80,7 @@ pub async fn create(name: &str, value: &str, public: bool, peers: Vec info!("With private write access"); client .register_create( - value.as_bytes().to_vec().into(), + Some(value.as_bytes().to_vec().into()), name, register_key, &wallet, diff --git a/autonomi/src/client/fs.rs b/autonomi/src/client/fs.rs index 15e32d1bf5..37f95127e6 100644 --- a/autonomi/src/client/fs.rs +++ b/autonomi/src/client/fs.rs @@ -109,11 +109,24 @@ impl Client { /// Upload a directory to the network. The directory is recursively walked. /// Reads all files, splits into chunks, uploads chunks, uploads datamaps, uploads archive, returns ArchiveAddr (pointing to the archive) - pub async fn dir_upload( + pub async fn dir_and_archive_upload( &self, dir_path: PathBuf, wallet: &EvmWallet, ) -> Result { + match self.dir_upload(dir_path.clone(), wallet).await { + Ok(archive) => Ok(self.archive_upload(&archive, wallet).await?), + Err(e) => Err(e), + } + } + + /// Upload a directory to the network. The directory is recursively walked. + /// Reads all files, splits into chunks, uploads chunks, uploads datamaps, returns Archive but does not upload that to the network. + pub async fn dir_upload( + &self, + dir_path: PathBuf, + wallet: &EvmWallet, + ) -> Result { info!("Uploading directory: {dir_path:?}"); let start = tokio::time::Instant::now(); @@ -152,14 +165,20 @@ impl Client { } } - // upload archive - let archive_serialized = archive.into_bytes()?; - let arch_addr = self.data_put(archive_serialized, wallet.into()).await?; - info!("Complete archive upload completed in {:?}", start.elapsed()); #[cfg(feature = "loud")] println!("Upload completed in {:?}", start.elapsed()); - Ok(arch_addr) + Ok(archive) + } + + /// Upload a directory Archive to the network + pub async fn archive_upload( + &self, + archive: &Archive, + wallet: &EvmWallet, + ) -> Result { + let archive_serialized = archive.into_bytes()?; + Ok(self.data_put(archive_serialized, wallet.into()).await?) } /// Upload a file to the network. diff --git a/autonomi/src/client/registers.rs b/autonomi/src/client/registers.rs index c405fd6cf7..1d49dbad99 100644 --- a/autonomi/src/client/registers.rs +++ b/autonomi/src/client/registers.rs @@ -255,12 +255,12 @@ impl Client { RegisterAddress::new(name, pk) } - /// Creates a new Register with a name and an initial value and uploads it to the network. + /// Creates a new Register with a name and optional initial value and uploads it to the network. /// /// The Register is created with the owner as the only writer. pub async fn register_create( &self, - value: Bytes, + value: Option, name: &str, owner: RegisterSecretKey, wallet: &EvmWallet, @@ -277,7 +277,7 @@ impl Client { /// Unlike `register_create`, this function allows you to specify the permissions for the register. pub async fn register_create_with_permissions( &self, - value: Bytes, + value: Option, name: &str, owner: RegisterSecretKey, permissions: RegisterPermissions, @@ -287,7 +287,7 @@ impl Client { let name = XorName::from_content_parts(&[name.as_bytes()]); // Owner can write to the register. - let register = Register::new(Some(value), name, owner, permissions)?; + let register = Register::new(value, name, owner, permissions)?; let address = register.address(); let reg_xor = address.xorname(); diff --git a/autonomi/tests/fs.rs b/autonomi/tests/fs.rs index 274fc447f2..35a948308e 100644 --- a/autonomi/tests/fs.rs +++ b/autonomi/tests/fs.rs @@ -30,7 +30,7 @@ async fn dir_upload_download() -> Result<()> { let wallet = get_funded_wallet(); let addr = client - .dir_upload("tests/file/test_dir".into(), &wallet) + .dir_and_archive_upload("tests/file/test_dir".into(), &wallet) .await?; sleep(Duration::from_secs(10)).await; @@ -86,7 +86,7 @@ async fn file_into_vault() -> Result<()> { let client_sk = bls::SecretKey::random(); let addr = client - .dir_upload("tests/file/test_dir".into(), &wallet) + .dir_and_archive_upload("tests/file/test_dir".into(), &wallet) .await?; sleep(Duration::from_secs(2)).await; diff --git a/autonomi/tests/register.rs b/autonomi/tests/register.rs index 266908c293..e698809d46 100644 --- a/autonomi/tests/register.rs +++ b/autonomi/tests/register.rs @@ -34,7 +34,12 @@ async fn register() -> Result<()> { .map(char::from) .collect(); let register = client - .register_create(vec![1, 2, 3, 4].into(), &rand_name, key.clone(), &wallet) + .register_create( + Some(vec![1, 2, 3, 4].into()), + &rand_name, + key.clone(), + &wallet, + ) .await .unwrap();