-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhaveIVoted.py
More file actions
50 lines (40 loc) · 1.45 KB
/
haveIVoted.py
File metadata and controls
50 lines (40 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import json
import os
from getpass import getpass
from web3 import Web3
import votingABI
import time
FuseFileStructure=True
RPC_ADDRESS = 'https://rpc.fuse.io'
dirToSearch = input("Where are you keystores?: ")
web3Fuse = Web3(Web3.HTTPProvider(votingABI.RPC_ADDRESS))
fuseVotingContract = web3Fuse.eth.contract(abi=votingABI.VOTING_ABI, address=votingABI.VOTING_ADDR)
activeBallots = fuseVotingContract.functions.activeBallots().call()
print("active Ballots: " + str(activeBallots[0]))
ballotID = input("Ballot ID: ")
choice = '0'
while (choice != '1' and choice != '2'):
choice = input("Accept (1), reject (2): ")
addrList = []
for file in os.listdir(dirToSearch):
private_key = ''
addr=''
if FuseFileStructure:
if(os.path.isdir(dirToSearch + '/' + file+'/config')):
with open(dirToSearch + '/' + file + '/config/address', 'r') as fileToRead:
addr = fileToRead.read().replace('\n', '')
else:
#grab the address from the keystore
f = open(dirToSearch + '/' + file)
data = json.load(f)
addr=data['address']
f.close()
if addr != '':
addr = Web3.toChecksumAddress(addr)
addrList.append(addr)
for address in addrList:
voted = fuseVotingContract.functions.getVoterChoice(int(ballotID), address).call()
if voted != int(choice):
print("Failed to vote for addr: " + address)
else:
print(address + " Voted correctly choice = " + str(voted))