# Import custom modules
import ballot
import keys
import geth

# Output a list of all the saved ballots
def allBallots(showIndexes=False, showBallotDetail=True):

    # Get the saved ballots
    savedBallots = ballot.savedBallots();

    # Check if there are any saved ballots
    if len(savedBallots) < 1:

        # No saved ballots where found
        print "No ballots found."

    else:

        # Loop through each saved ballot
        for index in xrange(len(savedBallots)):

            # Initalise this ballots output
            output = ''

            # Check if an index needs to be added
            if showIndexes:

                # Add the index of the saved ballot
                output += str(index + 1) + ' - '

            # Add the title of the ballot
            output += savedBallots[index].title

            # Check if details about the ballot are to be shown
            if showBallotDetail:

                # Add the ballots address
                output += ' - Address: ' + savedBallots[index].address

            # Output the ballot
            print output

# Output a list of all the saved keys
def allKeys(showIndexes=False, showKeyDetail=True):

    # Get the saved keys
    savedKeys = keys.savedKeys();

    # Check if there are any saved keys
    if len(savedKeys) < 1:

        # No saved keys where found
        print "No keys found."

    else:

        # Loop through each saved key
        for index in xrange(len(savedKeys)):

            # Initalise this keys output
            output = ''

            # Check if an index needs to be added
            if showIndexes:

                # Add the index of the saved key
                output += str(index + 1) + ' - '

            # Add the name of the key
            output += savedKeys[index].name

            # Check if details about the key are to be shown
            if showKeyDetail:

                # Check if the key has a private key
                if savedKeys[index].privateKey:

                    # The key has both
                    output += ' - Public and Private'

                else:

                    # The key is public only
                    output += ' - Public Only'

            # Output the key
            print output

# Output a list of all available Ethereum accounts
def allAccounts(showIndexes=False, showAccountDetail=True):

    # Get the accounts from the geth instance
    accounts = geth.accounts()

    # Check if there are any accounts
    if len(accounts) < 1:

        # No accounts where found
        print "No accounts found."

    else:

        # Loop through each account
        for index in xrange(len(accounts)):

            # Initalise this accounts output
            output = ''

            # Check if an index needs to be added
            if showIndexes:

                # Add the index of the account
                output += str(index + 1) + ' - '

            # Add the address of the account
            output += accounts[index].lstrip('0x')

            # Check if details about the account are to be shown
            if showAccountDetail:

                # Add the balance of the account
                output += " | " + str(geth.getBalance(accounts[index])) + " Ether"

            # Output the key
            print output

# Output the information of a ballot
def ballotInfo(targetBallot, showCandidates=True, showVoters=True):

    # Get the ballot title
    title = ballot.getTitle(targetBallot)

    # Get the ballot description
    description = ballot.getDescription(targetBallot)

    # Display the ballot information
    print ''
    print title
    print description

    # Check if the candidates should be shown
    if (showCandidates):

        # Get the ballot candidates
        candidates = ballot.getCandidates(targetBallot)

        # Display the candidates
        print ''
        print 'Candidates:'
        for candidate in candidates: print candidate

    # Check if the voters should be shown
    if (showVoters):

        # Get the ballot voters
        voters = ballot.getVoters(targetBallot)

        # Display the voters
        print ''
        print 'Voters:'
        for voter in voters: print voter

# Output the candidates of a ballot
def candidates(targetBallot, showIndexes=True):

    # Get the ballot candidates
    candidates = ballot.getCandidates(targetBallot)

    # Loop through each candidate
    for index in xrange(len(candidates)):

        # Initalise this candidates output
        output = ''

        # Check if an index needs to be added
        if showIndexes:

            # Add the index of the candidate
            output += str(index + 1) + ' - '

        # Add the name of the candidate
        output += candidates[index]

        # Output the candidate
        print output
# Import custom modules
import ballot
import keys
import geth

# Output a list of all the saved ballots
def allBallots(showIndexes=False, showBallotDetail=True):

    # Get the saved ballots
    savedBallots = ballot.savedBallots();

    # Check if there are any saved ballots
    if len(savedBallots) < 1:

        # No saved ballots where found
        print "No ballots found."

    else:

        # Loop through each saved ballot
        for index in xrange(len(savedBallots)):

            # Initalise this ballots output
            output = ''

            # Check if an index needs to be added
            if showIndexes:

                # Add the index of the saved ballot
                output += str(index + 1) + ' - '

            # Add the title of the ballot
            output += savedBallots[index].title

            # Check if details about the ballot are to be shown
            if showBallotDetail:

                # Add the ballots address
                output += ' - Address: ' + savedBallots[index].address

            # Output the ballot
            print output

