Skip to content

Commit

Permalink
feat: CCIP-2594 optimise pagination function
Browse files Browse the repository at this point in the history
  • Loading branch information
defistar committed Jul 11, 2024
1 parent 0046c84 commit d05af33
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions contracts/src/v0.8/ccip/capability/CCIPConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,16 @@ contract CCIPConfig is ITypeAndVersion, ICapabilityConfiguration, OwnerIsCreator
uint256 pageSize
) external view returns (CCIPConfigTypes.ChainConfigInfo[] memory) {
uint256 totalItems = s_remoteChainSelectors.length(); // Total number of chain selectors
if (pageSize == 0 || pageIndex * pageSize >= totalItems) {
uint256 startIndex = pageIndex * pageSize;

if (pageSize == 0 || startIndex >= totalItems) {
return new CCIPConfigTypes.ChainConfigInfo[](0); // Return an empty array if pageSize is 0 or pageIndex is out of bounds
}

uint256 startIndex = pageIndex * pageSize;
uint256 endIndex = startIndex + pageSize > totalItems ? totalItems : startIndex + pageSize;
uint256 endIndex = startIndex + pageSize;
if (endIndex > totalItems) {
endIndex = totalItems;
}

CCIPConfigTypes.ChainConfigInfo[] memory paginatedChainConfigs =
new CCIPConfigTypes.ChainConfigInfo[](endIndex - startIndex);
Expand Down

0 comments on commit d05af33

Please sign in to comment.