Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(examples): Voting Realm: A Bitmap and Nonce-based Approach #2225

Closed
wants to merge 57 commits into from

Conversation

linhpn99
Copy link
Contributor

@linhpn99 linhpn99 commented May 28, 2024

Simple UseCase Description :

1. Initialize the Contract :

  • Call the Init function to set up the contract.
  • This initializes the proposal and voter indices and creates empty AVL trees for proposals and registered voters.

2. Create a Proposal

  • A user creates a proposal by calling CreateProposal with the title, number of participants, and max votes per user.
  • The function returns a unique proposal ID.

3. Register as a Voter

  • Users must register as voters by calling RegisterVoter.
  • Each user receives a unique voter ID upon registration.

4. Cast a Vote

  • Registered voters can cast votes on proposals by calling Vote with the proposal ID and their voter ID.
  • The contract checks if the voter is registered, if the proposal exists, if the proposal is open for voting, and if the voter has not exceeded their vote limit.
  • If all conditions are met, the vote is recorded, and the vote count for the proposal is incremented.

5. Get Vote Count

  • Anyone can check the current vote count for a proposal by calling GetVotes with the proposal ID.
  • The function returns the total votes the proposal has received.

From issue : #2119

Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

linhpn99 and others added 30 commits May 16, 2024 14:31
Co-authored-by: Manfred Touron <94029+moul@users.noreply.github.com>
Co-authored-by: Manfred Touron <94029+moul@users.noreply.github.com>
Co-authored-by: Manfred Touron <94029+moul@users.noreply.github.com>
Co-authored-by: Manfred Touron <94029+moul@users.noreply.github.com>
Co-authored-by: Manfred Touron <94029+moul@users.noreply.github.com>
@linhpn99 linhpn99 requested a review from mvertes May 28, 2024 08:53
@github-actions github-actions bot added the 🧾 package/realm Tag used for new Realms or Packages. label May 28, 2024
@linhpn99 linhpn99 marked this pull request as draft May 28, 2024 08:53
@linhpn99
Copy link
Contributor Author

@moul Here's a simple demo (still under development). I am using newly added packages. Please let me know if anything is unclear

@linhpn99 linhpn99 changed the title Voting Realm: A Bitmap and Nonce-based Approach feat(examples): Voting Realm: A Bitmap and Nonce-based Approach May 28, 2024
title string // Title is the name or description of the proposal
votes uint64 // Votes is the total number of votes the proposal has received
voters *bitmap.Bitmap // Voters is a bitmap tracking whether users have voted
userVoteCount *nonce.Manager // UserVoteCount maps user addresses to the number of votes they have cast
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use an avl.Tree // std.Address -> *int without needing to update the tree each time you increment the pointed integer.

@linhpn99 linhpn99 closed this Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants