code: func (h *Handler) HandleGetHistoryForKey(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error) {
  	iterID := h.UUIDGenerator.New()
  	chaincodeName := h.ChaincodeName()
  
  	getHistoryForKey := &pb.GetHistoryForKey{}
  	err := proto.Unmarshal(msg.Payload, getHistoryForKey)
  	if err != nil {
  		return nil, errors.Wrap(err, "unmarshal failed")
  	}
  
  	historyIter, err := txContext.HistoryQueryExecutor.GetHistoryForKey(chaincodeName, getHistoryForKey.Key)
  	if err != nil {
  		return nil, errors.WithStack(err)
  	}
  
  	totalReturnLimit := calculateTotalReturnLimit(nil)
  
  	txContext.InitializeQueryContext(iterID, historyIter)
  	payload, err := h.QueryResponseBuilder.BuildQueryResponse(txContext, historyIter, iterID, false, totalReturnLimit)
  	if err != nil {
  		txContext.CleanupQueryContext(iterID)
  		return nil, errors.WithStack(err)
  	}
  
  	payloadBytes, err := proto.Marshal(payload)
  	if err != nil {
  		txContext.CleanupQueryContext(iterID)
  		return nil, errors.Wrap(err, "marshal failed")
  	}
  
  	chaincodeLogger.Debugf("Got keys and values. Sending %s", pb.ChaincodeMessage_RESPONSE)
  	return &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: payloadBytes, Txid: msg.Txid, ChannelId: msg.ChannelId}, nil
  }
docs: // Handles query to ledger history db