from SocketUtil import * import TxBlock as Tx # import Tx SERVER = 'localhost' wallet_list = [SERVER] tx_list = [] def minerServer(my_ip, wallet_list): miner_server_socket = newServerSocket(my_ip, 5050) # receive 2 transactions for i in range(10): newTx = recvObj(miner_server_socket) if isinstance(newTx, Tx): tx_list.append(newTx) print("Received Tx") if len(tx_list) == 2: break if len(tx_list) < 2: print("Error! Not enough transactions received.") return # collect into block newBlock = TxBlock(None) for tx in tx_list: newBlock.addTx(tx) # find nonce newBlock.find_nonce() if newBlock.good_nonce(): print("Success! Nonce is valid.") else: print("Error! Nonce is invalid.") return # send that block to each in wallet_list for wallet in wallet_list: sendObj(wallet, newBlock) return # Open Server Connection # Rec'v 2 transactions # Collect into block # Find nonce # Send that block to each in walle_list # return def minerServer(my_ip, wallet_list): # open server connection for the miner server_socket = newServerSocket(my_ip, 5050) print('Server is ready to receive data ...') # receive 2 transactions data = recvObj(server_socket) print('Server is receiving data ...') if data: print('Data: ', type(data), '\n') else: print('No object received') # collect into block if data: block = TxBlock(None) block.addTx(data) data = recvObj(server_socket) if data: block.addTx(data) server_socket.close() # find nonce block.find_nonce() # send that block to each in wallet_list for wallet in wallet_list: sendObj(wallet, block) return minerServer('localhost', wallet_list)