Skip to content

Commit

Permalink
feat(autonomi): remove registers from user data
Browse files Browse the repository at this point in the history
The (user) data that we store in our vault, includes references to
registers. To make the user data/vault independent from registers,
this is removed.
  • Loading branch information
b-zee committed Dec 16, 2024
1 parent 2ea9e13 commit 8ee4eed
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 30 deletions.
20 changes: 2 additions & 18 deletions ant-cli/src/access/user_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ use std::collections::HashMap;
use autonomi::client::{
address::{addr_to_str, str_to_addr},
files::{archive::PrivateArchiveAccess, archive_public::ArchiveAddr},
registers::{RegisterAddress, RegisterSecretKey},
registers::RegisterAddress,
vault::UserData,
};
use color_eyre::eyre::Result;

use super::{
data_dir::get_client_data_dir_path,
keys::{create_register_signing_key_file, get_register_signing_key},
};
use super::data_dir::get_client_data_dir_path;

use serde::{Deserialize, Serialize};

Expand All @@ -30,14 +27,10 @@ struct PrivateFileArchive {
}

pub fn get_local_user_data() -> Result<UserData> {
let register_sk = get_register_signing_key().map(|k| k.to_hex()).ok();
let registers = get_local_registers()?;
let file_archives = get_local_public_file_archives()?;
let private_file_archives = get_local_private_file_archives()?;

let user_data = UserData {
register_sk,
registers,
file_archives,
private_file_archives,
};
Expand Down Expand Up @@ -119,15 +112,6 @@ pub fn get_local_public_file_archives() -> Result<HashMap<ArchiveAddr, String>>
}

pub fn write_local_user_data(user_data: &UserData) -> Result<()> {
if let Some(register_key) = &user_data.register_sk {
let sk = RegisterSecretKey::from_hex(register_key)?;
create_register_signing_key_file(sk)?;
}

for (register, name) in user_data.registers.iter() {
write_local_register(register, name)?;
}

for (archive, name) in user_data.file_archives.iter() {
write_local_public_file_archive(addr_to_str(*archive), name)?;
}
Expand Down
5 changes: 0 additions & 5 deletions ant-cli/src/commands/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ pub async fn create(peers: Vec<Multiaddr>) -> Result<()> {
let local_user_data = crate::user_data::get_local_user_data()?;
let file_archives_len = local_user_data.file_archives.len();
let private_file_archives_len = local_user_data.private_file_archives.len();
let registers_len = local_user_data.registers.len();

println!("Pushing to network vault...");
let total_cost = client
Expand All @@ -53,7 +52,6 @@ pub async fn create(peers: Vec<Multiaddr>) -> Result<()> {
println!("Vault contains:");
println!("{file_archives_len} public file archive(s)");
println!("{private_file_archives_len} private file archive(s)");
println!("{registers_len} register(s)");
Ok(())
}

Expand All @@ -80,7 +78,6 @@ pub async fn sync(peers: Vec<Multiaddr>, force: bool) -> Result<()> {
let local_user_data = crate::user_data::get_local_user_data()?;
let file_archives_len = local_user_data.file_archives.len();
let private_file_archives_len = local_user_data.private_file_archives.len();
let registers_len = local_user_data.registers.len();
client
.put_user_data_to_vault(&vault_sk, wallet.into(), local_user_data)
.await?;
Expand All @@ -89,7 +86,6 @@ pub async fn sync(peers: Vec<Multiaddr>, force: bool) -> Result<()> {
println!("Vault contains:");
println!("{file_archives_len} public file archive(s)");
println!("{private_file_archives_len} private file archive(s)");
println!("{registers_len} register(s)");
Ok(())
}

Expand All @@ -108,6 +104,5 @@ pub async fn load(peers: Vec<Multiaddr>) -> Result<()> {
"{} private file archive(s)",
user_data.private_file_archives.len()
);
println!("{} register(s)", user_data.registers.len());
Ok(())
}
4 changes: 2 additions & 2 deletions autonomi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ default = ["vault"]
external-signer = ["ant-evm/external-signer"]
extension-module = ["pyo3/extension-module"]
fs = ["tokio/fs"]
full = ["registers", "vault", "fs"]
full = ["vault", "fs"]
local = ["ant-networking/local", "ant-evm/local"]
loud = []
registers = []
vault = ["registers"]
vault = []

[dependencies]
ant-bootstrap = { path = "../ant-bootstrap", version = "0.1.0" }
Expand Down
5 changes: 0 additions & 5 deletions autonomi/src/client/vault/user_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::client::data::PutError;
use crate::client::files::archive::PrivateArchiveAccess;
use crate::client::files::archive_public::ArchiveAddr;
use crate::client::payment::PaymentOption;
use crate::client::registers::RegisterAddress;
use crate::client::vault::VaultError;
use crate::client::vault::{app_name_to_vault_content_type, VaultContentType, VaultSecretKey};
use crate::client::Client;
Expand All @@ -32,10 +31,6 @@ pub static USER_DATA_VAULT_CONTENT_IDENTIFIER: LazyLock<VaultContentType> =
/// Using User Data Vault is optional, one can decide to keep all their data locally instead.
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct UserData {
/// The register secret key hex encoded
pub register_sk: Option<String>,
/// Owned register addresses, along with their names (can be empty)
pub registers: HashMap<RegisterAddress, String>,
/// Owned file archive addresses, along with their names (can be empty)
pub file_archives: HashMap<ArchiveAddr, String>,
/// Owned private file archives, along with their names (can be empty)
Expand Down

0 comments on commit 8ee4eed

Please sign in to comment.