Skip to content
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

feat(registry): add getallregistrants #158

Merged
merged 4 commits into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion bolt-contracts/src/contracts/BoltRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ contract BoltRegistry is IBoltRegistry {
// Mapping to hold the registrants
mapping(address => Registrant) public registrants;

// Array to hold operator addresses
address[] public operators;
thedevbirb marked this conversation as resolved.
Show resolved Hide resolved

// Mapping that holds the relationship between validator index and operator address
mapping(uint64 => address) public delegations;

Expand Down Expand Up @@ -47,6 +50,8 @@ contract BoltRegistry is IBoltRegistry {
metadata
);

operators.push(msg.sender);

thedevbirb marked this conversation as resolved.
Show resolved Hide resolved
// Set the delegations
for (uint256 i = 0; i < validatorIndexes.length; i++) {
delegations[validatorIndexes[i]] = msg.sender;
Expand Down Expand Up @@ -92,6 +97,15 @@ contract BoltRegistry is IBoltRegistry {
revert CooldownNotElapsed();
}

// Remove operator from the operators array
for (uint256 i = 0; i < operators.length; i++) {
if (operators[i] == msg.sender) {
operators[i] = operators[operators.length - 1];
mempirate marked this conversation as resolved.
Show resolved Hide resolved
operators.pop();
break;
}
}

delete registrants[msg.sender];

for (uint256 i = 0; i < registrant.validatorIndexes.length; i++) {
Expand All @@ -106,7 +120,7 @@ contract BoltRegistry is IBoltRegistry {
/// @notice Check if an address is a based proposer opted into the protocol
/// @param _operator The address to check
/// @return True if the address is an active based proposer, false otherwise
function isActiveOperator(address _operator) external view returns (bool) {
function isActiveOperator(address _operator) public view returns (bool) {
return registrants[_operator].status == Status.ACTIVE;
}

Expand All @@ -129,4 +143,24 @@ contract BoltRegistry is IBoltRegistry {

revert NotFound();
}

function getAllRegistrants() external view returns (Registrant[] memory) {
uint256 activeCount = 0;
for (uint256 i = 0; i < operators.length; i++) {
if (isActiveOperator(operators[i])) {
activeCount++;
}
}

Registrant[] memory _registrants = new Registrant[](activeCount);
uint256 index = 0;
for (uint256 i = 0; i < operators.length; i++) {
if (isActiveOperator(operators[i])) {
_registrants[index] = registrants[operators[i]];
index++;
}
}

return _registrants;
}
}
Loading