# Output a list of all the saved keys
def allKeys(showIndexes=False, showKeyDetail=True):

    # Get the saved keys
    savedKeys = keys.savedKeys();

    # Check if there are any saved keys
    if len(savedKeys) < 1:

        # No saved keys where found
        print "No keys found."

    else:

        # Loop through each saved key
        for index in xrange(len(savedKeys)):

            # Initalise this keys output
            output = ''

            # Check if an index needs to be added
            if showIndexes:

                # Add the index of the saved key
                output += str(index + 1) + ' - '

            # Add the name of the key
            output += savedKeys[index].name

            # Check if details about the key are to be shown
            if showKeyDetail:

                # Check if the key has a private key
                if savedKeys[index].privateKey:

                    # The key has both
                    output += ' - Public and Private'

                else:

                    # The key is public only
                    output += ' - Public Only'

            # Output the key
            print output

# Output a list of all available Ethereum accounts
def allAccounts(showIndexes=False, showAccountDetail=True):

    # Get the accounts from the geth instance
    accounts = geth.accounts()

    # Check if there are any accounts
    if len(accounts) < 1:

        # No accounts where found
        print "No accounts found."

    else:

        # Loop through each account
        for index in xrange(len(accounts)):

            # Initalise this accounts output
            output = ''

            # Check if an index needs to be added
            if showIndexes:

                # Add the index of the account
                output += str(index + 1) + ' - '

            # Add the address of the account
            output += accounts[index].lstrip('0x')

            # Check if details about the account are to be shown
            if showAccountDetail:

                # Add the balance of the account
                output += " | " + str(geth.getBalance(accounts[index])) + " Ether"

            # Output the key
            print output

# Output the information of a ballot
def ballotInfo(targetBallot, showCandidates=True, showVoters=True):

    # Get the ballot title
    title = ballot.getTitle(targetBallot)

    # Get the ballot description
    description = ballot.getDescription(targetBallot)

    # Display the ballot information
    print ''
    print title
    print description

    # Check if the candidates should be shown
    if (showCandidates):

        # Get the ballot candidates
        candidates = ballot.getCandidates(targetBallot)

        # Display the candidates
        print ''
        print 'Candidates:'
        for candidate in candidates: print candidate

    # Check if the voters should be shown
    if (showVoters):

        # Get the ballot voters
        voters = ballot.getVoters(targetBallot)

        # Display the voters
        print ''
        print 'Voters:'
        for voter in voters: print voter

# Output the candidates of a ballot
def candidates(targetBallot, showIndexes=True):

    # Get the ballot candidates
    candidates = ballot.getCandidates(targetBallot)

    # Loop through each candidate
    for index in xrange(len(candidates)):

        # Initalise this candidates output
        output = ''

        # Check if an index needs to be added
        if showIndexes:

            # Add the index of the candidate
            output += str(index + 1) + ' - '

        # Add the name of the candidate
        output += candidates[index]

        # Output the candidate
        print output
# Import custom modules # Output a list of all the saved ballots # Get the saved ballots # Check if there are any saved ballots # No saved ballots where found # Loop through each saved ballot # Initalise this ballots output # Check if an index needs to be added # Add the index of the saved ballot # Add the title of the ballot # Check if details about the ballot are to be shown # Add the ballots address # Output the ballot # Output a list of all the saved keys # Get the saved keys # Check if there are any saved keys # No saved keys where found # Loop through each saved key # Initalise this keys output # Check if an index needs to be added # Add the index of the saved key # Add the name of the key # Check if details about the key are to be shown # Check if the key has a private key # The key has both # The key is public only # Output the key # Output a list of all available Ethereum accounts # Get the accounts from the geth instance # Check if there are any accounts # No accounts where found # Loop through each account # Initalise this accounts output # Check if an index needs to be added # Add the index of the account # Add the address of the account # Check if details about the account are to be shown # Add the balance of the account # Output the key # Output the information of a ballot # Get the ballot title # Get the ballot description # Display the ballot information # Check if the candidates should be shown # Get the ballot candidates # Display the candidates # Check if the voters should be shown # Get the ballot voters # Display the voters # Output the candidates of a ballot # Get the ballot candidates # Loop through each candidate # Initalise this candidates output # Check if an index needs to be added # Add the index of the candidate # Add the name of the candidate # Output the candidate