Created
April 22, 2016 03:09
-
-
Save joeykrug/98e830ba420bf0754e6e6f9bcc4f9961 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# key is a voter address | |
data Voter[](weight, voted, delegatedTo, vote) | |
# key is a bill id | |
data Bill[](number, congress, billType, yesCount, noCount, chairperson) | |
macro TRUE: 1 | |
# Error -1: bill already exists | |
def newBallot(number, congress, billType): | |
billid = array(1) | |
billid[0] = number + congress + billType | |
billid = sha256(billid, items=1) | |
if(self.Bill[billid].chairperson): | |
return(-1) | |
self.Bill[billid].number = number | |
self.Bill[billid].congress = congress | |
self.Bill[billid].billType = billType | |
self.Bill[billid].chairperson = msg.sender | |
return(billid) | |
def vote(billid, vote): | |
if(self.Voter[msg.sender].voted): | |
return(0) | |
self.Voter[msg.sender].voted = TRUE | |
self.Voter[msg.sender].vote = vote | |
if(vote): | |
self.Bill[billid].yesCount += self.Voter[msg.sender].weight | |
else: | |
self.Bill[billid].yesCount += self.Voter[msg.sender].weight | |
return(1) | |
def giveRightToVote(voter, billid): | |
if(msg.sender != self.Bill[billid].chairperson || self.Voter[voter].voted): | |
return(0) | |
self.Voter[voter].weight = 1 | |
return(1) | |
def getBillNumber(billid): | |
return(self.Bill[billid].number) | |
def getCongress(billid): | |
return(self.Bill[billid].congress) | |
def getBillType(billid): | |
return(self.Bill[billid].billType) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment