HW19: Voting

Problem statement

Implement a smart contract for voting.

Example scenario

A high school class has to decide whether they should participate in a national competition. They decide they will vote on the issue.

The teacher creates a contract, submitting a description of the question, its hash value, and a deadline a week from now. Then the teacher proceeds to register all students of the class as participants.

In the following week, some or all of the students can vote "yes" or "no". In the end, 20 of 30 students have voted, 16 for "yes", 4 for "no".

After the deadline, anyone can read the result. As 16/30 > 50% of students voted "yes", the end result is also "yes".

Contract interface

Contract skeleton

pragma solidity ^0.4.21;

contract SingleUseVote {

    // <contract_variables>

    // </contract_variables>

    function SingleUseVote(string link, string hash, uint256 deadline) public
    {
        // TODO
    }

    function registerParticipant(address participant) public {
        // TODO
    }

    function vote(bool voteYes) public {
        // TODO
    }

    function getResult() public view returns (bool) {
        // TODO
    }

}