Starknet 백서

Starknet

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 73쪽 중 11쪽

{ __hash_state__: HashState, __pending_key__: felt252, } ``` # core::starknet::storage::PendingStoragePathTrait Source: https://docs.starknet.io/build/corelib/core-starknet-storage-PendingStoragePathTrait A trait for creating a `PendingStoragePath` from a `StoragePath` hash state and a key. ## Signature ```rust theme={null} pub trait PendingStoragePathTrait ``` ## Trait functions ### new #### Signature ```rust theme={null} fn new(storage_path: @StoragePath, pending_key: felt252) -> PendingStoragePath ``` # core::starknet::storage::StorableStoragePointerReadAccess Source: https://docs.starknet.io/build/corelib/core-starknet-storage-StorableStoragePointerReadAccess Simple implementation of `StoragePointerReadAccess` for any type that implements `Store` for any offset. ## Signature ```rust theme={null} pub impl StorableStoragePointerReadAccess, > of StoragePointerReadAccess>; ``` ## Impl functions ### read #### Signature ```rust theme={null} fn read(self: @StoragePointer) -> T ``` ## Impl types ### Value #### Signature ```rust theme={null} type Value = T; ``` # core::starknet::storage::StorageAsPath Source: https://docs.starknet.io/build/corelib/core-starknet-storage-StorageAsPath Trait for creating a new `StoragePath` from a storage member. ## Signature ```rust theme={null} pub trait StorageAsPath ``` ## Trait functions ### as\_path #### Signature ```rust theme={null} fn as_path(self: @TMemberState) -> StoragePathValue> ``` ## Trait types ### Value #### Signature ```rust theme={null} type Value; ``` # core::starknet::storage::StorageAsPointer Source: https://docs.starknet.io/build/corelib/core-starknet-storage-StorageAsPointer Trait for converting a storage member to a `StoragePointer0Offset`. ## Signature ```rust theme={null} pub trait StorageAsPointer ``` ## Trait functions ### as\_ptr #### Signature ```rust theme={null} fn as_ptr(self: @TMemberState) -> StoragePointer0OffsetValue> ``` ## Trait types ### Value #### Signature ```rust theme={null} type Value; ``` # core::starknet::storage::StorageNodeDeref Source: https://docs.starknet.io/build/corelib/core-starknet-storage-StorageNodeDeref This makes the storage node members directly accessible from a path to the parent struct. ## Signature ```rust theme={null} pub impl StorageNodeDeref> of Deref>; ``` ## Impl functions ### deref #### Signature ```rust theme={null} fn deref(self: StoragePath) -> NodeType ``` ## Impl types ### Target #### Signature ```rust theme={null} type Target = NodeType; ``` # core::starknet::storage::StorageNodeMutDeref Source: https://docs.starknet.io/build/corelib/core-starknet-storage-StorageNodeMutDeref This makes the storage node members directly accessible from a path to the parent struct. ## Signature ```rust theme={null} pub impl StorageNodeMutDeref> of Deref>>; ``` ## Impl functions ### deref #### Signature ```rust theme={null} fn deref(self: StoragePath>) -> NodeType ``` ## Impl types ### Target #### Signature ```rust theme={null} type Target = NodeType; ``` # core::starknet::storage::StoragePath Source: https://docs.starknet.io/build/corelib/core-starknet-storage-StoragePath An intermediate struct to store a hash state, in order to be able to hash multiple values and get the final address. Storage path should have two interfaces, if `T` is storable then it should implement `StorageAsPointer` in order to be able to get the address of the storage path. Otherwise, if `T` is not storable then it should implement some kind of updating trait, e.g. `StoragePathEntry`. ## Signature ```rust theme={null} pub struct StoragePath { __hash_state__: HashState, } ``` # core::starknet::storage::StoragePathMutableConversion Source: https://docs.starknet.io/build/corelib/core-starknet-storage-StoragePathMutableConversion ## Signature ```rust theme={null} pub trait StoragePathMutableConversion ``` ## Trait functions ### as\_non\_mut Converts a `StoragePath>` to a `StoragePath`. This is useful to expose functions implemented for `StoragePath` on a `StoragePath>`. #### Signature ```rust theme={null} fn as_non_mut(self: StoragePath>) -> StoragePath ``` # core::starknet::storage::StoragePointer Source: https://docs.starknet.io/build/corelib/core-starknet-storage-StoragePointer A pointer to an address in storage, can be used to read and write values, if the generic type supports it (e.g. basic types like `felt252`). ## Signature ```rust theme={null} pub struct StoragePointer { pub __storage_pointer_address__: StorageBaseAddress, pub __storage_pointer_offset__: u8, } ``` ## Members ### **storage\_pointer\_address** #### Signature ```rust theme={null} pub __storage_pointer_address__: StorageBaseAddress ``` ### **storage\_pointer\_offset** #### Signature ```rust theme={null} pub __storage_pointer_offset__: u8 ``` # core::starknet::storage::StoragePointer0Offset Source: https://docs.starknet.io/build/corelib/core-starknet-storage-StoragePointer0Offset Same as `StoragePointer`, but with `offset` 0, which allows for some optimizations. ## Signature ```rust theme={null} pub struct StoragePointer0Offset { pub __storage_pointer_address__: StorageBaseAddress, } ``` ## Members ### **storage\_pointer\_address** #### Signature ```rust theme={null} pub __storage_pointer_address__: StorageBaseAddress ``` # core::starknet::storage::StoragePointerReadAccess Source: https://docs.starknet.io/build/corelib/core-starknet-storage-StoragePointerReadAccess Trait for accessing the values in storage using a `StoragePointer`. ## Signature ```rust theme={null} pub trait StoragePointerReadAccess ``` ## Examples ## Trait functions ### read #### Signature ```rust theme={null} fn read(self: @T) -> StoragePointerReadAccessValue ``` ## Trait types ### Value #### Signature ```rust theme={null} type Value; ``` # core::starknet::storage::StoragePointerWriteAccess Source: https://docs.starknet.io/build/corelib/core-starknet-storage-StoragePointerWriteAccess Trait for writing values to storage using a `StoragePointer`. ## Signature ```rust theme={null} pub trait StoragePointerWriteAccess ``` ## Examples ## Trait functions ### write #### Signature ```rust theme={null} fn write(self: T, value: Self::Value) ``` ## Trait types ### Value #### Signature ```rust theme={null} type Value; ``` # core::starknet::storage::SubPointersDeref Source: https://docs.starknet.io/build/corelib/core-starknet-storage-SubPointersDeref This makes the sub-pointers members directly accessible from a pointer to the parent struct. ## Signature ```rust theme={null} pub impl SubPointersDeref> of Deref>; ``` ## Impl functions ### deref #### Signature ```rust theme={null} fn deref(self: StoragePointer) -> SubPointersType ``` ## Impl types ### Target #### Signature ```rust theme={null} type Target = SubPointersType; ``` # core::starknet::storage::SubPointersMutDeref Source: https://docs.starknet.io/build/corelib/core-starknet-storage-SubPointersMutDeref This makes the sub-pointers members directly accessible from a pointer to the parent struct. ## Signature ```rust theme={null} pub impl SubPointersMutDeref> of Deref>>; ``` ## Impl functions ### deref #### Signature ```rust theme={null} fn deref(self: StoragePointer>) -> SubPointersType ``` ## Impl types ### Target #### Signature ```rust theme={null} type Target = SubPointersType; ``` # core::starknet::storage::ValidStorageTypeTrait Source: https://docs.starknet.io/build/corelib/core-starknet-storage-ValidStorageTypeTrait Trait that ensures a type is valid for storage in Starknet contracts. This trait is used to enforce that only specific types, such as those implementing `Store` or acting as a `StorageNode`, can be a part of a storage hierarchy. Any type that does not implement this trait cannot be used in a storage struct. ## Signature ```rust theme={null} pub trait ValidStorageTypeTrait ``` # core::starknet::storage::map::Map Source: https://docs.starknet.io/build/corelib/core-starknet-storage-map-Map A persistent key-value store in contract storage. This type cannot be instantiated as it is marked with `#[phantom]`. This is by design: `Map` is a compile-time type that only exists to provide type information for the compiler. It represents a mapping in storage, but the actual storage operations are handled by the [`StorageMapReadAccess`](./core-starknet-storage-map-StorageMapReadAccess), [`StorageMapWriteAccess`](./core-starknet-storage-map-StorageMapWriteAccess), and [`StoragePathEntry`](./core-starknet-storage-map-StoragePathEntry) traits. ## Signature ```rust theme={null} #[phantom] pub struct Map {} ``` # core::starknet::storage::map::StorageMapReadAccess Source: https://docs.starknet.io/build/corelib/core-starknet-storage-map-StorageMapReadAccess Provides direct read access to values in a storage [`Map`](./core-starknet-storage-map-Map). ## Signature ```rust theme={null} pub trait StorageMapReadAccess ``` ## Examples ```rust theme={null} use starknet::ContractAddress; use starknet::storage::{Map, StorageMapReadAccess, StoragePathEntry}; #[storage] struct Storage { balances: Map, allowances: Map>, } 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.entry(owner).read(spender); } ``` ## Trait functions ### read #### Signature ```rust theme={null} fn read(self: TMemberState, key: Self::Key) -> StorageMapReadAccessValue ``` ## Trait types ### Key #### Signature ```rust theme={null} type Key; ``` ### Value #### Signature ```rust theme={null} type Value; ``` # core::starknet::storage::map::StorageMapWriteAccess Source: https://docs.starknet.io/build/corelib/core-starknet-storage-map-StorageMapWriteAccess Provides direct write access to values in a storage [`Map`](./core-starknet-storage-map-Map). Enables directly storing values in the contract's storage at the address of the given key. ## Signature ```rust theme={null} pub trait StorageMapWriteAccess ``` ## Examples ```rust theme={null} use starknet::ContractAddress; use starknet::storage::{Map, StorageMapWriteAccess, StoragePathEntry}; #[storage] struct Storage { balances: Map, allowances: Map>, } fn write_storage(ref self: ContractState, address: ContractAddress) { // Write to single mapping self.balances.write(address, 100); // Write to nested mapping self.allowances.entry(owner).write(spender, 50); } ``` ## Trait functions ### write #### Signature ```rust theme={null} fn write(self: TMemberState, key: Self::Key, value: Self::Value) ``` ## Trait types ### Key #### Signature ```rust theme={null} type Key; ``` ### Value #### Signature ```rust theme={null} type Value; ``` # core::starknet::storage::map::StoragePathEntry Source: https://docs.starknet.io/build/corelib/core-starknet-storage-map-StoragePathEntry Computes storage paths for accessing [`Map`](./core-starknet-storage-map-Map) entries. The storage path combines the variable's base path with the key's hash to create a unique identifier for the storage slot. This path can then be used for subsequent read or write operations, or advanced further by chaining the `entry` method. ## Signature ```rust theme={null} pub trait StoragePathEntry ``` ## Examples ```rust theme={null} use starknet::ContractAddress; use starknet::storage::{Map, StoragePathEntry}; #[storage] struct Storage { balances: Map, } // Get the storage path for the balance of a specific address let balance_path = self.balances.entry(address); ``` ## Trait functions ### entry #### Signature ```rust theme={null} fn entry(self: C, key: Self::Key) -> StoragePathValue> ``` ## Trait types ### Key #### Signature ```rust theme={null} type Key; ``` ### Value #### Signature ```rust theme={null} type Value; ``` # core::starknet::storage::storage_base::FlattenedStorage Source: https://docs.starknet.io/build/corelib/core-starknet-storage-storage_base-FlattenedStorage 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. ## Signature ```rust theme={null} pub struct FlattenedStorage {} ``` # core::starknet::storage::storage_base::StorageBase Source: https://docs.starknet.io/build/corelib/core-starknet-storage-storage_base-StorageBase 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 `FlattenedStorage` instances, with the generic type representing the type of the stored member. ## Signature ```rust theme={null} pub struct StorageBase { pub __base_address__: felt252, } ``` ## Members ### **base\_address** #### Signature ```rust theme={null} pub __base_address__: felt252 ``` # core::starknet::storage::storage_base::StorageTrait Source: https://docs.starknet.io/build/corelib/core-starknet-storage-storage_base-StorageTrait A trait for creating the struct containing the `StorageBase` or `FlattenedStorage` of all the members of a contract state. ## Signature ```rust theme={null} pub trait StorageTrait ``` ## Trait functions ### storage 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. #### Signature ```rust theme={null} fn storage(self: FlattenedStorage) -> StorageTraitBaseType ``` ## Trait types ### BaseType The type of the struct containing the `StorageBase` or `FlattenedStorage` of all the members of the type `T`. #### Signature ```rust theme={null} type BaseType; ``` # core::starknet::storage::storage_base::StorageTraitMut Source: https://docs.starknet.io/build/corelib/core-starknet-storage-storage_base-StorageTraitMut A trait for creating the struct containing the mutable `StorageBase` or `FlattenedStorage` of all the members of a contract state. ## Signature ```rust theme={null} pub trait StorageTraitMut ``` ## Trait functions ### storage\_mut 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. #### Signature ```rust theme={null} fn storage_mut(self: FlattenedStorage>) -> StorageTraitMutBaseType ``` ## Trait types ### BaseType The type of the struct containing the mutable `StorageBase` or `FlattenedStorage` of all the members of the type `T`. #### Signature ```rust theme={null} type BaseType; ``` # core::starknet::storage::storage_node::StorageNode Source: https://docs.starknet.io/build/corelib/core-starknet-storage-storage_node-StorageNode A trait that given a storage path of a struct, generates the storage node of this struct. ## Signature ```rust theme={null} pub trait StorageNode ``` ## Trait functions ### storage\_node #### Signature ```rust theme={null} fn storage_node(self: StoragePath) -> StorageNodeNodeType ``` ## Trait types ### NodeType #### Signature ```rust theme={null} type NodeType; ``` # core::starknet::storage::storage_node::StorageNodeMut Source: https://docs.starknet.io/build/corelib/core-starknet-storage-storage_node-StorageNodeMut A mutable version of `StorageNode`, works the same way, but on `Mutable`. ## Signature ```rust theme={null} pub trait StorageNodeMut ``` ## Trait functions ### storage\_node\_mut #### Signature ```rust theme={null} fn storage_node_mut(self: StoragePath>) -> StorageNodeMutNodeType ``` ## Trait types ### NodeType #### Signature ```rust theme={null} type NodeType; ``` # core::starknet::storage::sub_pointers::SubPointers Source: https://docs.starknet.io/build/corelib/core-starknet-storage-sub_pointers-SubPointers Similar to storage node, but for structs which are stored sequentially in the storage. In contrast to storage node, the fields of the struct are just at an offset from the base address of the struct. ## Signature ```rust theme={null} pub trait SubPointers ``` ## Trait functions ### sub\_pointers Creates a sub pointers struct for the given storage pointer to a struct T. #### Signature ```rust theme={null} fn sub_pointers(self: StoragePointer) -> SubPointersSubPointersType ``` ## Trait types ### SubPointersType The type of the storage pointers, generated for the struct T. #### Signature ```rust theme={null} type SubPointersType; ``` # core::starknet::storage::sub_pointers::SubPointersForward Source: https://docs.starknet.io/build/corelib/core-starknet-storage-sub_pointers-SubPointersForward A trait for implementing `SubPointers` for types which are not a `StoragePointer`, such as `StorageBase` and `StoragePath`. ## Signature ```rust theme={null} pub trait SubPointersForward ``` ## Trait functions ### sub\_pointers #### Signature ```rust theme={null} fn sub_pointers(self: T) -> SubPointersForwardSubPointersType ``` ## Trait types ### SubPointersType #### Signature ```rust theme={null} type SubPointersType; ``` # core::starknet::storage::sub_pointers::SubPointersMut Source: https://docs.starknet.io/build/corelib/core-starknet-storage-sub_pointers-SubPointersMut A mutable version of `SubPointers`, works the same way, but on `Mutable`. ## Signature ```rust theme={null} pub trait SubPointersMut ``` ## Trait functions ### sub\_pointers\_mut Creates a sub pointers struct for the given storage pointer to a struct T. #### Signature ```rust theme={null} fn sub_pointers_mut(self: StoragePointer>) -> SubPointersMutSubPointersType ``` ## Trait types ### SubPointersType The type of the storage pointers, generated for the struct T. #### Signature ```rust theme={null} type SubPointersType; ``` # core::starknet::storage::sub_pointers::SubPointersMutForward Source: https://docs.starknet.io/build/corelib/core-starknet-storage-sub_pointers-SubPointersMutForward A trait for implementing `SubPointersMut` for types which are not a `StoragePointer`, such as `StorageBase` and `StoragePath`. ## Signature ```rust theme={null} pub trait SubPointersMutForward ``` ## Trait functions ### sub\_pointers\_mut #### Signature ```rust theme={null} fn sub_pointers_mut(self: T) -> SubPointersMutForwardSubPointersType ``` ## Trait types ### SubPointersType #### Signature ```rust theme={null} type SubPointersType; ``` # core::starknet::storage::vec::MutableVecTrait Source: https://docs.starknet.io/build/corelib/core-starknet-storage-vec-MutableVecTrait Provides mutable access to elements in a storage [`Vec`](./core-starknet-storage-vec-Vec). This trait extends the read functionality with methods to append new elements and modify existing ones. ## Signature ```rust theme={null} pub trait MutableVecTrait ``` ## Trait functions ### get Returns a mutable storage path to the element at the specified index, or `None` if out of bounds. #### Signature ```rust theme={null} fn get(self: T, index: u64) -> OptionElementType>>> ``` #### Examples ```rust theme={null} use starknet::storage::{Vec, MutableVecTrait, StoragePointerWriteAccess}; #[storage] struct Storage { numbers: Vec, } fn set_number(ref self: ContractState, index: u64, number: u256) -> bool { if let Some(ptr) = self.numbers.get(index) { ptr.write(number); true } else { false } } ``` ### at Returns a mutable storage path to the element at the specified index. #### Panics Panics if the index is out of bounds. #### Examples ```rust theme={null} use starknet::storage::{Vec, MutableVecTrait, StoragePointerWriteAccess}; #[storage] struct Storage { numbers: Vec, } fn set_number(ref self: ContractState, index: u64, number: u256) { self.numbers.at(index).write(number); } ``` #### Signature ```rust theme={null} fn at(self: T, index: u64) -> StoragePathElementType>> ``` ### len Returns the number of elements in the vector. The length is stored a
프로젝트로 돌아가기