def BroadcastTransaction(self, request, context): transaction = pickle.loads(request.message) self.transactionLobby.append(transaction) return helloworld_pb2.Blank(message="Transaction Received")
def BroadcastBlock(self, request, context): block = pickle.loads(request.message) self.blockLobby.append(block) return helloworld_pb2.Blank(message="Block Received")
def SendPeer(self, request, context): print("Adding peer" + request.message) if request.message not in self.peers: self.peers.append(request.message) for x in self.peers: print("known nodes:" + str(x)) print("Peers: " + str(self.peers)) return helloworld_pb2.Blank(message="Added peer (Y)")
def pullBlockSize(self): channel = grpc.insecure_channel(self.registration.addrMe) stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.PullBlockSize(helloworld_pb2.Blank(message="")) size = response.size #print("size is : " + str(size)) return size
def pullTransactions(self): channel = grpc.insecure_channel(self.registration.addrMe) stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.PullTransactions(helloworld_pb2.Blank(message="")) transaction = pickle.loads(response.message) #print("pulled transactions " + str(transaction)) return transaction
def returnPeers(self, address): channel = grpc.insecure_channel(address) stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.PullPeers(helloworld_pb2.Blank(message="")) knownPeers = [] for x in response.message: knownPeers.append(x) return knownPeers
def pullBlocks(self): channel = grpc.insecure_channel(self.registration.addrMe) stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.PullBlocks(helloworld_pb2.Blank(message="")) blocks = pickle.loads(response.message) knownBlocks = [] for x in blocks: knownBlocks.append(x) return knownBlocks