Skip to content

Commit

Permalink
Add storage path update trait. (#5973)
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbens-starkware authored Jul 7, 2024
1 parent 1af57c9 commit 9e72a1c
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions corelib/src/starknet/storage.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,20 @@ impl StoragePathImpl<T> of StoragePathTrait<T> {
}
}

/// Trait for updating the hash state of a storage path with a given value. Also change the generic
/// type of the storage path from `SourceType` to `TargetType`.
trait StoragePathUpdateTrait<SourceType, TargetType, Value> {
fn update(self: StoragePath<SourceType>, value: Value) -> StoragePath<TargetType>;
}

impl StoragePathUpdateImpl<
SourceType, TargetType, Value, impl HashImpl: core::hash::Hash<Value, StoragePathHashState>
> of StoragePathUpdateTrait<SourceType, TargetType, Value> {
fn update(self: StoragePath<SourceType>, value: Value) -> StoragePath<TargetType> {
StoragePath { hash_state: HashImpl::update_state(self.hash_state, value) }
}
}


/// Trait for creating a new `StoragePath` from a storage member.
pub trait StorageAsPath<TMemberState> {
Expand Down Expand Up @@ -227,13 +241,7 @@ impl EntryInfoStoragePathEntry<
type Key = EntryInfo::<T>::Key;
type Value = EntryInfo::<T>::Value;
fn entry(self: StoragePath<T>, key: EntryInfo::<T>::Key) -> StoragePath<EntryInfo::<T>::Value> {
StoragePath::<
EntryInfo::<T>::Value
> {
hash_state: core::hash::Hash::<
EntryInfo::<T>::Key, StoragePathHashState
>::update_state(self.hash_state, key)
}
self.update(key)
}
}

Expand All @@ -248,13 +256,7 @@ impl MutableEntryStoragePathEntry<
type Key = EntryImpl::Key;
type Value = Mutable<EntryImpl::Value>;
fn entry(self: StoragePath<T>, key: EntryImpl::Key) -> StoragePath<Mutable<EntryImpl::Value>> {
StoragePath::<
Mutable<EntryImpl::Value>
> {
hash_state: core::hash::Hash::<
EntryImpl::Key, StoragePathHashState
>::update_state(self.hash_state, key)
}
self.update(key)
}
}

Expand Down

0 comments on commit 9e72a1c

Please sign in to comment.