Skip to content

Commit

Permalink
refactor code for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
yuetloo committed May 22, 2024
1 parent 3d47629 commit 729eadc
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions contracts/contracts/ClrFund.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ contract ClrFund is OwnableUpgradeable, DomainObjs, Params {
error MaxRecipientsNotSet();
error NotInitialized();

modifier maciFactoryInitialized() {
if (address(maciFactory) == address(0)) revert InvalidMaciFactory();
if (maciFactory.maxRecipients() == 0) revert MaxRecipientsNotSet();
_;
}


/**
* @dev Initialize clrfund instance with MACI factory and round factory
Expand Down Expand Up @@ -141,26 +147,20 @@ contract ClrFund is OwnableUpgradeable, DomainObjs, Params {
emit UserRegistryChanged(address(_userRegistry));
}

/**
* @dev Set the max recipients in the recipient registry
*/
function _setMaxRecipients() private {
if (address(maciFactory) == address(0)) revert NotInitialized();
if (maciFactory.maxRecipients() == 0) revert MaxRecipientsNotSet();
recipientRegistry.setMaxRecipients(maciFactory.maxRecipients());
}

/**
* @dev Set recipient registry.
* @param _recipientRegistry Address of a recipient registry.
*/
function setRecipientRegistry(IRecipientRegistry _recipientRegistry)
external
onlyOwner
maciFactoryInitialized
{

recipientRegistry = _recipientRegistry;
_setMaxRecipients();

// Make sure that the max number of recipients is set correctly
recipientRegistry.setMaxRecipients(maciFactory.maxRecipients());

emit RecipientRegistryChanged(address(_recipientRegistry));
}
Expand Down Expand Up @@ -215,6 +215,7 @@ contract ClrFund is OwnableUpgradeable, DomainObjs, Params {
)
external
onlyOwner
maciFactoryInitialized
{
IFundingRound currentRound = getCurrentRound();
if (address(currentRound) != address(0) && !currentRound.isFinalized()) {
Expand All @@ -224,7 +225,7 @@ contract ClrFund is OwnableUpgradeable, DomainObjs, Params {
if (address(recipientRegistry) == address(0)) revert RecipientRegistryNotSet();

// Make sure that the max number of recipients is set correctly
_setMaxRecipients();
recipientRegistry.setMaxRecipients(maciFactory.maxRecipients());

// Deploy funding round and MACI contracts
address newRound = roundFactory.deploy(duration, address(this));
Expand Down

0 comments on commit 729eadc

Please sign in to comment.