Iterate over storagemap

Let’s assume I cannot iterate over a StorageMap (given it’s a map).

Let’s further assume I have knowledge of how many keys I have.
What would be a good approach to have something iterable in a sway contract?

So for example:

  • I Have a list of shares by address
  • On a distribution function I want to distribute to all shareholders

How would I achieve that?

Is it possible to do something like so:

shares: StorageVec<(Address, u64)> = StorageVec {},

in storage and iterate over it?

Solved using:

let mut i = 0;
while i < storage.shares.len() {
...
i +=1;
}

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.