-
Notifications
You must be signed in to change notification settings - Fork 11.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 'paginated' getters for EnumerableSet and Map #2390
Comments
Hi @nventuro ! Thanks for the suggestion, it is really appreciated. The project owner will review your suggestion as soon as they can. Please wait until we have discussed this idea before writing any code or submitting a Pull Request, so we can go through the design beforehand. We don’t want you to waste your time! |
I would like to have some kind of listAll function function listAll(
EnumerableSet.AddressSet storage set
) internal view returns (address[] memory); |
Hello @ducquangkstn This was already requested many times, but the issue remains the same. AddressSet, and all the other sets, use a This would very gas expensive to do it onchain, and it feels like gettings elements on request using the |
Actually I think this is not that difficult using inline assembly:
From the docs, a storage array should always have an offset of 0, so we don't need to assign that. I did a quick test on remix and it seems to work. |
Bumping this. Contracts with EnumerableSet/Map variables that want to expose that data through getters currently have two options:
Option 1 is not recommended because
Note that I'm mainly thinking about off-chain purposes but the same downsides apply on-chain. A paginated getter would be the best of both worlds. You have to expose just one function, you can bound the array to whatever length you want, and you can just keep going until the array you get has shorter length than the page size that was requested. And you can safely and efficiently use it on-chain. |
The current API only provides access via
.length()
and.at()
. It'd be great to have a.list(start, end)
that returned a partial view of the set's elements.The reasoning behind making this a non-complete view is to let the caller decide how much gas they want to spend. Calls to
view
functions from off-chain sources (i.e.eth_call
) are also capped in gas, and a large enough set can cause them to fail.The implementation should be quite simple:
The text was updated successfully, but these errors were encountered: