Skip to content

Instantly share code, notes, and snippets.

@fortmarek
Created February 28, 2020 16:02
Show Gist options
  • Save fortmarek/b9407779ef905be552ddcb83a6d597b4 to your computer and use it in GitHub Desktop.
Save fortmarek/b9407779ef905be552ddcb83a6d597b4 to your computer and use it in GitHub Desktop.
Contract init
import smartpy as sp
class Ballot(sp.Contract):
def __init__(self, name, manager, candidates, voters, numberOfVotes):
initialBallot = {}
for candidate in candidates:
# Initializing initialBallot where we save `candidateName` and set `numberOfVotes` to zero
initialBallot[candidate[0]] = sp.record(candidateName = candidate[1], numberOfVotes = 0)
initialVoters = { }
for voter in voters:
# For every voter set their remaining votes to maximum
initialVoters[voter] = numberOfVotes
self.init(name = name, manager = manager, ballot = initialBallot, voters = initialVoters, hasEnded = False, totalNumberOfVotes = 0, votesPerVoter = numberOfVotes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment