Skip to content

Commit 7a77bf1

Browse files
committed
add getActivePayers paginated
1 parent c249353 commit 7a77bf1

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

contracts/src/Payer.sol

+28
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,34 @@ contract Payer is Initializable, AccessControlUpgradeable, UUPSUpgradeable, Paus
459459
return _getPayerStorage().payers[payer];
460460
}
461461

462+
/**
463+
* @inheritdoc IPayer
464+
*/
465+
function getActivePayers(uint256 offset, uint256 limit) external view returns (Payer[] memory payers, bool hasMore) {
466+
PayerStorage storage $ = _getPayerStorage();
467+
468+
uint256 totalCount = $.activePayers.length();
469+
470+
if (offset >= totalCount) revert OutOfBounds();
471+
472+
uint256 count = totalCount - offset;
473+
if (count > limit) {
474+
count = limit;
475+
hasMore = true;
476+
} else {
477+
hasMore = false;
478+
}
479+
480+
payers = new Payer[](count);
481+
482+
for (uint256 i = 0; i < count; i++) {
483+
address payerAddress = $.activePayers.at(offset + i);
484+
payers[i] = $.payers[payerAddress];
485+
}
486+
487+
return (payers, hasMore);
488+
}
489+
462490
/**
463491
* @inheritdoc IPayer
464492
*/

contracts/src/interfaces/IPayer.sol

+15
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ interface IPayerErrors {
162162

163163
/// @notice Error thrown when deleting a payer has failed.
164164
error FailedToDeletePayer();
165+
166+
/// @notice Error thrown when the offset is out of bounds.
167+
error OutOfBounds();
165168
}
166169

167170
/**
@@ -405,6 +408,18 @@ interface IPayer is IERC165, IPayerEvents, IPayerErrors {
405408
*/
406409
function getPayer(address payer) external view returns (Payer memory payerInfo);
407410

411+
/**
412+
* @notice Returns all active payers in a paginated response.
413+
* @param offset Number of payers to skip before starting to return results.
414+
* @param limit Maximum number of payers to return.
415+
* @return payers The payer information.
416+
* @return hasMore True if there are more payers to retrieve.
417+
*/
418+
function getActivePayers(uint256 offset, uint256 limit)
419+
external
420+
view
421+
returns (Payer[] memory payers, bool hasMore);
422+
408423
/**
409424
* @notice Checks if a given address is an active payer.
410425
* @param payer The address to check.

0 commit comments

Comments
 (0)