2

So currently, I need to iterate over the StorageMap defined like this:

pub(super) type Report<T: Config> = StorageMap<_, Blake2_128Concat, (T::AccountId, HealthRound), Reports<T::AccountId,HealthRound>, OptionQuery>;

And to solve this, I found IterableStorageMap in frame_support::storage, So I defined it like this

pub(super) type Report<T: Config> = IterableStorageMap<_, Blake2_128Concat, (T::AccountId, HealthRound), Reports<T::AccountId,HealthRound>, OptionQuery>;

Upon doing this, I get an error like this

error: Invalid pallet::storage, expected ident: `StorageValue` or `StorageMap` or `StorageDoubleMap` or `StorageNMap` in order to expand metadata, found `IterableStorageMap`.

Am I missing something? It would be of great help if someone who has already used this can explain how to initialize this type of StorageItem.

1 Answer 1

3

You might not need to use an explicit IterableStorageMap as a normal StorageMap supports iterating both over the keys as well as they values, see the Documentation:

  1. Either via the KeyPrefixIterator by calling Report::<T>::iter_keys()
  2. Or via the PrefixIterator by calling Report::<T>::iter_values()

for

pub(super) type Report<T: Config> = StorageMap<_, Blake2_128Concat, (T::AccountId, HealthRound), Reports<T::AccountId,HealthRound>, OptionQuery>;
2
  • 1
    To add to this, IterableStorageMap is a trait, not a type. The concrete StorageMap exposed by frame_support is an IterableStorageMap, so this is why it has iter_keys and iter_values methods.
    – rob
    Apr 7, 2022 at 18:10
  • 1
    So you don't need to update the type of the storage map, but just ensure that the IterableStorageMap trait is in scope so you can use its methods by importing IterableStorageMap.
    – rob
    Apr 7, 2022 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.