Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
clarifications for unhashed::contains_prefixed_key
Signed-off-by: muraca <[email protected]>
  • Loading branch information
muraca committed Jan 26, 2023
commit 5e32f06af700feaa4519c9ed90bfbb34dcfdef5f
2 changes: 1 addition & 1 deletion frame/support/src/storage/generator/double_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ where
where
KArg1: EncodeLike<K1>,
{
unhashed::contains_prefix(Self::storage_double_map_final_key1(k1).as_ref())
unhashed::contains_prefixed_key(Self::storage_double_map_final_key1(k1).as_ref())
}

fn iter_prefix_values<KArg1>(k1: KArg1) -> storage::PrefixIterator<V>
Expand Down
2 changes: 1 addition & 1 deletion frame/support/src/storage/generator/nmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ where
where
K: HasKeyPrefix<KP>,
{
unhashed::contains_prefix(&Self::storage_n_map_partial_key(partial_key))
unhashed::contains_prefixed_key(&Self::storage_n_map_partial_key(partial_key))
}

fn iter_prefix_values<KP>(partial_key: KP) -> PrefixIterator<V>
Expand Down
5 changes: 4 additions & 1 deletion frame/support/src/storage/unhashed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ pub fn clear_prefix(
MultiRemovalResults { maybe_cursor, backend: i, unique: i, loops: i }
}

pub fn contains_prefix(prefix: &[u8]) -> bool {
/// Returns `true` if the storage contains any key, which starts with a certain prefix,
/// and is longer than said prefix.
/// This means that a key which equals the prefix will not be counted.
pub fn contains_prefixed_key(prefix: &[u8]) -> bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cheme I hope this is fine now

Copy link
Contributor

@cheme cheme Jan 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 (I am not really good at getting to the right api but looks fine, would have prefer a more explicit name as I never read the doc at first, but that's me :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for some context, @shawntabrizi approved the api and doc 😺

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, if you look above, you will see a bunch of APIs for acting on one key, like clear_prefix, which use the same term and parameter.

match sp_io::storage::next_key(prefix) {
Some(key) => key.starts_with(prefix),
None => false,
Expand Down