Skip to content

Instantly share code, notes, and snippets.

@RJ-software-outsourcing
Last active January 6, 2019 07:11
Show Gist options
  • Save RJ-software-outsourcing/a0c368ad0d85461bb6d917ad5e032c66 to your computer and use it in GitHub Desktop.
Save RJ-software-outsourcing/a0c368ad0d85461bb6d917ad5e032c66 to your computer and use it in GitHub Desktop.
Blank template for Election
pragma solidity ^0.4.25;
contract Election {
address owner; // Address of the contract owner
bool public isVoting = false; // isVoting should be true when voting starts
uint public round = 0; // round number should be increased when new election starts
struct Candidate {
uint vote;
string name;
bool isRegistered;
uint candidateNumber;
}
address[] public candiatesList;
mapping(uint => mapping(address => Candidate)) public candidateData;
mapping(uint => mapping(address => bool)) public voted;
/* Following will be needed for extra bonuse */
uint public guaranteedDeposit = 0;
uint public refundRatio = 5; // In order to get refund, candidate's votes must be more than 1/5
/*
!IMPORTANT!
Events should be fired at the correct moment otherwise DAPP wont work normally
*/
event voteStart(uint round); // When vote starts
event elected(uint round, address candidate, string name, uint vote); // When someone is elected
event reset(uint round); // When ocntract owner resets the election
event registered(uint round, address candidate); // When someone registered
event voteCandidate(uint round, address candidate, address voter); // When someone voted
/* events for extrea bonus */
event sponsorCandidate(uint round, address candidate, string name, address sponsor, uint amount); // When someone sponsor a candidate
event refund(address candidate, string name, uint amount, uint round); // When a candidates gets refunded
constructor() public {
}
/* Stop voting and start registration */
function resetElection() public {
}
/* Stop registration and start voting */
function startVoting() public {
}
/* Vote a candidate */
function vote(address candidateAddr) public {
}
/* register as a candidate */
function register(string name) public payable {
}
function getCandidatesList() public view returns (address[]) {
return candiatesList;
}
// Extra bonus
/* sponsor a candidate */
function sponsor(address candidateAddr) public payable {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment