code: func (h *Handler) HandleQueryStateNext(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error) {
  	queryStateNext := &pb.QueryStateNext{}
  	err := proto.Unmarshal(msg.Payload, queryStateNext)
  	if err != nil {
  		return nil, errors.Wrap(err, "unmarshal failed")
  	}
  
  	queryIter := txContext.GetQueryIterator(queryStateNext.Id)
  	if queryIter == nil {
  		return nil, errors.New("query iterator not found")
  	}
  
  	totalReturnLimit := calculateTotalReturnLimit(nil)
  
  	payload, err := h.QueryResponseBuilder.BuildQueryResponse(txContext, queryIter, queryStateNext.Id, false, totalReturnLimit)
  	if err != nil {
  		txContext.CleanupQueryContext(queryStateNext.Id)
  		return nil, errors.WithStack(err)
  	}
  
  	payloadBytes, err := proto.Marshal(payload)
  	if err != nil {
  		txContext.CleanupQueryContext(queryStateNext.Id)
  		return nil, errors.Wrap(err, "marshal failed")
  	}
  
  	return &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: payloadBytes, Txid: msg.Txid, ChannelId: msg.ChannelId}, nil
  }
docs: // Handles query to ledger for query state next