I have a very basic question - ink! now has a Mapping struct for key-value pairs
. It seems it does not implement the Iterator
trait?
-
1You can check this answer: substrate.stackexchange.com/questions/863/…– P.OssunMay 12, 2022 at 12:46
-
1Vec is heap-allocated, what if I have a really large collection?– fbielejecMay 12, 2022 at 12:58
-
In the real reality, the question is NOT simple.– Tomasz WaszczykMay 29 at 14:17
2 Answers
There is no way to iterate over a Mapping
from a contract. We intent to implement this functionality soon. For more information check out this issue: https://github.com/paritytech/substrate/issues/11410
If you try to iterate over a mapping off chain (from a UI for example) you could use the childState_getKeys
RPC to list the keys of the child trie used by the contract in question.
There are any alternatives for HashMap
today Mapping
that developers can use and have possibility to iterate?