Exemple #1
0
def getPublicKey(ballot):

    # Get the public key 'n'
    publicKeyResponse = geth.callFunction(ballot.address,
                                          'getPublicKeyN')['result']
    publicKeyN = geth.responseToPublicKey(publicKeyResponse)

    # Get the public key 'g'
    publicKeyResponse = geth.callFunction(ballot.address,
                                          'getPublicKeyG')['result']
    publicKeyG = geth.responseToPublicKey(publicKeyResponse)

    # Return a public key object
    return crypto.PublicKey(publicKeyN, publicKeyG)
Exemple #2
0
def getVotes(ballot):

    # Get the vote values for the selected ballot
    votesResponse = geth.callFunction(ballot.address, 'getVotes')['result']
    voteValues = geth.responseToVoteValues(votesResponse)

    # Get the candidate count
    candidateCount = getCandidateCount(ballot)

    # Initalise the votes array
    votes = []

    # Loop through each set of votes
    for index in xrange((len(voteValues) / 8) / candidateCount):

        # Add a row for this set of votes
        votes.append([])

        # Loop through each candidate
        for candidateIndex in xrange(candidateCount):

            # Initalise this vote value
            voteValue = ''

            # Loop through each value for this candidate
            for valueIndex in xrange(8):

                # Compile this vote
                voteValue += str(voteValues[((index * (candidateCount * 8)) +
                                             (candidateIndex) * 8) +
                                            valueIndex])

            # Add the vote value to the vote array
            votes[index].append(geth.hexToNumber(voteValue))

    # Return the votes array
    return votes
Exemple #3
0
def getVoters(ballot):
    votersResponse = geth.callFunction(ballot.address, 'getVoters')['result']
    return geth.responseToVoters(votersResponse)
Exemple #4
0
def getCandidateCount(ballot):
    candidateCountResponse = geth.callFunction(ballot.address,
                                               'getCandidateCount')['result']
    return geth.responseToInteger(candidateCountResponse)
Exemple #5
0
def getCandidates(ballot):
    candidatesResponse = geth.callFunction(ballot.address,
                                           'getCandidates')['result']
    return geth.responseToCandidates(candidatesResponse)
Exemple #6
0
def getDescription(ballot):
    descriptionResponse = geth.callFunction(ballot.address,
                                            'getDescription')['result']
    return geth.responseToString(descriptionResponse)
Exemple #7
0
def getTitle(ballot):
    titleResponse = geth.callFunction(ballot.address, 'getTitle')['result']
    return geth.responseToString(titleResponse)