From e29be3e79bdee6f00119d2b387bf2c65f28fdbbe Mon Sep 17 00:00:00 2001 From: TAdev0 Date: Sat, 11 Jan 2025 18:57:27 +0100 Subject: [PATCH] add missing import + remove nested mappings --- corelib/src/starknet/storage/map.cairo | 32 +++++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/corelib/src/starknet/storage/map.cairo b/corelib/src/starknet/storage/map.cairo index ec4334b9f59..8bec4ed9c62 100644 --- a/corelib/src/starknet/storage/map.cairo +++ b/corelib/src/starknet/storage/map.cairo @@ -61,18 +61,22 @@ //! Basic usage with a single mapping: //! //! ``` +//! use core::starknet::ContractAddress; +//! use core::starknet::storage::{Map, StorageMapReadAccess, StoragePathEntry, +//! StoragePointerReadAccess}; +//! //! #[storage] //! struct Storage { //! balances: Map, //! } //! -//! 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] @@ -80,9 +84,8 @@ //! allowances: Map>, //! } //! -//! 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); //! } //! ``` @@ -97,18 +100,17 @@ use super::{ /// # Examples /// /// ``` +/// use core::starknet::ContractAddress; +/// use core::starknet::storage::{Map, StorageMapReadAccess}; +/// /// #[storage] /// struct Storage { /// balances: Map, -/// allowances: Map>, /// } /// -/// 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 { @@ -124,18 +126,17 @@ pub trait StorageMapReadAccess { /// # Examples /// /// ``` +/// use core::starknet::ContractAddress; +/// use core::starknet::storage::{Map, StorageMapWriteAccess}; +/// /// #[storage] /// struct Storage { /// balances: Map, -/// allowances: Map>, /// } /// -/// 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 { @@ -153,6 +154,9 @@ pub trait StorageMapWriteAccess { /// # Examples /// /// ``` +/// use core::starknet::ContractAddress; +/// use core::starknet::storage::{Map, StoragePathEntry}; +/// /// #[storage] /// struct Storage { /// balances: Map,