Skip to content

Commit

Permalink
Updates to address PR review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bitzoic committed Sep 7, 2023
1 parent cbfa98a commit cf118de
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion sway-lib-core/src/storage.sw
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ pub struct StorageKey<T> {
slot: b256,
/// The assigned offset based on the data structure `T`.
offset: u64,
/// A unqiue identifier.
/// A unique identifier.
field_id: b256,
}
2 changes: 1 addition & 1 deletion sway-lib-std/src/storage/storage_key.sw
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl<T> StorageKey<T> {
///
/// * `slot`: [b256] - The assigned location in storage for the new `StorageKey`.
/// * `offset`: [u64] - The assigned offset based on the data structure `T` for the new `StorageKey`.
/// * `field_id`: [b256] - A unqiue identifier for the new `StorageKey`.
/// * `field_id`: [b256] - A unique identifier for the new `StorageKey`.
///
/// # Returns
///
Expand Down
6 changes: 5 additions & 1 deletion sway-lib-std/src/storage/storage_map.sw
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ impl<K, V> StorageKey<StorageMap<K, V>> where K: Hash {
/// }
/// ```
pub fn get(self, key: K) -> StorageKey<V> where K: Hash {
StorageKey::<V>::new(sha256((key, self.field_id)), 0, sha256((key, self.field_id)))
StorageKey::<V>::new(
sha256((key, self.field_id)),
0,
sha256((key, self.field_id))
)
}

/// Clears a value previously stored using a key
Expand Down
18 changes: 15 additions & 3 deletions sway-lib-std/src/storage/storage_vec.sw
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ impl<V> StorageKey<StorageVec<V>> {
return None;
}

Some(StorageKey::<V>::new(sha256((index, self.field_id)), 0, sha256((index, self.field_id))))
Some(StorageKey::<V>::new(
sha256((index, self.field_id)),
0,
sha256((index, self.field_id))
))
}

/// Removes the element in the given index and moves all the elements in the following indexes
Expand Down Expand Up @@ -571,7 +575,11 @@ impl<V> StorageKey<StorageVec<V>> {
pub fn first(self) -> Option<StorageKey<V>> {
match read::<u64>(self.field_id, 0).unwrap_or(0) {
0 => None,
_ => Some(StorageKey::<V>::new(sha256((0, self.field_id)), 0, sha256((0, self.field_id)))),
_ => Some(StorageKey::<V>::new(
sha256((0, self.field_id)),
0,
sha256((0, self.field_id))
)),
}
}

Expand Down Expand Up @@ -606,7 +614,11 @@ impl<V> StorageKey<StorageVec<V>> {
pub fn last(self) -> Option<StorageKey<V>> {
match read::<u64>(self.field_id, 0).unwrap_or(0) {
0 => None,
len => Some(StorageKey::<V>::new(sha256((len - 1, self.field_id)), 0, sha256((0, self.field_id)))),
len => Some(StorageKey::<V>::new(
sha256((len - 1, self.field_id)),
0,
sha256((0, self.field_id))
)),
}
}

Expand Down

0 comments on commit cf118de

Please sign in to comment.