Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
- [BREAKING] Migrated to `miden-vm` v0.20 and `miden-crypto` v0.19 ([#2158](https://github.com/0xMiden/miden-base/pull/2158)).
- [BREAKING] Refactored `AccountStorageDelta` to use a new `StorageSlotDelta` type ([#2182](https://github.com/0xMiden/miden-base/pull/2182)).
- [BREAKING] Removed OLD_MAP_ROOT from being returned when calling [`native_account::set_map_item`](crates/miden-lib/asm/miden/native_account.masm) ([#2194](https://github.com/0xMiden/miden-base/pull/2194)).
- [BREAKING] Refactored account component templates into `StorageSchema` ([#2193](https://github.com/0xMiden/miden-base/pull/2193)).
- [BREAKING] Refactored `InitStorageData` to support native types ([#2230](https://github.com/0xMiden/miden-base/pull/2230)).
- Added `StorageSchema::commitment()` ([#2244](https://github.com/0xMiden/miden-base/pull/2244)).
- [BREAKING] Refactored account component templates into `AccountStorageSchema` ([#2193](https://github.com/0xMiden/miden-base/pull/2193)).
- [BREAKING] Refactor note tags to be arbitrary `u32` values and drop previous validation ([#2219](https://github.com/0xMiden/miden-base/pull/2219)).
- [BREAKING] Refactored `InitStorageData` to support native types ([#2230](https://github.com/0xMiden/miden-base/pull/2230)).
Expand Down
36 changes: 23 additions & 13 deletions crates/miden-protocol/src/account/component/metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use miden_mast_package::{Package, SectionId};
use miden_processor::DeserializationError;
use semver::Version;

use super::{AccountStorageSchema, AccountType, SchemaRequirement, StorageValueName};
use super::{AccountType, SchemaRequirement, StorageSchema, StorageValueName};
use crate::AccountError;

// ACCOUNT COMPONENT METADATA
Expand Down Expand Up @@ -40,10 +40,10 @@ use crate::AccountError;
/// use miden_protocol::account::StorageSlotName;
/// use miden_protocol::account::component::{
/// AccountComponentMetadata,
/// AccountStorageSchema,
/// FeltSchema,
/// InitStorageData,
/// SchemaTypeId,
/// StorageSchema,
/// StorageSlotSchema,
/// StorageValueName,
/// ValueSlotSchema,
Expand All @@ -61,7 +61,7 @@ use crate::AccountError;
/// FeltSchema::new_typed(SchemaTypeId::native_felt(), "foo"),
/// ]);
///
/// let storage_schema = AccountStorageSchema::new([(
/// let storage_schema = StorageSchema::new([(
/// slot_name.clone(),
/// StorageSlotSchema::Value(ValueSlotSchema::new(Some("demo slot".into()), word)),
/// )])?;
Expand Down Expand Up @@ -102,7 +102,7 @@ pub struct AccountComponentMetadata {

/// Storage schema defining the component's storage layout, defaults, and init-supplied values.
#[cfg_attr(feature = "std", serde(rename = "storage"))]
storage_schema: AccountStorageSchema,
storage_schema: StorageSchema,
}

impl AccountComponentMetadata {
Expand All @@ -112,7 +112,7 @@ impl AccountComponentMetadata {
description: String,
version: Version,
targets: BTreeSet<AccountType>,
storage_schema: AccountStorageSchema,
storage_schema: StorageSchema,
) -> Self {
Self {
name,
Expand Down Expand Up @@ -154,7 +154,7 @@ impl AccountComponentMetadata {
}

/// Returns the storage schema of the component.
pub fn storage_schema(&self) -> &AccountStorageSchema {
pub fn storage_schema(&self) -> &StorageSchema {
&self.storage_schema
}
}
Expand Down Expand Up @@ -200,14 +200,24 @@ impl Serializable for AccountComponentMetadata {

impl Deserializable for AccountComponentMetadata {
fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
let name = String::read_from(source)?;
let description = String::read_from(source)?;
if !description.is_ascii() {
return Err(DeserializationError::InvalidValue(
"description must contain only ASCII characters".to_string(),
));
}
let version = semver::Version::from_str(&String::read_from(source)?)
.map_err(|err: semver::Error| DeserializationError::InvalidValue(err.to_string()))?;
let supported_types = BTreeSet::<AccountType>::read_from(source)?;
let storage_schema = StorageSchema::read_from(source)?;

Ok(Self {
name: String::read_from(source)?,
description: String::read_from(source)?,
version: semver::Version::from_str(&String::read_from(source)?).map_err(
|err: semver::Error| DeserializationError::InvalidValue(err.to_string()),
)?,
supported_types: BTreeSet::<AccountType>::read_from(source)?,
storage_schema: AccountStorageSchema::read_from(source)?,
name,
description,
version,
supported_types,
storage_schema,
})
}
}
4 changes: 2 additions & 2 deletions crates/miden-protocol/src/account/component/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ mod tests {
"A test component".to_string(),
Version::new(1, 0, 0),
BTreeSet::from_iter([AccountType::RegularAccountImmutableCode]),
AccountStorageSchema::default(),
StorageSchema::default(),
);

let metadata_bytes = metadata.to_bytes();
Expand Down Expand Up @@ -329,7 +329,7 @@ mod tests {
AccountType::RegularAccountImmutableCode,
AccountType::RegularAccountUpdatableCode,
]),
AccountStorageSchema::default(),
StorageSchema::default(),
);

// Test with empty init data - this tests the complete workflow:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ pub enum WordValue {
Elements([String; 4]),
}

impl From<Word> for WordValue {
fn from(value: Word) -> Self {
WordValue::FullyTyped(value)
}
}

impl From<String> for WordValue {
fn from(value: String) -> Self {
WordValue::Atomic(value)
Expand All @@ -35,11 +41,8 @@ impl From<&str> for WordValue {
}
}

impl From<Word> for WordValue {
fn from(value: Word) -> Self {
WordValue::FullyTyped(value)
}
}
// CONVERSIONS
// ====================================================================================================

impl From<Felt> for WordValue {
/// Converts a [`Felt`] to a [`WordValue`] as a Word in the form `[0, 0, 0, felt]`.
Expand Down Expand Up @@ -120,7 +123,7 @@ impl InitStorageData {
/// - `[Felt; 4]`: converted to a Word
/// - `Felt`: converted to `[0, 0, 0, felt]`
/// - `String` or `&str`: a parseable string value
/// - `WordValue`: a raw or fully-typed word value
/// - `WordValue`: a word value (fully typed, atomic, or elements)
pub fn insert_value(
&mut self,
name: StorageValueName,
Expand Down Expand Up @@ -201,6 +204,12 @@ impl InitStorageData {
self.map_entries.entry(slot_name).or_default().extend(entries);
}
}

/// Merges another [`InitStorageData`] into this one, overwriting value entries and appending
/// map entries.
pub fn merge_from(&mut self, other: InitStorageData) {
self.merge_with(other);
}
}

// ERRORS
Expand Down
Loading