Skip to content

Commit 30308c9

Browse files
committed
added proposal existence check logic
1 parent 5090d98 commit 30308c9

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/ProposalManager.sol

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ pragma solidity ^0.8.28;
44

55
error Not_Admin();
66
error INVALID_PROPOSAL_STATUS();
7+
error PROPOSAL_DOES_NOT_EXIST();
8+
79

810
contract ProposalManager {
911

@@ -38,6 +40,11 @@ constructor(){
3840
_;
3941
}
4042

43+
modifier proposalExists(uint256 proposalId) {
44+
if(proposalCount > 0 && proposalId != proposalCount) revert PROPOSAL_DOES_NOT_EXIST();
45+
_;
46+
}
47+
4148
event proposalCreated(address indexed proposer, address recipient, uint amount);
4249
event proposalApproved(uint indexed proposer_id);
4350
event proposalexecuted(uint indexed proposer);
@@ -56,15 +63,15 @@ constructor(){
5663
emit proposalCreated(msg.sender, _recipient, _amount);
5764
}
5865

59-
function approveProposal(uint _id)external onlyAdmin {
66+
function approveProposal(uint _id)external onlyAdmin proposalExists(_id){
6067
Proposal storage proposal = proposals[_id];
6168
if(proposal.status != ProposalStatus.CREATED) revert INVALID_PROPOSAL_STATUS();
6269
proposals[_id].status = ProposalStatus.APPROVED;
6370

6471
emit proposalApproved(_id);
6572
}
6673

67-
function executeProposal(uint _id)external onlyAdmin {
74+
function executeProposal(uint _id)external onlyAdmin proposalExists(_id){
6875
Proposal storage proposal = proposals[_id];
6976
if(proposal.status != ProposalStatus.APPROVED) revert INVALID_PROPOSAL_STATUS();
7077
proposals[_id].status = ProposalStatus.EXECUTED;

0 commit comments

Comments
 (0)