Trait frame_support::storage::StoragePrefixedMap

source ·
pub trait StoragePrefixedMap<Value: FullCodec> {
    // Required methods
    fn pallet_prefix() -> &'static [u8] ;
    fn storage_prefix() -> &'static [u8] ;

    // Provided methods
    fn final_prefix() -> [u8; 32] { ... }
    fn remove_all(limit: Option<u32>) -> KillStorageResult { ... }
    fn clear(limit: u32, maybe_cursor: Option<&[u8]>) -> MultiRemovalResults { ... }
    fn iter_values() -> PrefixIterator<Value>  { ... }
    fn translate_values<OldValue: Decode, F: FnMut(OldValue) -> Option<Value>>(
        f: F,
    ) { ... }
}
Expand description

Trait for maps that store all its value after a unique prefix.

By default the final prefix is:

Twox128(pallet_prefix) ++ Twox128(storage_prefix)

Required Methods§

source

fn pallet_prefix() -> &'static [u8]

Pallet prefix. Used for generating final key.

source

fn storage_prefix() -> &'static [u8]

Storage prefix. Used for generating final key.

Provided Methods§

source

fn final_prefix() -> [u8; 32]

Final full prefix that prefixes all keys.

source

fn remove_all(limit: Option<u32>) -> KillStorageResult

👎Deprecated: Use clear instead

Remove all values in the overlay and up to limit in the backend.

All values in the client overlay will be deleted, if there is some limit then up to limit values are deleted from the client backend, if limit is none then all values in the client backend are deleted.

§Note

Calling this multiple times per block with a limit set leads always to the same keys being removed and the same result being returned. This happens because the keys to delete in the overlay are not taken into account when deleting keys in the backend.

source

fn clear(limit: u32, maybe_cursor: Option<&[u8]>) -> MultiRemovalResults

Attempt to remove all items from the map.

Returns MultiRemovalResults to inform about the result. Once the resultant maybe_cursor field is None, then no further items remain to be deleted.

NOTE: After the initial call for any given map, it is important that no further items are inserted into the map. If so, then the map may not be empty when the resultant maybe_cursor is None.

§Limit

A limit must always be provided through in order to cap the maximum amount of deletions done in a single call. This is one fewer than the maximum number of backend iterations which may be done by this operation and as such represents the maximum number of backend deletions which may happen. A limit of zero implies that no keys will be deleted, though there may be a single iteration done.

§Cursor

A cursor may be passed in to this operation with maybe_cursor. None should only be passed once (in the initial call) for any given storage map. Subsequent calls operating on the same map should always pass Some, and this should be equal to the previous call result’s maybe_cursor field.

source

fn iter_values() -> PrefixIterator<Value>

Iter over all value of the storage.

NOTE: If a value failed to decode because storage is corrupted then it is skipped.

source

fn translate_values<OldValue: Decode, F: FnMut(OldValue) -> Option<Value>>(f: F)

Translate the values of all elements by a function f, in the map in no particular order. By returning None from f for an element, you’ll remove it from the map.

NOTE: If a value fail to decode because storage is corrupted then it is skipped.

§Warning

This function must be used with care, before being updated the storage still contains the old type, thus other calls (such as get) will fail at decoding it.

§Usage

This would typically be called inside the module implementation of on_runtime_upgrade.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<Prefix, Hasher1, Key1, Hasher2, Key2, Value, QueryKind, OnEmpty, MaxValues> StoragePrefixedMap<Value> for StorageDoubleMap<Prefix, Hasher1, Key1, Hasher2, Key2, Value, QueryKind, OnEmpty, MaxValues>
where Prefix: StorageInstance, Hasher1: StorageHasher, Hasher2: StorageHasher, Key1: FullCodec, Key2: FullCodec, Value: FullCodec, QueryKind: QueryKindTrait<Value, OnEmpty>, OnEmpty: Get<QueryKind::Query> + 'static, MaxValues: Get<Option<u32>>,

source§

impl<Prefix, Hasher, Key, Value, QueryKind, OnEmpty, MaxValues> StoragePrefixedMap<Value> for StorageMap<Prefix, Hasher, Key, Value, QueryKind, OnEmpty, MaxValues>
where Prefix: StorageInstance, Hasher: StorageHasher, Key: FullCodec, Value: FullCodec, QueryKind: QueryKindTrait<Value, OnEmpty>, OnEmpty: Get<QueryKind::Query> + 'static, MaxValues: Get<Option<u32>>,

source§

impl<Prefix, Key, Value, QueryKind, OnEmpty, MaxValues> StoragePrefixedMap<Value> for StorageNMap<Prefix, Key, Value, QueryKind, OnEmpty, MaxValues>
where Prefix: StorageInstance, Key: KeyGenerator, Value: FullCodec, QueryKind: QueryKindTrait<Value, OnEmpty>, OnEmpty: Get<QueryKind::Query> + 'static, MaxValues: Get<Option<u32>>,