def GetObject(self, request: qrl_pb2.GetObjectReq, context) -> qrl_pb2.GetObjectResp: logger.debug("[PublicAPI] GetObject") answer = qrl_pb2.GetObjectResp() answer.found = False # FIXME: We need a unified way to access and validate data. query = bytes( request.query ) # query will be as a string, if Q is detected convert, etc. if self.qrlnode.address_is_valid(query): if self.qrlnode.get_address_is_used(query): address_state = self.qrlnode.get_address_state(query) if address_state is not None: answer.found = True answer.address_state.CopyFrom(address_state) return answer transaction = self.qrlnode.get_transaction(query) if transaction is not None: answer.found = True block_index = self.qrlnode.get_blockidx_from_txhash( transaction.txhash) blockheader = None if block_index: block = self.qrlnode.get_block_from_index(block_index) blockheader = block.blockheader.pbdata txextended = qrl_pb2.TransactionExtended(header=blockheader, tx=transaction.pbdata) answer.transaction.CopyFrom(txextended) return answer block = self.qrlnode.get_block_from_hash(query) if block is not None: answer.found = True answer.block.CopyFrom(block.pbdata) return answer block = self.qrlnode.get_block_from_hash(query) if block is not None: answer.found = True answer.block.CopyFrom(block.pbdata) return answer # NOTE: This is temporary, indexes are accepted for blocks try: query_str = query.decode() query_index = int(query_str) block = self.qrlnode.get_block_from_index(query_index) if block is not None: answer.found = True answer.block.CopyFrom(block.pbdata) return answer except Exception: pass return answer
def GetObject(self, request: qrl_pb2.GetObjectReq, context) -> qrl_pb2.GetObjectResp: logger.debug("[PublicAPI] GetObject") answer = qrl_pb2.GetObjectResp() answer.found = False # FIXME: We need a unified way to access and validate data. query = bytes( request.query ) # query will be as a string, if Q is detected convert, etc. if AddressState.address_is_valid(query): if self.qrlnode.get_address_is_used(query): address_state = self.qrlnode.get_address_state(query) if address_state is not None: answer.found = True answer.address_state.CopyFrom(address_state.pbdata) return answer transaction, block_number = self.qrlnode.get_transaction(query) if transaction is not None: answer.found = True blockheader = None if block_number is not None: block = self.qrlnode.get_block_from_index(block_number) blockheader = block.blockheader.pbdata txextended = qrl_pb2.TransactionExtended( header=blockheader, tx=transaction.pbdata, addr_from=transaction.addr_from, size=transaction.size) answer.transaction.CopyFrom(txextended) return answer # NOTE: This is temporary, indexes are accepted for blocks try: block = self.qrlnode.get_block_from_hash(query) if block is None: query_str = query.decode() query_index = int(query_str) block = self.qrlnode.get_block_from_index(query_index) answer.found = True block_extended = qrl_pb2.BlockExtended() block_extended.header.CopyFrom(block.blockheader.pbdata) block_extended.size = block.size for transaction in block.transactions: tx = Transaction.from_pbdata(transaction) extended_tx = qrl_pb2.TransactionExtended( tx=transaction, addr_from=tx.addr_from, size=tx.size) block_extended.extended_transactions.extend([extended_tx]) answer.block_extended.CopyFrom(block_extended) return answer except Exception: pass return answer
def GetObject(self, request: qrl_pb2.GetObjectReq, context) -> qrl_pb2.GetObjectResp: logger.debug("[PublicAPI] GetObject") answer = qrl_pb2.GetObjectResp() answer.found = False # FIXME: We need a unified way to access and validate data. query = bytes( request.query ) # query will be as a string, if Q is detected convert, etc. try: if AddressState.address_is_valid(query): if self.qrlnode.get_address_is_used(query): address_state = self.qrlnode.get_address_state(query) if address_state is not None: answer.found = True answer.address_state.CopyFrom(address_state.pbdata) return answer except ValueError: pass transaction_block_number = self.qrlnode.get_transaction(query) transaction = None blockheader = None if transaction_block_number: transaction, block_number = transaction_block_number answer.found = True block = self.qrlnode.get_block_from_index(block_number) blockheader = block.blockheader.pbdata timestamp = block.blockheader.timestamp else: transaction_timestamp = self.qrlnode.get_unconfirmed_transaction( query) if transaction_timestamp: transaction, timestamp = transaction_timestamp answer.found = True if transaction: txextended = qrl_pb2.TransactionExtended( header=blockheader, tx=transaction.pbdata, addr_from=transaction.addr_from, size=transaction.size, timestamp_seconds=timestamp) answer.transaction.CopyFrom(txextended) return answer # NOTE: This is temporary, indexes are accepted for blocks try: block = self.qrlnode.get_block_from_hash(query) # The condition after or is to avoid a bug, where a block is deserialized by BlockNumberMapping if block is None or (block.block_number == 0 and block.prev_headerhash != config.user.genesis_prev_headerhash): query_str = query.decode() query_index = int(query_str) block = self.qrlnode.get_block_from_index(query_index) if not block: return answer answer.found = True block_extended = qrl_pb2.BlockExtended() block_extended.header.CopyFrom(block.blockheader.pbdata) block_extended.size = block.size for transaction in block.transactions: tx = Transaction.from_pbdata(transaction) extended_tx = qrl_pb2.TransactionExtended( tx=transaction, addr_from=tx.addr_from, size=tx.size, timestamp_seconds=block.blockheader.timestamp) block_extended.extended_transactions.extend([extended_tx]) answer.block_extended.CopyFrom(block_extended) return answer except Exception: pass return answer