Skip to content

Add 'paginated' getters for EnumerableSet and Map #2390

@nventuro

Description

@nventuro

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:

function list(
    EnumerableSet.AddressSet storage set,
    uint256 start,
    uint256 end
) internal view returns (address[] memory) {
    address[] memory elements = new address[](end - start);

    for (uint256 i = 0; i < elements.length; ++i) {
        elements[i] = set.at(i + start);
    }

    return elements;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew contracts, functions, or helpers.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions