def GetLatestData(self, request: qrl_pb2.GetLatestDataReq, context) -> qrl_pb2.GetLatestDataResp: logger.debug("[PublicAPI] GetLatestData") response = qrl_pb2.GetLatestDataResp() all_requested = request.filter == qrl_pb2.GetLatestDataReq.ALL quantity = min(request.quantity, self.MAX_REQUEST_QUANTITY) if all_requested or request.filter == qrl_pb2.GetLatestDataReq.BLOCKHEADERS: result = [] for blk in self.qrlnode.get_latest_blocks(offset=request.offset, count=quantity): transaction_count = qrl_pb2.TransactionCount() for tx in blk.transactions: transaction_count.count[tx.type] += 1 for tx in blk.vote: transaction_count.count[tx.type] += 1 for tx in blk.duplicate_transactions: transaction_count.count[tx.type] += 1 voted_weight = 0 total_stake_weight = 0 if blk.block_number > 0: voted_weight, total_stake_weight = self.qrlnode.get_vote_metadata( blk.block_number) result.append( qrl_pb2.BlockHeaderExtended( header=blk.blockheader.pbdata, transaction_count=transaction_count, voted_weight=voted_weight, total_stake_weight=total_stake_weight)) response.blockheaders.extend(result) if all_requested or request.filter == qrl_pb2.GetLatestDataReq.TRANSACTIONS: result = [] for tx in self.qrlnode.get_latest_transactions( offset=request.offset, count=quantity): # FIXME: Improve this once we have a proper database schema block_index = self.qrlnode.get_blockidx_from_txhash(tx.txhash) block = self.qrlnode.get_block_from_index(block_index) txextended = qrl_pb2.TransactionExtended( header=block.blockheader.pbdata, tx=tx.pbdata) result.append(txextended) response.transactions.extend(result) if all_requested or request.filter == qrl_pb2.GetLatestDataReq.TRANSACTIONS_UNCONFIRMED: result = [] for tx in self.qrlnode.get_latest_transactions_unconfirmed( offset=request.offset, count=quantity): block_index = self.qrlnode.get_blockidx_from_txhash(tx.txhash) block = self.qrlnode.get_block_from_index(block_index) txextended = qrl_pb2.TransactionExtended( header=block.blockheader.pbdata, tx=tx.pbdata) result.append(txextended) response.transactions_unconfirmed.extend(result) return response
def GetLatestData(self, request: qrl_pb2.GetLatestDataReq, context) -> qrl_pb2.GetLatestDataResp: logger.debug("[PublicAPI] GetLatestData") response = qrl_pb2.GetLatestDataResp() all_requested = request.filter == qrl_pb2.GetLatestDataReq.ALL quantity = min(request.quantity, self.MAX_REQUEST_QUANTITY) if all_requested or request.filter == qrl_pb2.GetLatestDataReq.BLOCKHEADERS: result = [] for blk in self.qrlnode.get_latest_blocks(offset=request.offset, count=quantity): transaction_count = qrl_pb2.TransactionCount() for tx in blk.transactions: transaction_count.count[CODEMAP[tx.WhichOneof( 'transactionType')]] += 1 result.append( qrl_pb2.BlockHeaderExtended( header=blk.blockheader.pbdata, transaction_count=transaction_count)) response.blockheaders.extend(result) if all_requested or request.filter == qrl_pb2.GetLatestDataReq.TRANSACTIONS: result = [] for tx in self.qrlnode.get_latest_transactions( offset=request.offset, count=quantity): # FIXME: Improve this once we have a proper database schema block_index = self.qrlnode.get_blockidx_from_txhash(tx.txhash) block = self.qrlnode.get_block_from_index(block_index) header = None if block: header = block.blockheader.pbdata txextended = qrl_pb2.TransactionExtended( header=header, tx=tx.pbdata, addr_from=tx.addr_from, size=tx.size) result.append(txextended) response.transactions.extend(result) if all_requested or request.filter == qrl_pb2.GetLatestDataReq.TRANSACTIONS_UNCONFIRMED: result = [] for tx_info in self.qrlnode.get_latest_transactions_unconfirmed( offset=request.offset, count=quantity): tx = tx_info.transaction txextended = qrl_pb2.TransactionExtended( header=None, tx=tx.pbdata, addr_from=tx.addr_from, size=tx.size, timestamp_seconds=tx_info.timestamp) result.append(txextended) response.transactions_unconfirmed.extend(result) return response