Skip to content

feat(governance): add multi-choice proposal support#461

Open
devEunicee wants to merge 1 commit into
PrincessnJoy:mainfrom
devEunicee:feature/298-multi-choice-proposals
Open

feat(governance): add multi-choice proposal support#461
devEunicee wants to merge 1 commit into
PrincessnJoy:mainfrom
devEunicee:feature/298-multi-choice-proposals

Conversation

@devEunicee

Copy link
Copy Markdown
Contributor

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.rs

  • Add Vote::Choice(u32) variant — carries the 0-based choice index
  • Add ContractError::InvalidChoice = 28
  • Add choices: Vec<String> and winning_choice: Option<u32> fields to Proposal

contracts/governance/src/storage.rs

  • Add PersistentKey::ChoiceVotes(proposal_id, index) for per-choice vote tallies
  • Add choice_votes / set_choice_votes accessors

contracts/governance/src/lib.rs

  • create_multi_choice_proposal() — creates a proposal with 2–10 named choices
  • get_choice_votes() — query accumulated weight for any choice index
  • cast_vote() — routes Vote::Choice to per-index tally; rejects Yes/No/Abstain on multi-choice proposals (and vice-versa)
  • finalise() — multi-choice uses first-past-the-post; quorum check on total participation; sets winning_choice

contracts/governance/src/test.rs

  • 5 new tests: passing proposal with correct winner, quorum failure, invalid vote type rejection, out-of-bounds index, minimum choices validation

Backward Compatibility

Standard Yes/No/Abstain proposals are unaffected. New choices field defaults to empty Vec for existing proposals.

- 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement multi-choice proposal support beyond Yes/No/Abstain

1 participant