-
Notifications
You must be signed in to change notification settings - Fork 0
/
funciones_tic2.py
130 lines (98 loc) · 3.35 KB
/
funciones_tic2.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
with open("../Contratos/Compilado/TicTacToe2.abi") as contract_abi_file:
contract_abi = json.load(contract_abi_file)
with open("../Contratos/Compilado/TicTacToe2.bin") as contract_bin_file:
contract_bytecode = '0x' + contract_bin_file.read()
contract_address = "0xDDB0F27773BC7bA619b43F7FABC631357857983F"
tic = web3.eth.contract(address = contract_address, abi = contract_abi, bytecode = contract_bytecode)
#tx_hash = None
#ticket = None
gas = 200000
gasPrice = web3.toWei('5', 'gwei')
#gasPrice = 1
def player1():
return tic.functions.player1().call()
def player2():
return tic.functions.player2().call()
def estado():
return tic.functions.gameActive().call()
def costo():
return tic.functions.gameCost().call()
def tablero():
#board = list(tic.functions.getBoard().call())
board = tic.functions.getBoard().call()
for i in range(3):
for j in range(3):
if (board[i][j] == acc0):
board[i][j] = 1
elif (board[i][j] == acc1):
board[i][j] = 2
else:
board[i][j] = 0
print('\n',board[0],'\n',board[1],'\n',board[2],'\n')
global tx_hash
try:
player = tic.events.NextPlayer().processReceipt(web3.eth.getTransactionReceipt(tx_hash.hex()))[0]['args'].player
except IndexError: player = None
try:
winner = tic.events.GameOverWithWin().processReceipt(web3.eth.getTransactionReceipt(tx_hash.hex()))[0]['args'].winner
except IndexError: winner = None
if (player is None):
None
else:
print('Ahora le toca a', player)
if (winner is None):
None
else:
print('El que gano fue', winner)
def entrar(_accN):
unsigned_txn = tic.functions.joinGame().buildTransaction({
'gas': gas,
'gasPrice': gasPrice,
'nonce': web3.eth.getTransactionCount(acc[_accN]),
'value': 10
})
#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())
global ticket
ticket = web3.eth.waitForTransactionReceipt(tx_hash.hex())
try:
player = tic.events.NextPlayer().processReceipt(web3.eth.getTransactionReceipt(tx_hash.hex()))[0]['args'].player
except IndexError: player = None
if (player is None):
None
else:
print('Ahora le toca a', player)
#return ticket
def ficha(_x, _y, _accN):
unsigned_txn = tic.functions.setStone(_x, _y).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'])
global ticket
ticket = web3.eth.waitForTransactionReceipt(tx_hash.hex())
tablero()
#return web3.eth.waitForTransactionReceipt(tx_hash.hex())
def salirse(_accN):
unsigned_txn = tic.functions.emergecyCashout().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())
global ticket
ticket = web3.eth.waitForTransactionReceipt(tx_hash.hex())
#return web3.eth.waitForTransactionReceipt(tx_hash.hex())