-
Notifications
You must be signed in to change notification settings - Fork 1
/
Election.py
63 lines (47 loc) · 6.6 KB
/
Election.py
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
from web3 import Web3
import json
ganache_url = "HTTP://127.0.0.1:7545"
web3 = Web3(Web3.HTTPProvider(ganache_url))
bytecode = "608060405260016000806101000a81548160ff02191690831515021790555034801561002a57600080fd5b5033600060016101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506100b06040518060400160405280600b81526020017f43616e646964617465203100000000000000000000000000000000000000000081525061013d60201b60201c565b6100f46040518060400160405280600b81526020017f43616e646964617465203200000000000000000000000000000000000000000081525061013d60201b60201c565b6101386040518060400160405280600b81526020017f43616e646964617465203300000000000000000000000000000000000000000081525061013d60201b60201c565b610256565b6003600081548092919060010191905055506040518060600160405280600354815260200182815260200160008152506002600060035481526020019081526020016000206000820151816000015560208201518160010190805190602001906101a89291906101b9565b506040820151816002015590505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106101fa57805160ff1916838001178555610228565b82800160010185558215610228579182015b8281111561022757825182559160200191906001019061020c565b5b5090506102359190610239565b5090565b5b8082111561025257600081600090555060010161023a565b5090565b6106b8806102656000396000f3fe608060405234801561001057600080fd5b506004361061007d5760003560e01c80638da5cb5b1161005b5780638da5cb5b14610183578063a3ec138d146101b7578063efbe1c1c14610211578063f1cea4c71461021b5761007d565b80630121b93f146100825780632d35a8a2146100b05780633477ee2e146100ce575b600080fd5b6100ae6004803603602081101561009857600080fd5b8101908080359060200190929190505050610239565b005b6100b861048f565b6040518082815260200191505060405180910390f35b6100fa600480360360208110156100e457600080fd5b8101908080359060200190929190505050610495565b6040518084815260200180602001838152602001828103825284818151815260200191508051906020019080838360005b8381101561014657808201518184015260208101905061012b565b50505050905090810190601f1680156101735780820380516001836020036101000a031916815260200191505b5094505050505060405180910390f35b61018b610557565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6101f9600480360360208110156101cd57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061057d565b60405180821515815260200191505060405180910390f35b61021961059d565b005b61022361067c565b6040518082815260200191505060405180910390f35b600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16156102f9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600d8152602001807f416c726561647920766f7465640000000000000000000000000000000000000081525060200191505060405180910390fd5b60008111801561030b57506003548111155b61037d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260118152602001807f496e76616c69642063616e64696461746500000000000000000000000000000081525060200191505060405180910390fd5b60008054906101000a900460ff166103fd576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600e8152602001807f456c656374696f6e20656e64656400000000000000000000000000000000000081525060200191505060405180910390fd5b60018060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550600260008281526020019081526020016000206002016000815480929190600101919050555060046000815480929190600101919050555050565b60035481565b6002602052806000526040600020600091509050806000015490806001018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156105475780601f1061051c57610100808354040283529160200191610547565b820191906000526020600020905b81548152906001019060200180831161052a57829003601f168201915b5050505050908060020154905083565b600060019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60016020528060005260406000206000915054906101000a900460ff1681565b600060019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610660576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260138152602001807f204f4e4c59204f574e45522043414e20454e440000000000000000000000000081525060200191505060405180910390fd5b60008060006101000a81548160ff021916908315150217905550565b6004548156fea2646970667358221220fc028afe769ed7d72080779f959aae40d8f01e668a66ae1a66843a2d7f4138e064736f6c634300060c0033"
truffle_file = json.load(open('./build/contracts/Election.json'))
abi = truffle_file['abi']
def checkConnected():
print(web3.isConnected())
print(web3.eth.accounts)
def deployContract( owner , signature):
election = web3.eth.contract(abi=abi , bytecode=bytecode)
transaction_body = {
'nonce':web3.eth.get_transaction_count(owner),
'gas' :1728712,
'gasPrice':web3.toWei(8 , 'gwei')
}
deployment = election.constructor().buildTransaction(transaction_body)
signed_transaction = web3.eth.account.sign_transaction(deployment , signature)
result = web3.eth.send_raw_transaction(signed_transaction.rawTransaction)
return result
def totalVote(add , pvt):
contractAddress = "0x3a5B0258b8330Aa84a1620950e3577167Bf8918e"
# get = web3.eth.contract( address=contractAddress, abi=abi )
contract = web3.eth.contract(address=contractAddress, abi=abi)
transaction = contract.functions.hello().call().buildTransaction()
transaction['nonce'] = web3.eth.getTransactionCount(add)
signed_tx = web3.eth.account.signTransaction(transaction, pvt)
tx_hash = web3.eth.sendRawTransaction(signed_tx.rawTransaction)
return tx_hash
# data = contract.functions.hello().call()
# return data
add = "0x1E350c7eA62f10C5F39482561DE3D2066883ba6B"
key = "f8294d3f4176b466cfacca574dc188c8e3c3616ac5fd0695389f4449f3c023c2"
add2 = "0xFBfe3E0978A6c705777BA5009FC64e39Cb69892f"
pvt = "e841bddc4fa0f69b467932cf5cc97580f7f3c97b8ed6ddce41e2d59c4ef85304"
print(
# deployContract(add , key),
totalVote(add2 , pvt)
)
# contract = web3.eth.contract(address=contract_addr, abi=abi)
# transaction = contract.functions.vote(cid).buildTransaction()
# transaction['nonce'] = web3.eth.getTransactionCount(acc)
# signed_tx = web3.eth.account.signTransaction(transaction, pvt)
# tx_hash = web3.eth.sendRawTransaction(signed_tx.rawTransaction)
# vote_tx.append(tx_hash)
# # checkConnected()