Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core Lib Documentation:storage_base module #7039

Merged
merged 4 commits into from
Jan 10, 2025
Merged
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
30 changes: 19 additions & 11 deletions corelib/src/starknet/storage/storage_base.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
//! Core abstractions for contract storage management.
//!
//! This module provides the types and traits for handling contract storage internally
//! within the Cairo core library. Most developers should not need to implement these traits
//! directly, as they are primarily used by the storage system implementation.
//!
//! If you're writing a regular Starknet contract, you should use the high-level storage
//! traits and types, interacting with the members of the storage struct directly.

use super::{Mutable, StorageAsPath, StoragePath, StoragePathTrait};

/// A struct for holding an address to initialize a storage path with. The members (not direct
/// members, but accessible using deref) of a contract state are either `StorageBase` or
/// members, but accessible using `deref`) of a contract state are either `StorageBase` or
/// `FlattenedStorage` instances, with the generic type representing the type of the stored member.
pub struct StorageBase<T> {
pub __base_address__: felt252,
Expand All @@ -24,7 +33,6 @@ impl StorageBaseDeref<T> of core::ops::Deref<StorageBase<T>> {
}
}


/// A type that represents a flattened storage, i.e. a storage object which does not have any effect
/// on the path taken into consideration when computing the address of the storage object.
pub struct FlattenedStorage<T> {}
Expand Down Expand Up @@ -53,24 +61,24 @@ impl MutableFlattenedStorageDeref<
}
}

/// A trait for creating the struct containing the StorageBase or FlattenedStorage of all the
/// A trait for creating the struct containing the `StorageBase` or `FlattenedStorage` of all the
/// members of a contract state.
pub trait StorageTrait<T> {
/// The type of the struct containing the StorageBase or FlattenedStorage of all the members of
/// a the type `T`.
/// The type of the struct containing the `StorageBase` or `FlattenedStorage` of all the members
/// of the type `T`.
type BaseType;
/// Creates a struct containing the StorageBase or FlattenedStorage of all the members of a
/// Creates a struct containing the `StorageBase` or `FlattenedStorage` of all the members of a
/// contract state. Should be called from the `deref` method of the contract state.
fn storage(self: FlattenedStorage<T>) -> Self::BaseType;
}

/// A trait for creating the struct containing the mutable StorageBase or FlattenedStorage of all
/// the members of a contract state.
/// A trait for creating the struct containing the mutable `StorageBase` or `FlattenedStorage` of
/// all the members of a contract state.
pub trait StorageTraitMut<T> {
/// The type of the struct containing the mutable StorageBase or FlattenedStorage of all the
/// members of a the type `T`.
/// The type of the struct containing the mutable `StorageBase` or `FlattenedStorage` of all the
/// members of the type `T`.
type BaseType;
/// Creates a struct containing a mutable version of the StorageBase or FlattenedStorage of
/// Creates a struct containing a mutable version of the `StorageBase` or `FlattenedStorage` of
/// all the members of a contract state. Should be called from the `deref` method of the
/// contract state.
fn storage_mut(self: FlattenedStorage<Mutable<T>>) -> Self::BaseType;
Expand Down
Loading