lessons period 2
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
from TxBlock import *
|
||||
from Transaction import *
|
||||
from Signature import *
|
||||
|
||||
from client import *
|
||||
|
||||
SERVER = 'localhost'
|
||||
TCP_PORT = 5005
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
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, 2.3)
|
||||
Tx1.add_output(mike_pbc, 1.0)
|
||||
Tx1.add_output(rose_pbc, 1.1)
|
||||
Tx1.sign(alex_prv)
|
||||
|
||||
Tx2 = Tx()
|
||||
Tx2.add_input(rose_pbc, 2.3)
|
||||
Tx2.add_input(mike_pbc, 1.0)
|
||||
Tx2.add_output(alex_pbc, 3.1)
|
||||
Tx2.sign(mike_prv)
|
||||
Tx2.sign(rose_prv)
|
||||
|
||||
B1 = TxBlock.TxBlock(None)
|
||||
B1.addTx(Tx1)
|
||||
B1.addTx(Tx2)
|
||||
|
||||
sendObj(SERVER, B1)
|
||||
|
||||
sendObj(SERVER, Tx2)
|
@@ -0,0 +1,57 @@
|
||||
import TxBlock
|
||||
import socket
|
||||
import pickle
|
||||
|
||||
from server import *
|
||||
|
||||
|
||||
local_hostname = socket.gethostname()
|
||||
# local_ip = socket.gethostbyname(local_hostname)
|
||||
local_ip = '192.168.1.103'
|
||||
|
||||
|
||||
TCP_PORT = 5005
|
||||
BUFFER_SIZE = 1024
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
server = newConnection(local_ip)
|
||||
print(f"[LISTENING] Server is listening on {local_ip}")
|
||||
|
||||
|
||||
newB = recvObj(server)
|
||||
# print(newB.data[0])
|
||||
# print(newB.data[1])
|
||||
|
||||
if (newB.is_valid()):
|
||||
print("Success! Transaction is valid.")
|
||||
else:
|
||||
print("Error! Transaction invalid.")
|
||||
|
||||
if newB.data[0].inputs[0][1] == 2.3:
|
||||
print("Success! Input value matches.")
|
||||
else:
|
||||
print("Error! Wrong input value for block 1, transaction 1.")
|
||||
|
||||
if newB.data[0].outputs[1][1] == 1.1:
|
||||
print("Success! Output value matches.")
|
||||
else:
|
||||
print("Error! Wrong output value for block 1, transaction 1.")
|
||||
|
||||
if newB.data[1].inputs[0][1] == 2.3:
|
||||
print("Success! Input value matches.")
|
||||
else:
|
||||
print("Error! Wrong input value for block 1, transaction 1.")
|
||||
|
||||
if newB.data[1].inputs[1][1] == 1.0:
|
||||
print("Success! Input value matches.")
|
||||
else:
|
||||
print("Error! Wrong input value for block 1, transaction 1.")
|
||||
|
||||
if newB.data[1].outputs[0][1] == 3.1:
|
||||
print("Success! Output value matches.")
|
||||
else:
|
||||
print("Error! Wrong output value for block 1, transaction 1.")
|
||||
|
||||
newTx = recvObj(server)
|
||||
# print(newTx)
|
Reference in New Issue
Block a user