Storage
Here you will find snippets for working with storage.
#
How do I check for storage existence?In the metadata, for each storage item a fallback is provided. This means that when an entry does not exist, the fallback (which is the default value for the type) will be provided. This means, that querying for a non-existent key (unless an option), will yield a value -
In the second case, the non-existent prefs returns the default/fallback value for the storage item. So in this case we don't know if the value is set to 0 or unset. Existence can be checked by using the storage size, which would be zero if nothing is stored.
#
How do I use .entries()/.keys() on double maps?As explained elsewhere each map-type storage entry exposes the entries/keys helpers to retrieve the whole list. In the case of double maps, with the addition of a single argument, you can retrieve either all entries or a subset based on the first map key.
In both these cases, entries/keys operate the same way, .entries()
retrieving (StorageKey, Codec)[]
and .keys()
retrieving StorageKey[]
While we can retrieve only the keys for a specific era, using a argument for the first part of the doublemap (as defined here, an EraIndex
) -