This canister implements a voting system where the weight of a voter's vote is determined by their contribution to the poll.
- createPoll(payload: PollPayload): Result<Poll, string>
- Anyone can create a new poll with the following information: Name of the poll, Voting options and Voting deadline.
- getPollByName(name: string): Result<Poll, string>
- Anyone can get information about a poll by its name. Only the owner of the poll can get detailed information.
- getAllPolls(): Vec<Poll>
- Anyone can get information about all polls. Only the owner of the polls can get detailed information.
- registerVoterToPoll(pollname: string, votername: string): Result<Voter, string>
- Anyone can register themselves as a voter on the poll. The initial value of the voter's contribution is 1.0.
- changeVoterContribution(pollname: string, votername: string, contribution: float32): Result<Voter, string>
- Only the owner of the poll can change the contribution of a voter. The owner's own contribution cannot be changed.
- voteToPoll(pollname: string, votername: string, option: string): Result<VotingDetail, string>
- Only registered voters can vote to the poll.
- getVotingResult(name: string): Result<Vec<string>, string>
- After the poll closes, the owner of the poll and the voters can get the voting results.
- removeExpiredPolls(overTime: int32): Vec<Poll>
- Remove polls that have expired the voting deadline.
The tests are written in bats. I used bats because I did not know how to change the principal of the canister caller in 'azle/test'.
- Bats hangs on last test, use Ctrl-C to continue.
Contributions are welcome. Please open an issue or submit a pull request.