-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvoting.py
More file actions
84 lines (68 loc) · 2.99 KB
/
voting.py
File metadata and controls
84 lines (68 loc) · 2.99 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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): ")
hexData = fuseVotingContract.encodeABI(fn_name="vote", args=[int(ballotID),int(choice)])
addrList = []
for file in os.listdir(dirToSearch):
private_key = ''
if FuseFileStructure:
if(os.path.isdir(dirToSearch + '/' + file+'/config')):
with open(dirToSearch + '/' + file + '/config/address', 'r') as fileToRead:
addr = fileToRead.read().replace('\n', '')
with open(dirToSearch + '/' + file +'/config/pass.pwd', 'r') as fileToRead:
keystorePassword = fileToRead.read().replace('\n', '')
for keys in os.listdir(dirToSearch + '/' + file+'/config/keys/FuseNetwork'):
if keys.startswith("UTC"):
with open(dirToSearch + '/' + file+'/config/keys/FuseNetwork/' + keys) as keyfile:
encrypted_key = keyfile.read()
private_key = web3Fuse.eth.account.decrypt(encrypted_key, keystorePassword)
else:
#grab the address from the keystore
f = open(dirToSearch + '/' + file)
data = json.load(f)
addr=data['address']
f.close()
passWordString = 'What is your password for ' + addr + ' ?: '
keystorePassword = getpass(prompt=passWordString)
web3Fuse = Web3(Web3.HTTPProvider(RPC_ADDRESS))
with open(dirToSearch + '/' + file) as keyfile:
encrypted_key = keyfile.read()
private_key = web3Fuse.eth.account.decrypt(encrypted_key, keystorePassword)
if(private_key != ''):
addr = Web3.toChecksumAddress(addr)
Nonce = web3Fuse.eth.getTransactionCount(addr)
signed_txn = web3Fuse.eth.account.signTransaction(dict(
nonce=Nonce,
gasPrice=web3Fuse.toWei('1', 'gwei'),
gas=250000,
to=votingABI.VOTING_ADDR,
value=0,
chainId=122,
data=hexData
),
private_key=private_key)
try:
txid = web3Fuse.eth.sendRawTransaction(signed_txn.rawTransaction)
print ("Transaction sent on: " + addr + " TXID: " + web3Fuse.toHex(txid))
addrList.append(addr)
except ValueError:
print("failedToSend from " + addr)
time.sleep(5)
for address in addrList:
voted = fuseVotingContract.functions.getVoterChoice(int(ballotID), address).call()
if voted != int(choice):
print("Failed to vote for addr: " + address)