-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunciones_toDos.py
86 lines (71 loc) · 2.61 KB
/
funciones_toDos.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
with open("../Contratos/Compilado/TodoList.abi") as contract_abi_file:
contract_abi = json.load(contract_abi_file)
with open("../Contratos/Compilado/TodoList.bin") as contract_bin_file:
contract_bytecode = '0x' + contract_bin_file.read()
contract_address = "0x412F46d9D27356260B47AF0D0480ea34814f3991"
todos = web3.eth.contract(address = contract_address, abi = contract_abi, bytecode = contract_bytecode)
tx_hash = None
gas = 1000000
gasPrice = web3.toWei('5', 'gwei')
#gasPrice = 1
def duenio():
return todos.functions.owner().call()
def anotaciones(_accN):
if todos.functions.overIds(acc[_accN]).call():
last = 5
else:
last = todos.functions.lastIds(acc[_accN]).call()
for i in range(last):
print(todos.functions.todos(acc[_accN],i).call())
def addTodo(contenido,_accN):
unsigned_txn = todos.functions.addTodo(contenido).buildTransaction({
'gas': gas,
'gasPrice': gasPrice,
'nonce': web3.eth.getTransactionCount(acc[_accN])
})
#print(bh_txn)
signed_txn = web3.eth.account.signTransaction(unsigned_txn, private_key=private_key[_accN])
global tx_hash
tx_hash = web3.eth.sendRawTransaction(signed_txn.rawTransaction)
print(tx_hash.hex())
return web3.eth.waitForTransactionReceipt(tx_hash.hex())
def markTodoAsCompleted(Id,_accN):
unsigned_txn = todos.functions.markTodoAsCompleted(Id).buildTransaction({
'gas': gas,
'gasPrice': gasPrice,
'nonce': web3.eth.getTransactionCount(acc[_accN])
})
#print(bh_txn)
signed_txn = web3.eth.account.signTransaction(unsigned_txn, private_key=private_key[_accN])
global tx_hash
tx_hash = web3.eth.sendRawTransaction(signed_txn.rawTransaction)
print(tx_hash.hex())
#print('Log:', web3.eth.waitForTransactionReceipt(tx_hash.hex()).logs[0]['data'])
return web3.eth.waitForTransactionReceipt(tx_hash.hex())
def mandarPlata(_to, _value, _accN):
signed_txn = web3.eth.account.signTransaction(dict(
nonce = web3.eth.getTransactionCount(acc[_accN]),
gasPrice = gasPrice,
gas = 25000,
to = _to,
value = _value,
#data=b'',
),
private_key[_accN],
)
global tx_hash
tx_hash = web3.eth.sendRawTransaction(signed_txn.rawTransaction)
print(tx_hash.hex())
return web3.eth.waitForTransactionReceipt(tx_hash)
def matame(_accN):
unsigned_txn = todos.functions.matame().buildTransaction({
'gas': gas,
'gasPrice': gasPrice,
'nonce': web3.eth.getTransactionCount(acc[_accN])
})
#print(bh_txn)
signed_txn = web3.eth.account.signTransaction(unsigned_txn, private_key=private_key[_accN])
global tx_hash
tx_hash = web3.eth.sendRawTransaction(signed_txn.rawTransaction)
print(tx_hash.hex())
return web3.eth.waitForTransactionReceipt(tx_hash.hex())