Skip to content

Commit

Permalink
feat: add get_base_storage_address at storage_map
Browse files Browse the repository at this point in the history
  • Loading branch information
JhChoy committed Aug 8, 2024
1 parent d4f8bf7 commit 625adbd
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/libraries/storage_map.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ pub impl Felt252MapImpl<T, +Drop<T>, impl TStore: Store<T>> of Felt252MapTrait<T
Felt252Map { address_domain, base }
}

fn get_base_storage_address(self: @Felt252Map<T>) -> (u32, StorageBaseAddress) {
(*self.address_domain, *self.base)
}

fn address_at(self: @Felt252Map<T>, key: felt252) -> felt252 {
let base_storage_address: felt252 = storage_address_from_base(*self.base).into();

Expand Down Expand Up @@ -84,7 +88,6 @@ pub impl Felt252MapImpl<T, +Drop<T>, impl TStore: Store<T>> of Felt252MapTrait<T
pub type StorageMap<K, V> = Felt252Map<V>;

pub trait StorageMapTrait<K, V> {
fn fetch(address_domain: u32, base: StorageBaseAddress) -> StorageMap<K, V>;
fn address_at(self: @StorageMap<K, V>, key: K) -> felt252;
fn read_at(self: @StorageMap<K, V>, key: K) -> V;
fn write_at(ref self: StorageMap<K, V>, key: K, value: V);
Expand All @@ -93,11 +96,6 @@ pub trait StorageMapTrait<K, V> {
impl StorageMapIntoImpl<
K, V, +Into<K, felt252>, +Drop<K>, +Drop<V>, impl TStore: Store<V>
> of StorageMapTrait<K, V> {
#[inline]
fn fetch(address_domain: u32, base: StorageBaseAddress) -> StorageMap<K, V> {
Felt252Map { address_domain, base }
}

fn address_at(self: @StorageMap<K, V>, key: K) -> felt252 {
Felt252MapTrait::address_at(self, key.into())
}
Expand All @@ -114,11 +112,6 @@ impl StorageMapIntoImpl<
impl StorageMapHashImpl<
K, V, +Hash<K, HashState>, +Drop<K>, +Drop<V>, impl TStore: Store<V>
> of StorageMapTrait<K, V> {
#[inline]
fn fetch(address_domain: u32, base: StorageBaseAddress) -> StorageMap<K, V> {
Felt252Map { address_domain, base }
}

fn address_at(self: @StorageMap<K, V>, key: K) -> felt252 {
Felt252MapTrait::address_at(self, PoseidonTrait::new().update_with(key).finalize())
}
Expand Down

0 comments on commit 625adbd

Please sign in to comment.