Skip to content

Commit

Permalink
revert if next proposal set and current proposal not 0
Browse files Browse the repository at this point in the history
  • Loading branch information
arr00 committed Nov 4, 2024
1 parent 9063080 commit 0521101
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions contracts/governance/extensions/GovernorSequentialProposalId.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pragma solidity ^0.8.20;
import {Governor} from "../Governor.sol";

abstract contract GovernorSequentialProposalId is Governor {
error NextProposalIdCanOnlyBeSetOnce();

uint256 private _numberOfProposals;
mapping(uint256 proposalHash => uint256 proposalId) private _proposalIds;

Expand All @@ -19,4 +21,12 @@ abstract contract GovernorSequentialProposalId is Governor {
uint256 storedProposalId = _proposalIds[proposalHash];
return storedProposalId == 0 ? (_proposalIds[proposalHash] = ++_numberOfProposals) : storedProposalId;
}

/**
* @dev Internal function to set the sequential proposal ID for the next proposal. This is helpful for transitioning from another governing system.
*/
function _setNextProposalId(uint256 nextProposalId) internal virtual {
if (_numberOfProposals != 0) revert NextProposalIdCanOnlyBeSetOnce();
_numberOfProposals = nextProposalId - 1;
}
}

0 comments on commit 0521101

Please sign in to comment.