I can see we have the option to get the values by using their keys one by one using get(), but is there any way to get all the pairs together wrapped in an iterator so that we don't need to hit the get() multiple times?
1 Answer
From the best of my knowledge there is no utility to do it, you are limited to OffchainStorage
trait.
Technically, the offchain storage directly writes to the underlying db column (just prefixing the key).
So rocksdb user can iterate on that, but that is not a good solution as paritydb users cannot (it would need to switch paritydb to an ordered column which is not a light change).
Depending on your use case it may be possible to keep trace of order at a higher level (like storing a linked list or other), but that would be slow and a bit costy. (in some case it can be a best choice, when you need to handle concurrent access and add some mutex like protection with compare_and_set
).
Can also think of rolling out your own backend, but then you cannot access it with the standard rpc (so probably no existing ui can access it).