Skip to content

Commit

Permalink
add missing import + remove nested mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
TAdev0 committed Jan 11, 2025
1 parent dff35c0 commit e29be3e
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions corelib/src/starknet/storage/map.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,31 @@
//! Basic usage with a single mapping:
//!
//! ```
//! use core::starknet::ContractAddress;
//! use core::starknet::storage::{Map, StorageMapReadAccess, StoragePathEntry,
//! StoragePointerReadAccess};
//!
//! #[storage]
//! struct Storage {
//! balances: Map<ContractAddress, u256>,
//! }
//!
//! fn read_storage(self: @ContractState) {
//! fn read_storage(self: @ContractState, address: ContractAddress) {
//! let balance = self.balances.read(address);
//! let balance = self.balances.entry(address).read();
//! }
//! ```
//!
//! Nested mappings:
//! For nested mappings, only path-based access is available:
//!
//! ```
//! #[storage]
//! struct Storage {
//! allowances: Map<ContractAddress, Map<ContractAddress, u256>>,
//! }
//!
//! fn read_storage(self: @ContractState) {
//! fn read_storage(self: @ContractState, owner: ContractAddress, spender: ContractAddress) {
//! let allowance = self.allowances.entry(owner).entry(spender).read();
//! let allowance = self.allowances.read(owner, spender);
//! }
//! ```

Expand All @@ -97,18 +100,17 @@ use super::{
/// # Examples
///
/// ```
/// use core::starknet::ContractAddress;
/// use core::starknet::storage::{Map, StorageMapReadAccess};
///
/// #[storage]
/// struct Storage {
/// balances: Map<ContractAddress, u256>,
/// allowances: Map<ContractAddress, Map<ContractAddress, u256>>,
/// }
///
/// fn read_storage(self: @ContractState) {
/// fn read_storage(self: @ContractState, address: ContractAddress) {
/// // Read from single mapping
/// let balance = self.balances.read(address);
///
/// // Read from nested mapping
/// let allowance = self.allowances.read(owner, spender);
/// }
/// ```
pub trait StorageMapReadAccess<TMemberState> {
Expand All @@ -124,18 +126,17 @@ pub trait StorageMapReadAccess<TMemberState> {
/// # Examples
///
/// ```
/// use core::starknet::ContractAddress;
/// use core::starknet::storage::{Map, StorageMapWriteAccess};
///
/// #[storage]
/// struct Storage {
/// balances: Map<ContractAddress, u256>,
/// allowances: Map<ContractAddress, Map<ContractAddress, u256>>,
/// }
///
/// fn write_storage(ref self: ContractState) {
/// fn write_storage(ref self: ContractState, address: ContractAddress) {
/// // Write to single mapping
/// self.balances.write(address, 100);
///
/// // Write to nested mapping
/// self.allowances.write(owner, spender, 50);
/// }
/// ```
pub trait StorageMapWriteAccess<TMemberState> {
Expand All @@ -153,6 +154,9 @@ pub trait StorageMapWriteAccess<TMemberState> {
/// # Examples
///
/// ```
/// use core::starknet::ContractAddress;
/// use core::starknet::storage::{Map, StoragePathEntry};
///
/// #[storage]
/// struct Storage {
/// balances: Map<ContractAddress, u256>,
Expand Down

0 comments on commit e29be3e

Please sign in to comment.