From a5d6130effe5d062e6a25df0fd40832085008671 Mon Sep 17 00:00:00 2001 From: sergerad Date: Sun, 2 Feb 2025 13:12:09 +1300 Subject: [PATCH 1/3] Rename AccountData to AccountFile --- crates/miden-objects/src/account/data.rs | 52 ++++++++++++------------ crates/miden-objects/src/account/mod.rs | 2 +- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/crates/miden-objects/src/account/data.rs b/crates/miden-objects/src/account/data.rs index 2f8789558..cb168dbbf 100644 --- a/crates/miden-objects/src/account/data.rs +++ b/crates/miden-objects/src/account/data.rs @@ -15,22 +15,22 @@ use super::{ Account, AuthSecretKey, Word, }; -// ACCOUNT DATA +// ACCOUNT FILE // ================================================================================================ -/// Account data contains a complete description of an account, including the [Account] struct as +/// Account file contains a complete description of an account, including the [Account] struct as /// well as account seed and account authentication info. /// /// The intent of this struct is to provide an easy way to serialize and deserialize all /// account-related data as a single unit (e.g., to/from files). #[derive(Debug, Clone)] -pub struct AccountData { +pub struct AccountFile { pub account: Account, pub account_seed: Option, pub auth_secret_key: AuthSecretKey, } -impl AccountData { +impl AccountFile { pub fn new(account: Account, account_seed: Option, auth: AuthSecretKey) -> Self { Self { account, @@ -40,13 +40,13 @@ impl AccountData { } #[cfg(feature = "std")] - /// Serialises and writes binary AccountData to specified file + /// Serialises and writes binary [AccountFile] to specified file pub fn write(&self, filepath: impl AsRef) -> io::Result<()> { fs::write(filepath, self.to_bytes()) } #[cfg(feature = "std")] - /// Reads from file and tries to deserialise an AccountData + /// Reads from file and tries to deserialise an [AccountFile] pub fn read(filepath: impl AsRef) -> io::Result { let mut file = File::open(filepath)?; let mut buffer = Vec::new(); @@ -54,16 +54,16 @@ impl AccountData { file.read_to_end(&mut buffer)?; let mut reader = SliceReader::new(&buffer); - Ok(AccountData::read_from(&mut reader).map_err(|_| io::ErrorKind::InvalidData)?) + Ok(AccountFile::read_from(&mut reader).map_err(|_| io::ErrorKind::InvalidData)?) } } // SERIALIZATION // ================================================================================================ -impl Serializable for AccountData { +impl Serializable for AccountFile { fn write_into(&self, target: &mut W) { - let AccountData { + let AccountFile { account, account_seed, auth_secret_key: auth, @@ -75,7 +75,7 @@ impl Serializable for AccountData { } } -impl Deserializable for AccountData { +impl Deserializable for AccountFile { fn read_from(source: &mut R) -> Result { let account = Account::read_from(source)?; let account_seed = >::read_from(source)?; @@ -102,14 +102,14 @@ mod tests { #[cfg(feature = "std")] use tempfile::tempdir; - use super::AccountData; + use super::AccountFile; use crate::{ account::{storage, Account, AccountCode, AccountId, AuthSecretKey, Felt, Word}, asset::AssetVault, testing::account_id::ACCOUNT_ID_REGULAR_ACCOUNT_IMMUTABLE_CODE_ON_CHAIN, }; - fn build_account_data() -> AccountData { + fn build_account_file() -> AccountFile { let id = AccountId::try_from(ACCOUNT_ID_REGULAR_ACCOUNT_IMMUTABLE_CODE_ON_CHAIN).unwrap(); let code = AccountCode::mock(); @@ -121,19 +121,19 @@ mod tests { let account_seed = Some(Word::default()); let auth_secret_key = AuthSecretKey::RpoFalcon512(SecretKey::new()); - AccountData::new(account, account_seed, auth_secret_key) + AccountFile::new(account, account_seed, auth_secret_key) } #[test] fn test_serde() { - let account_data = build_account_data(); - let serialized = account_data.to_bytes(); - let deserialized = AccountData::read_from_bytes(&serialized).unwrap(); - assert_eq!(deserialized.account, account_data.account); - assert_eq!(deserialized.account_seed, account_data.account_seed); + let account_file = build_account_file(); + let serialized = account_file.to_bytes(); + let deserialized = AccountFile::read_from_bytes(&serialized).unwrap(); + assert_eq!(deserialized.account, account_file.account); + assert_eq!(deserialized.account_seed, account_file.account_seed); assert_eq!( deserialized.auth_secret_key.to_bytes(), - account_data.auth_secret_key.to_bytes() + account_file.auth_secret_key.to_bytes() ); } @@ -141,17 +141,17 @@ mod tests { #[test] fn test_serde_file() { let dir = tempdir().unwrap(); - let filepath = dir.path().join("account_data.mac"); + let filepath = dir.path().join("account_file.mac"); - let account_data = build_account_data(); - account_data.write(filepath.as_path()).unwrap(); - let deserialized = AccountData::read(filepath.as_path()).unwrap(); + let account_file = build_account_file(); + account_file.write(filepath.as_path()).unwrap(); + let deserialized = AccountFile::read(filepath.as_path()).unwrap(); - assert_eq!(deserialized.account, account_data.account); - assert_eq!(deserialized.account_seed, account_data.account_seed); + assert_eq!(deserialized.account, account_file.account); + assert_eq!(deserialized.account_seed, account_file.account_seed); assert_eq!( deserialized.auth_secret_key.to_bytes(), - account_data.auth_secret_key.to_bytes() + account_file.auth_secret_key.to_bytes() ); } } diff --git a/crates/miden-objects/src/account/mod.rs b/crates/miden-objects/src/account/mod.rs index 3bb2f2fee..d0ad063c2 100644 --- a/crates/miden-objects/src/account/mod.rs +++ b/crates/miden-objects/src/account/mod.rs @@ -40,7 +40,7 @@ mod header; pub use header::AccountHeader; mod data; -pub use data::AccountData; +pub use data::AccountFile; // ACCOUNT // ================================================================================================ From 9e2018c1d0bbd38a567db029105fd417a61e8acf Mon Sep 17 00:00:00 2001 From: sergerad Date: Sun, 2 Feb 2025 13:20:04 +1300 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d12deca7..17ddc0485 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - [BREAKING] Moved `generated` module from `miden-proving-service-client` crate to `tx_prover::generated` hierarchy (#1102). - Added an endpoint to the `miden-proving-service` to update the workers (#1107). - Renamed the protobuf file of the transaction prover to `tx_prover.proto` (#1110). +- [BREAKING] Renamed `AccountData` to `AccountFile` (#1116). ## 0.7.2 (2025-01-28) - `miden-objects` crate only @@ -22,7 +23,6 @@ - Added missing doc comments (#1100). - Fixed setting of supporting types when instantiating `AccountComponent` from templates (#1103). - ## 0.7.0 (2025-01-22) ### Highlights From 8808d198aa83e016f2ed1eeba6717ef8725396a3 Mon Sep 17 00:00:00 2001 From: sergerad Date: Mon, 3 Feb 2025 08:15:44 +1300 Subject: [PATCH 3/3] Rename data.rs to file.rs and reorder attr/comment --- crates/miden-objects/src/account/{data.rs => file.rs} | 4 ++-- crates/miden-objects/src/account/mod.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename crates/miden-objects/src/account/{data.rs => file.rs} (100%) diff --git a/crates/miden-objects/src/account/data.rs b/crates/miden-objects/src/account/file.rs similarity index 100% rename from crates/miden-objects/src/account/data.rs rename to crates/miden-objects/src/account/file.rs index cb168dbbf..ccc227c3b 100644 --- a/crates/miden-objects/src/account/data.rs +++ b/crates/miden-objects/src/account/file.rs @@ -39,14 +39,14 @@ impl AccountFile { } } - #[cfg(feature = "std")] /// Serialises and writes binary [AccountFile] to specified file + #[cfg(feature = "std")] pub fn write(&self, filepath: impl AsRef) -> io::Result<()> { fs::write(filepath, self.to_bytes()) } - #[cfg(feature = "std")] /// Reads from file and tries to deserialise an [AccountFile] + #[cfg(feature = "std")] pub fn read(filepath: impl AsRef) -> io::Result { let mut file = File::open(filepath)?; let mut buffer = Vec::new(); diff --git a/crates/miden-objects/src/account/mod.rs b/crates/miden-objects/src/account/mod.rs index d0ad063c2..2893733c5 100644 --- a/crates/miden-objects/src/account/mod.rs +++ b/crates/miden-objects/src/account/mod.rs @@ -39,8 +39,8 @@ pub use storage::{AccountStorage, AccountStorageHeader, StorageMap, StorageSlot, mod header; pub use header::AccountHeader; -mod data; -pub use data::AccountFile; +mod file; +pub use file::AccountFile; // ACCOUNT // ================================================================================================