feat(governance): add multi-choice proposal support#461
Open
devEunicee wants to merge 1 commit into
Open
Conversation
- Add Vote::Choice(u32) variant to Vote enum - Add InvalidChoice error code (28) - Add choices: Vec<String> and winning_choice: Option<u32> to Proposal - Add PersistentKey::ChoiceVotes(proposal_id, index) storage key - Add create_multi_choice_proposal() contract function (2-10 choices) - Add get_choice_votes() query function - cast_vote() routes Vote::Choice to per-index tally; rejects Yes/No/Abstain on multi-choice proposals and rejects Vote::Choice on standard proposals - finalise() uses first-past-the-post for multi-choice; sets winning_choice - Add 5 unit tests covering passing, quorum failure, invalid vote types, out-of-bounds index, and minimum choices validation Closes PrincessnJoy#298
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #298
Extends the governance contract to support proposals with more than three response types. Voters can now choose from any named list of options using a first-past-the-post outcome model.
Changes
contracts/governance/src/types.rsVote::Choice(u32)variant — carries the 0-based choice indexContractError::InvalidChoice = 28choices: Vec<String>andwinning_choice: Option<u32>fields toProposalcontracts/governance/src/storage.rsPersistentKey::ChoiceVotes(proposal_id, index)for per-choice vote tallieschoice_votes/set_choice_votesaccessorscontracts/governance/src/lib.rscreate_multi_choice_proposal()— creates a proposal with 2–10 named choicesget_choice_votes()— query accumulated weight for any choice indexcast_vote()— routesVote::Choiceto per-index tally; rejectsYes/No/Abstainon multi-choice proposals (and vice-versa)finalise()— multi-choice uses first-past-the-post; quorum check on total participation; setswinning_choicecontracts/governance/src/test.rsBackward Compatibility
Standard
Yes/No/Abstainproposals are unaffected. Newchoicesfield defaults to emptyVecfor existing proposals.