Skip to content

Commit

Permalink
feat(passport): add crowdfund state changed event
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Lahaye <[email protected]>
  • Loading branch information
ChrisLahaye committed Feb 7, 2024
1 parent 43e4e82 commit f195fc7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions contracts/passport/CrowdfundV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ contract CrowdfundV1 is
revert Forbidden();
}

_setState(campaignId, State.EXECUTED);

unchecked {
_campaigns[campaignId].state = State.EXECUTED;
_campaigns[campaignId].unused = campaign.total - price;
}

Expand All @@ -99,8 +100,6 @@ contract CrowdfundV1 is
assignments_,
abi.encode(campaignId)
);

emit Execute(campaignId);
}

function fund(
Expand Down Expand Up @@ -141,7 +140,7 @@ contract CrowdfundV1 is
}

if (success) {
_campaigns[campaignId].state = State.CONFIRMED;
_setState(campaignId, State.CONFIRMED);

if (campaign.unused > 0) {
_asyncTransfer(campaign.creator, campaign.unused);
Expand Down Expand Up @@ -233,7 +232,7 @@ contract CrowdfundV1 is
}

function _refund(uint256 campaignId) internal {
_campaigns[campaignId].state = State.REFUNDED;
_setState(campaignId, State.REFUNDED);

address[] memory contributors_ = _campaigns[campaignId].contributors;
uint256 length = contributors_.length;
Expand All @@ -252,6 +251,12 @@ contract CrowdfundV1 is
}
}

function _setState(uint256 campaignId, State state_) internal {
_campaigns[campaignId].state = state_;

emit StateChanged(campaignId, state_);
}

modifier whenExists(uint256 campaignId) {
if (_campaigns[campaignId].creator == address(0)) {
revert NotFound();
Expand Down
2 changes: 1 addition & 1 deletion contracts/passport/ICrowdfundV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface ICrowdfundV1 {
uint256 campaignId
);
event Fund(uint256 indexed campaignId, uint256 amount);
event Execute(uint256 indexed campaignId);
event StateChanged(uint256 indexed campaignId, State state);

enum State {
PENDING,
Expand Down

0 comments on commit f195fc7

Please sign in to comment.