Skip to content

Commit 65155f2

Browse files
committed
refactor: require statements to internal functions
1 parent 447a396 commit 65155f2

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/StakeRegistry.sol

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,17 @@ contract StakeRegistry is StakeRegistryStorage {
2424
using BitmapUtils for *;
2525

2626
modifier onlyRegistryCoordinator() {
27-
require(
28-
msg.sender == address(registryCoordinator),
29-
"StakeRegistry.onlyRegistryCoordinator: caller is not the RegistryCoordinator"
30-
);
27+
_checkRegistryCoordinator();
3128
_;
3229
}
3330

3431
modifier onlyCoordinatorOwner() {
35-
require(msg.sender == IRegistryCoordinator(registryCoordinator).owner(), "StakeRegistry.onlyCoordinatorOwner: caller is not the owner of the registryCoordinator");
32+
_checkRegistryCoordinatorOwner();
3633
_;
3734
}
3835

3936
modifier quorumExists(uint8 quorumNumber) {
40-
require(_quorumExists(quorumNumber), "StakeRegistry.quorumExists: quorum does not exist");
37+
_checkQuorumExists(quorumNumber);
4138
_;
4239
}
4340

@@ -74,7 +71,7 @@ contract StakeRegistry is StakeRegistryStorage {
7471
for (uint256 i = 0; i < quorumNumbers.length; i++) {
7572

7673
uint8 quorumNumber = uint8(quorumNumbers[i]);
77-
require(_quorumExists(quorumNumber), "StakeRegistry.registerOperator: quorum does not exist");
74+
_checkQuorumExists(quorumNumber);
7875

7976
// Retrieve the operator's current weighted stake for the quorum, reverting if they have not met
8077
// the minimum.
@@ -121,7 +118,7 @@ contract StakeRegistry is StakeRegistryStorage {
121118
*/
122119
for (uint256 i = 0; i < quorumNumbers.length; i++) {
123120
uint8 quorumNumber = uint8(quorumNumbers[i]);
124-
require(_quorumExists(quorumNumber), "StakeRegistry.deregisterOperator: quorum does not exist");
121+
_checkQuorumExists(quorumNumber);
125122

126123
// Update the operator's stake for the quorum and retrieve the shares removed
127124
int256 stakeDelta = _recordOperatorStakeUpdate({
@@ -161,7 +158,7 @@ contract StakeRegistry is StakeRegistryStorage {
161158
*/
162159
for (uint256 i = 0; i < quorumNumbers.length; i++) {
163160
uint8 quorumNumber = uint8(quorumNumbers[i]);
164-
require(_quorumExists(quorumNumber), "StakeRegistry.updateOperatorStake: quorum does not exist");
161+
_checkQuorumExists(quorumNumber);
165162

166163
// Fetch the operator's current stake, applying weighting parameters and checking
167164
// against the minimum stake requirements for the quorum.
@@ -697,7 +694,7 @@ contract StakeRegistry is StakeRegistryStorage {
697694
uint32[] memory indices = new uint32[](quorumNumbers.length);
698695
for (uint256 i = 0; i < quorumNumbers.length; i++) {
699696
uint8 quorumNumber = uint8(quorumNumbers[i]);
700-
require(_quorumExists(quorumNumber), "StakeRegistry.getTotalStakeIndicesAtBlockNumber: quorum does not exist");
697+
_checkQuorumExists(quorumNumber);
701698
require(
702699
_totalStakeHistory[quorumNumber][0].updateBlockNumber <= blockNumber,
703700
"StakeRegistry.getTotalStakeIndicesAtBlockNumber: quorum has no stake history at blockNumber"
@@ -712,4 +709,19 @@ contract StakeRegistry is StakeRegistryStorage {
712709
}
713710
return indices;
714711
}
712+
713+
function _checkRegistryCoordinator() internal view {
714+
require(
715+
msg.sender == address(registryCoordinator),
716+
"StakeRegistry.onlyRegistryCoordinator: caller is not the RegistryCoordinator"
717+
);
718+
}
719+
720+
function _checkRegistryCoordinatorOwner() internal view {
721+
require(msg.sender == IRegistryCoordinator(registryCoordinator).owner(), "StakeRegistry.onlyCoordinatorOwner: caller is not the owner of the registryCoordinator");
722+
}
723+
724+
function _checkQuorumExists(uint8 quorumNumber) internal view {
725+
require(_quorumExists(quorumNumber), "StakeRegistry.quorumExists: quorum does not exist");
726+
}
715727
}

0 commit comments

Comments
 (0)