2023-12-05 13:50:23 +01:00

69 lines
1.6 KiB
Python

from SocketUtil import *
from Transaction import *
from Signature import *
M_SERVER_IP = 'localhost'
M_SERVER_PORT = 5005
W_SERVER_IP = 'localhost'
W_SERVER_PORT = 5006
alex_prv, alex_pbc = generate_keys()
mike_prv, mike_pbc = generate_keys()
rose_prv, rose_pbc = generate_keys()
mara_prv, mara_pbc = generate_keys()
Tx1 = Tx()
Tx1.add_input(alex_pbc, 4.0)
Tx1.add_input(mike_pbc, 1.0)
Tx1.add_output(rose_pbc, 4.8)
Tx1.sign(alex_prv)
Tx1.sign(mike_prv)
Tx2 = Tx()
Tx2.add_input(rose_pbc, 4.0)
Tx2.add_output(mike_pbc, 4.0)
Tx2.add_reqd(alex_pbc)
Tx2.sign(rose_prv)
Tx2.sign(alex_prv)
print(Tx1.is_valid())
print(Tx2.is_valid())
try:
sendObj(M_SERVER_IP, Tx1, M_SERVER_PORT)
print("Sent Tx1")
sendObj(M_SERVER_IP, Tx2, M_SERVER_PORT)
print("Sent Tx2")
except:
print("Error! Connection unsuccessful.")
wallet_server_socket = newServerSocket(W_SERVER_IP, W_SERVER_PORT)
for i in range(10):
newBlock = recvObj(wallet_server_socket)
if newBlock:
break
wallet_server_socket.close()
if newBlock.is_valid():
print("Success! Block is valid.")
if newBlock.good_nonce():
print("Success! Nonce is valid.")
tx1_found = tx2_found = False
for tx in newBlock.data:
try:
if tx.inputs[0][0] == alex_pbc and tx.inputs[0][1] == 4.0:
print("Tx1 is present.")
tx1_found = True
except:
pass
try:
if tx.inputs[0][0] == rose_pbc and tx.inputs[0][1] == 4.0:
print("Tx2 is present.")
tx2_found = True
except:
pass