Quadratic Voting

# Constant
data voters[]
data num_voters
data contract
data timelimit

# Keep track of how many votes each voter has cast
data vote_counts[]

# Creates a new vote that executes the specified contract if it passes.
def initialize(voters, num_voters, contract, timelimit):
    self.voters = voters
    self.num_voters = num_voters
    self.contract = contract
    self.timelimit = timelimit

def count_votes():
    i = 0
    total_votes = 0
    while i < self.num_voters:
        total_votes += self.vote_counts[i]
    if total_votes > 0:

def receive_vote_request(num_votes):
    voter = msg.sender  # TODO: check if the voter is in voters[]
    past_vote_cost = self.vote_counts[voter]^2
    total_vote_cost = past_vote_cost + msg.value  # the total cost of the final number of votes
    extra_payment =  total_vote_cost - (self.vote_counts[voter] + num_votes)^2
    if extra_payment >= 0:  # enough money was sent
        # If sender paid more than necessary, refund the remainder
        if extra_payment > 0:
            send(msg.sender, extra_payment)
        # Not enough money was sent, so return all money to sender
        send(msg.sender, msg.value)
    # TODO: handle the vote

Serpent contract for Ethereum

Quadratic Voting in Serpent.


Note: Your changes won't be saved, because not Logged-in.

Create your own Contract