mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-21 13:21:03 +00:00
implemented contains_prefix for StorageDoubleMap and StorageNMap (#13232)
* implemented `contains_prefix` for StorageDoubleMap and StorageNMap Signed-off-by: muraca <mmuraca247@gmail.com> * match prefix to next_key Signed-off-by: muraca <mmuraca247@gmail.com> * warning unexpected behaviour with empty keys Signed-off-by: muraca <mmuraca247@gmail.com> * clarifications for unhashed::contains_prefixed_key Signed-off-by: muraca <mmuraca247@gmail.com> * added tests for StorageNMap Signed-off-by: muraca <mmuraca247@gmail.com> --------- Signed-off-by: muraca <mmuraca247@gmail.com>
This commit is contained in:
@@ -154,6 +154,16 @@ pub fn clear_prefix(
|
||||
MultiRemovalResults { maybe_cursor, backend: i, unique: i, loops: i }
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
match sp_io::storage::next_key(prefix) {
|
||||
Some(key) => key.starts_with(prefix),
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Get a Vec of bytes from storage.
|
||||
pub fn get_raw(key: &[u8]) -> Option<Vec<u8>> {
|
||||
sp_io::storage::get(key).map(|value| value.to_vec())
|
||||
|
||||
Reference in New Issue
Block a user