From 63105b99e44f1e5694dbe801926baf64adefeeca Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 12 Jun 2023 14:30:23 +0300 Subject: [PATCH 01/14] Add chages. --- moonstreamapi/moonstreamapi/routes/queries.py | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/moonstreamapi/moonstreamapi/routes/queries.py b/moonstreamapi/moonstreamapi/routes/queries.py index 97c71de7..88ba227b 100644 --- a/moonstreamapi/moonstreamapi/routes/queries.py +++ b/moonstreamapi/moonstreamapi/routes/queries.py @@ -450,3 +450,67 @@ async def remove_query_handler( raise MoonstreamHTTPException(status_code=500, internal_error=e) return entry + + +@router.get("/suggest", tags=["queries"]) +def get_suggested_queries( + request: Request, + supported_interfaces: Optional[List[str]] = None, + address: Optional[str] = None, +)-> Any: + + """ + Return set of suggested queries for user + """ + + tags = ["#type:query", "#approved"] + + if supported_interfaces: + tags.extend([f"#?interface:{interface}" for interface in supported_interfaces]) + + + + if address: + + tags.append(f"?#address:{address}") + + + query = " ".join(tags) + + + try: + queries = bc.search( + token=MOONSTREAM_ADMIN_ACCESS_TOKEN, + journal_id=MOONSTREAM_QUERIES_JOURNAL_ID, + query=query, + limit=100, + timeout=5, + ) + except BugoutResponseException as e: + raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail) + except Exception as e: + raise MoonstreamHTTPException(status_code=500, internal_error=e) + + + # make split by interfaces + + interfaces = {} + + for entry in queries.results: + + for tag in entry.tags: + + if tag.startswith("?interface:"): + + interface = tag.split(":")[1] + + if interface not in interfaces: + + interfaces[interface] = [] + + interfaces[interface].append(entry) + + + + return interfaces + From a4a982b1c1ea3d09a7045fab356b7e428259034a Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 12 Jun 2023 16:08:31 +0300 Subject: [PATCH 02/14] Add query suggestion and copy. --- moonstreamapi/moonstreamapi/data.py | 5 + moonstreamapi/moonstreamapi/routes/queries.py | 119 ++++++++++++++++-- 2 files changed, 111 insertions(+), 13 deletions(-) diff --git a/moonstreamapi/moonstreamapi/data.py b/moonstreamapi/moonstreamapi/data.py index ac67968e..e8fb29ce 100644 --- a/moonstreamapi/moonstreamapi/data.py +++ b/moonstreamapi/moonstreamapi/data.py @@ -296,3 +296,8 @@ class QueryInfoResponse(BaseModel): parameters: Dict[str, Any] = Field(default_factory=dict) created_at: Optional[datetime] updated_at: Optional[datetime] + + +class QueryCopy(BaseModel): + query_id: str + name: str diff --git a/moonstreamapi/moonstreamapi/routes/queries.py b/moonstreamapi/moonstreamapi/routes/queries.py index 88ba227b..0b93148d 100644 --- a/moonstreamapi/moonstreamapi/routes/queries.py +++ b/moonstreamapi/moonstreamapi/routes/queries.py @@ -456,28 +456,24 @@ async def remove_query_handler( def get_suggested_queries( request: Request, supported_interfaces: Optional[List[str]] = None, - address: Optional[str] = None, -)-> Any: + address: Optional[str] = None, +) -> Any: """ Return set of suggested queries for user """ - tags = ["#type:query", "#approved"] + tags = ["#type:query", "#approved", "#template"] if supported_interfaces: - tags.extend([f"#?interface:{interface}" for interface in supported_interfaces]) - - + tags.extend([f"?#interface:{interface}" for interface in supported_interfaces]) if address: tags.append(f"?#address:{address}") - query = " ".join(tags) - try: queries = bc.search( token=MOONSTREAM_ADMIN_ACCESS_TOKEN, @@ -490,17 +486,16 @@ def get_suggested_queries( raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail) except Exception as e: raise MoonstreamHTTPException(status_code=500, internal_error=e) - # make split by interfaces - interfaces = {} + interfaces: Dict[str, Any] = {} for entry in queries.results: for tag in entry.tags: - if tag.startswith("?interface:"): + if tag.startswith("interface:"): interface = tag.split(":")[1] @@ -510,7 +505,105 @@ def get_suggested_queries( interfaces[interface].append(entry) - - return interfaces + +@router.post("/copy", tags=["queries"]) +def copy_query(request: Request, query_copy: data.QueryCopy) -> BugoutJournalEntry: + """ + Create copy of query + """ + + token = request.state.token + user = request.state.user + + # get real query by id + + try: + entry = bc.get_entry( + token=token, + journal_id=MOONSTREAM_QUERIES_JOURNAL_ID, + entry_id=query_copy.query_id, + ) + except BugoutResponseException as e: + raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail) + except Exception as e: + raise MoonstreamHTTPException(status_code=500, internal_error=e) + + # Check already existed queries + + params = { + "type": data.BUGOUT_RESOURCE_QUERY_RESOLVER, + } + try: + resources: BugoutResources = bc.list_resources(token=token, params=params) + except BugoutResponseException as e: + raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail) + except Exception as e: + raise MoonstreamHTTPException(status_code=500, internal_error=e) + + used_queries: List[str] = [ + resource.resource_data["name"] for resource in resources.resources + ] + try: + query_name = name_normalization(query_copy.name) + except NameNormalizationException: + raise MoonstreamHTTPException( + status_code=403, + detail=f"Provided query name can't be normalize please select different.", + ) + + if query_name in used_queries: + raise MoonstreamHTTPException( + status_code=404, + detail=f"Provided query name already use. Please remove it or use PUT /{query_name} for update query", + ) + + try: + # Put query to journal + entry = bc.create_entry( + token=MOONSTREAM_ADMIN_ACCESS_TOKEN, + journal_id=MOONSTREAM_QUERIES_JOURNAL_ID, + title=f"Query:{query_name}", + tags=[tag for tag in entry.tags if tag != "template"], + content=entry.content, + ) + except BugoutResponseException as e: + raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail) + except Exception as e: + raise MoonstreamHTTPException(status_code=500, internal_error=e) + + try: + # create resource query_name_resolver + bc.create_resource( + token=token, + application_id=MOONSTREAM_APPLICATION_ID, + resource_data={ + "type": data.BUGOUT_RESOURCE_QUERY_RESOLVER, + "user_id": str(user.id), + "user": str(user.username), + "name": query_name, + "entry_id": str(entry.id), + }, + ) + except BugoutResponseException as e: + logger.error(f"Error creating name resolving resource: {str(e)}") + raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail) + except Exception as e: + raise MoonstreamHTTPException(status_code=500, internal_error=e) + + try: + bc.update_tags( + token=MOONSTREAM_ADMIN_ACCESS_TOKEN, + journal_id=MOONSTREAM_QUERIES_JOURNAL_ID, + entry_id=entry.id, + tags=[f"query_id:{entry.id}"], + ) + + except BugoutResponseException as e: + logger.error(f"Error in applind tags to query entry: {str(e)}") + raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail) + except Exception as e: + raise MoonstreamHTTPException(status_code=500, internal_error=e) + + return entry From 8cb7dfb8be655401750e0286f31c2b599810dce7 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 16 Jun 2023 14:30:02 +0300 Subject: [PATCH 03/14] Add filters on queries execution. --- moonstreamapi/moonstreamapi/routes/queries.py | 86 +++++++++++++++---- 1 file changed, 71 insertions(+), 15 deletions(-) diff --git a/moonstreamapi/moonstreamapi/routes/queries.py b/moonstreamapi/moonstreamapi/routes/queries.py index 0b93148d..a7f67d9b 100644 --- a/moonstreamapi/moonstreamapi/routes/queries.py +++ b/moonstreamapi/moonstreamapi/routes/queries.py @@ -272,16 +272,42 @@ async def update_query_data_handler( token = request.state.token + # normalize query name + + query_name_normalized = name_normalization(query_name) + + # check in admin resources + + params = { + "type": data.BUGOUT_RESOURCE_QUERY_RESOLVER, + "name": query_name_normalized, + } + try: - query_id = get_query_by_name(query_name, token) - except NameNormalizationException: - raise MoonstreamHTTPException( - status_code=403, - detail=f"Provided query name can't be normalize please select different.", + admin_resources: BugoutResources = bc.list_resources( + token=MOONSTREAM_ADMIN_ACCESS_TOKEN, params=params ) + except BugoutResponseException as e: + raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail) except Exception as e: + logger.error(f"Error in get query: {str(e)}") raise MoonstreamHTTPException(status_code=500, internal_error=e) + if len(admin_resources.resources) == 0: + + try: + query_id = get_query_by_name(query_name, token) + except NameNormalizationException: + raise MoonstreamHTTPException( + status_code=403, + detail=f"Provided query name can't be normalize please select different.", + ) + except Exception as e: + raise MoonstreamHTTPException(status_code=500, internal_error=e) + + else: + query_id = admin_resources.resources[0].resource_data["entry_id"] + try: entries = bc.search( token=MOONSTREAM_ADMIN_ACCESS_TOKEN, @@ -348,17 +374,40 @@ async def get_access_link_handler( token = request.state.token + # normalize query name + + query_name_normalized = name_normalization(query_name) + + params = { + "type": data.BUGOUT_RESOURCE_QUERY_RESOLVER, + "name": query_name_normalized, + } + try: - query_id = get_query_by_name(query_name, token) - except NameNormalizationException: - raise MoonstreamHTTPException( - status_code=403, - detail=f"Provided query name can't be normalize please select different.", + admin_resources: BugoutResources = bc.list_resources( + token=MOONSTREAM_ADMIN_ACCESS_TOKEN, params=params ) + except BugoutResponseException as e: + raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail) except Exception as e: logger.error(f"Error in get query: {str(e)}") raise MoonstreamHTTPException(status_code=500, internal_error=e) + if len(admin_resources.resources) == 0: + + try: + query_id = get_query_by_name(query_name, token) + except NameNormalizationException: + raise MoonstreamHTTPException( + status_code=403, + detail=f"Provided query name can't be normalize please select different.", + ) + except Exception as e: + raise MoonstreamHTTPException(status_code=500, internal_error=e) + + else: + query_id = admin_resources.resources[0].resource_data["entry_id"] + try: entries = bc.search( token=MOONSTREAM_ADMIN_ACCESS_TOKEN, @@ -452,27 +501,34 @@ async def remove_query_handler( return entry -@router.get("/suggest", tags=["queries"]) +@router.get("/templates", tags=["queries"]) def get_suggested_queries( request: Request, supported_interfaces: Optional[List[str]] = None, address: Optional[str] = None, + title: Optional[str] = None, + limit: int = 10, ) -> Any: """ Return set of suggested queries for user """ - tags = ["#type:query", "#approved", "#template"] + filters = ["#type:query", "#approved", "#template"] if supported_interfaces: - tags.extend([f"?#interface:{interface}" for interface in supported_interfaces]) + filters.extend( + [f"?#interface:{interface}" for interface in supported_interfaces] + ) if address: - tags.append(f"?#address:{address}") + filters.append(f"?#address:{address}") - query = " ".join(tags) + if title: + filters.append(title) + + query = " ".join(filters) try: queries = bc.search( From b2bf46ad7e42c4b7c6e3332fb7ac9939c7902263 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 16 Jun 2023 18:08:56 +0300 Subject: [PATCH 04/14] Add changes. --- crawlers/mooncrawl/mooncrawl/api.py | 29 +++++++++++++++++++ crawlers/mooncrawl/mooncrawl/data.py | 3 +- moonstreamapi/moonstreamapi/data.py | 1 + moonstreamapi/moonstreamapi/routes/queries.py | 27 ++++++++++------- 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/crawlers/mooncrawl/mooncrawl/api.py b/crawlers/mooncrawl/mooncrawl/api.py index 970c43df..f78fffc3 100644 --- a/crawlers/mooncrawl/mooncrawl/api.py +++ b/crawlers/mooncrawl/mooncrawl/api.py @@ -13,6 +13,13 @@ from bugout.data import BugoutResource from entity.data import EntityResponse # type: ignore from fastapi import BackgroundTasks, FastAPI from fastapi.middleware.cors import CORSMiddleware +from moonstreamdb.blockchain import ( + AvailableBlockchainType, + get_label_model, + get_block_model, + get_transaction_model, +) + from sqlalchemy import text from .actions import ( @@ -229,6 +236,28 @@ async def queries_data_update_handler( logger.error(f"Unhandled query execute exception, error: {e}") raise MoonstreamHTTPException(status_code=500) + requested_query = request_data.query + + if request_data.blockchain: + if request_data.blockchain not in AvailableBlockchainType.values(): + logger.error(f"Unknown blockchain {request_data.blockchain}") + raise MoonstreamHTTPException(status_code=403, detail="Unknown blockchain") + + requested_query = ( + requested_query.replace( + "transaction_table", + f"{request_data.blockchain}_transactions", + ) + .replace( + "block_table", + f"{request_data.blockchain}_blocks", + ) + .replace( + "label_table", + f"{request_data.blockchain}_labels", + ) + ) + # Check if it can transform to TextClause try: query = text(request_data.query) diff --git a/crawlers/mooncrawl/mooncrawl/data.py b/crawlers/mooncrawl/mooncrawl/data.py index 7a923225..3cef9a75 100644 --- a/crawlers/mooncrawl/mooncrawl/data.py +++ b/crawlers/mooncrawl/mooncrawl/data.py @@ -1,7 +1,7 @@ from dataclasses import dataclass from datetime import datetime from enum import Enum -from typing import Any, Dict, List +from typing import Any, Dict, List, Optional from pydantic import BaseModel, Field @@ -49,6 +49,7 @@ class QueryDataUpdate(BaseModel): file_type: str query: str params: Dict[str, Any] = Field(default_factory=dict) + blockchain: Optional[str] = None class TokenURIs(BaseModel): diff --git a/moonstreamapi/moonstreamapi/data.py b/moonstreamapi/moonstreamapi/data.py index e8fb29ce..ee0b0273 100644 --- a/moonstreamapi/moonstreamapi/data.py +++ b/moonstreamapi/moonstreamapi/data.py @@ -271,6 +271,7 @@ class DashboardUpdate(BaseModel): class UpdateDataRequest(BaseModel): params: Dict[str, Any] = Field(default_factory=dict) + blockchain: Optional[str] = None class UpdateQueryRequest(BaseModel): diff --git a/moonstreamapi/moonstreamapi/routes/queries.py b/moonstreamapi/moonstreamapi/routes/queries.py index a7f67d9b..fd689160 100644 --- a/moonstreamapi/moonstreamapi/routes/queries.py +++ b/moonstreamapi/moonstreamapi/routes/queries.py @@ -10,6 +10,7 @@ from bugout.data import BugoutResources, BugoutJournalEntryContent, BugoutJourna from bugout.exceptions import BugoutResponseException from fastapi import APIRouter, Body, Request import requests # type: ignore +from moonstreamdb.blockchain import AvailableBlockchainType from sqlalchemy import text @@ -272,6 +273,15 @@ async def update_query_data_handler( token = request.state.token + if request_update.blockchain: + try: + AvailableBlockchainType(request_update.blockchain) + except ValueError: + raise MoonstreamHTTPException( + status_code=400, + detail=f"Provided blockchain is not supported.", + ) + # normalize query name query_name_normalized = name_normalization(query_name) @@ -294,7 +304,6 @@ async def update_query_data_handler( raise MoonstreamHTTPException(status_code=500, internal_error=e) if len(admin_resources.resources) == 0: - try: query_id = get_query_by_name(query_name, token) except NameNormalizationException: @@ -340,6 +349,9 @@ async def update_query_data_handler( "query": content, "params": request_update.params, "file_type": file_type, + "blockchain": request_update.blockchain + if request_update.blockchain + else None, }, timeout=5, ) @@ -394,7 +406,6 @@ async def get_access_link_handler( raise MoonstreamHTTPException(status_code=500, internal_error=e) if len(admin_resources.resources) == 0: - try: query_id = get_query_by_name(query_name, token) except NameNormalizationException: @@ -509,7 +520,6 @@ def get_suggested_queries( title: Optional[str] = None, limit: int = 10, ) -> Any: - """ Return set of suggested queries for user """ @@ -522,7 +532,6 @@ def get_suggested_queries( ) if address: - filters.append(f"?#address:{address}") if title: @@ -548,15 +557,11 @@ def get_suggested_queries( interfaces: Dict[str, Any] = {} for entry in queries.results: - for tag in entry.tags: - if tag.startswith("interface:"): - interface = tag.split(":")[1] if interface not in interfaces: - interfaces[interface] = [] interfaces[interface].append(entry) @@ -577,7 +582,7 @@ def copy_query(request: Request, query_copy: data.QueryCopy) -> BugoutJournalEnt try: entry = bc.get_entry( - token=token, + token=MOONSTREAM_ADMIN_ACCESS_TOKEN, journal_id=MOONSTREAM_QUERIES_JOURNAL_ID, entry_id=query_copy.query_id, ) @@ -621,8 +626,8 @@ def copy_query(request: Request, query_copy: data.QueryCopy) -> BugoutJournalEnt token=MOONSTREAM_ADMIN_ACCESS_TOKEN, journal_id=MOONSTREAM_QUERIES_JOURNAL_ID, title=f"Query:{query_name}", - tags=[tag for tag in entry.tags if tag != "template"], - content=entry.content, + tags=[tag for tag in entry.tags if tag not in ["template", "approved"]], + content=entry.content if entry.content else None, # type: ignore ) except BugoutResponseException as e: raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail) From 4788a3d8a76d4c4762f2c9012fa9486e1901c2c0 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 16 Jun 2023 18:15:39 +0300 Subject: [PATCH 05/14] Add changes. --- crawlers/mooncrawl/mooncrawl/api.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crawlers/mooncrawl/mooncrawl/api.py b/crawlers/mooncrawl/mooncrawl/api.py index f78fffc3..0065efcd 100644 --- a/crawlers/mooncrawl/mooncrawl/api.py +++ b/crawlers/mooncrawl/mooncrawl/api.py @@ -243,18 +243,20 @@ async def queries_data_update_handler( logger.error(f"Unknown blockchain {request_data.blockchain}") raise MoonstreamHTTPException(status_code=403, detail="Unknown blockchain") + blockchain = AvailableBlockchainType(request_data.blockchain) + requested_query = ( requested_query.replace( "transaction_table", - f"{request_data.blockchain}_transactions", + get_transaction_model(blockchain).__tablename__, ) .replace( "block_table", - f"{request_data.blockchain}_blocks", + get_block_model(blockchain).__tablename__, ) .replace( "label_table", - f"{request_data.blockchain}_labels", + get_label_model(blockchain).__tablename__, ) ) From d473db954cf49db4bedccdcb1282c45fc82c5c02 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 19 Jun 2023 00:05:45 +0300 Subject: [PATCH 06/14] Add changes. --- .../mooncrawl/reports_crawler/queries.py | 7 + moonstreamapi/moonstreamapi/routes/queries.py | 177 +++++++++--------- moonstreamapi/moonstreamapi/settings.py | 4 + 3 files changed, 102 insertions(+), 86 deletions(-) diff --git a/crawlers/mooncrawl/mooncrawl/reports_crawler/queries.py b/crawlers/mooncrawl/mooncrawl/reports_crawler/queries.py index fa936131..311f649c 100644 --- a/crawlers/mooncrawl/mooncrawl/reports_crawler/queries.py +++ b/crawlers/mooncrawl/mooncrawl/reports_crawler/queries.py @@ -818,3 +818,10 @@ tokenomics_orange_dao_queries = [ """, }, ] + + +""" + +""" + +template_queries = [] diff --git a/moonstreamapi/moonstreamapi/routes/queries.py b/moonstreamapi/moonstreamapi/routes/queries.py index fd689160..e6a9098c 100644 --- a/moonstreamapi/moonstreamapi/routes/queries.py +++ b/moonstreamapi/moonstreamapi/routes/queries.py @@ -32,7 +32,7 @@ from ..settings import ( MOONSTREAM_S3_QUERIES_BUCKET_PREFIX, MOONSTREAM_QUERIES_JOURNAL_ID, ) -from ..settings import bugout_client as bc +from ..settings import bugout_client as bc, MOONSTREAM_QUERY_TEMPLATE_CONTEXT_TYPE logger = logging.getLogger(__name__) @@ -286,24 +286,26 @@ async def update_query_data_handler( query_name_normalized = name_normalization(query_name) - # check in admin resources - - params = { - "type": data.BUGOUT_RESOURCE_QUERY_RESOLVER, - "name": query_name_normalized, - } + # check in templates try: - admin_resources: BugoutResources = bc.list_resources( - token=MOONSTREAM_ADMIN_ACCESS_TOKEN, params=params + entries = bc.search( + token=MOONSTREAM_ADMIN_ACCESS_TOKEN, + journal_id=MOONSTREAM_QUERIES_JOURNAL_ID, + query=f"tag:template", + filters=[ + f"context_type:{MOONSTREAM_QUERY_TEMPLATE_CONTEXT_TYPE}", + f"context_id:{query_name_normalized}", + ], + limit=1, ) except BugoutResponseException as e: + logger.error(f"Error in get query: {str(e)}") raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail) except Exception as e: - logger.error(f"Error in get query: {str(e)}") raise MoonstreamHTTPException(status_code=500, internal_error=e) - if len(admin_resources.resources) == 0: + if len(entries.results) == 0: try: query_id = get_query_by_name(query_name, token) except NameNormalizationException: @@ -314,60 +316,59 @@ async def update_query_data_handler( except Exception as e: raise MoonstreamHTTPException(status_code=500, internal_error=e) - else: - query_id = admin_resources.resources[0].resource_data["entry_id"] - - try: - entries = bc.search( - token=MOONSTREAM_ADMIN_ACCESS_TOKEN, - journal_id=MOONSTREAM_QUERIES_JOURNAL_ID, - query=f"tag:approved tag:query_id:{query_id} !tag:preapprove", - limit=1, - timeout=5, - ) + try: + entries = bc.search( + token=MOONSTREAM_ADMIN_ACCESS_TOKEN, + journal_id=MOONSTREAM_QUERIES_JOURNAL_ID, + query=f"tag:approved tag:query_id:{query_id} !tag:preapprove", + limit=1, + timeout=5, + ) + except BugoutResponseException as e: + logger.error(f"Error in get query: {str(e)}") + raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail) + except Exception as e: + raise MoonstreamHTTPException(status_code=500, internal_error=e) if len(entries.results) == 0: raise MoonstreamHTTPException( status_code=403, detail="Query not approved yet." ) + else: + query_id = entries.results[0].id - s3_response = None + s3_response = None - if entries.results[0].content: - content = entries.results[0].content + if entries.results[0].content: + content = entries.results[0].content - tags = entries.results[0].tags + tags = entries.results[0].tags - file_type = "json" + file_type = "json" - if "ext:csv" in tags: - file_type = "csv" + if "ext:csv" in tags: + file_type = "csv" - responce = requests.post( - f"{MOONSTREAM_CRAWLERS_SERVER_URL}:{MOONSTREAM_CRAWLERS_SERVER_PORT}/jobs/{query_id}/query_update", - json={ - "query": content, - "params": request_update.params, - "file_type": file_type, - "blockchain": request_update.blockchain - if request_update.blockchain - else None, - }, - timeout=5, + responce = requests.post( + f"{MOONSTREAM_CRAWLERS_SERVER_URL}:{MOONSTREAM_CRAWLERS_SERVER_PORT}/jobs/{query_id}/query_update", + json={ + "query": content, + "params": request_update.params, + "file_type": file_type, + "blockchain": request_update.blockchain + if request_update.blockchain + else None, + }, + timeout=5, + ) + + if responce.status_code != 200: + raise MoonstreamHTTPException( + status_code=responce.status_code, + detail=responce.text, ) - if responce.status_code != 200: - raise MoonstreamHTTPException( - status_code=responce.status_code, - detail=responce.text, - ) - - s3_response = data.QueryPresignUrl(**responce.json()) - except BugoutResponseException as e: - logger.error(f"Error in updating query: {str(e)}") - raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail) - except Exception as e: - raise MoonstreamHTTPException(status_code=500, internal_error=e) + s3_response = data.QueryPresignUrl(**responce.json()) return s3_response @@ -390,47 +391,54 @@ async def get_access_link_handler( query_name_normalized = name_normalization(query_name) - params = { - "type": data.BUGOUT_RESOURCE_QUERY_RESOLVER, - "name": query_name_normalized, - } - - try: - admin_resources: BugoutResources = bc.list_resources( - token=MOONSTREAM_ADMIN_ACCESS_TOKEN, params=params - ) - except BugoutResponseException as e: - raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail) - except Exception as e: - logger.error(f"Error in get query: {str(e)}") - raise MoonstreamHTTPException(status_code=500, internal_error=e) - - if len(admin_resources.resources) == 0: - try: - query_id = get_query_by_name(query_name, token) - except NameNormalizationException: - raise MoonstreamHTTPException( - status_code=403, - detail=f"Provided query name can't be normalize please select different.", - ) - except Exception as e: - raise MoonstreamHTTPException(status_code=500, internal_error=e) - - else: - query_id = admin_resources.resources[0].resource_data["entry_id"] + # check in templattes try: entries = bc.search( token=MOONSTREAM_ADMIN_ACCESS_TOKEN, journal_id=MOONSTREAM_QUERIES_JOURNAL_ID, - query=f"tag:approved tag:query_id:{query_id} !tag:preapprove", + query=f"tag:template", + filters=[ + f"context_type:{MOONSTREAM_QUERY_TEMPLATE_CONTEXT_TYPE}", + f"context_id:{query_name_normalized}", + ], limit=1, - timeout=5, ) + except BugoutResponseException as e: + logger.error(f"Error in get query: {str(e)}") + raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail) + except Exception as e: + raise MoonstreamHTTPException(status_code=500, internal_error=e) + + if len(entries.results) == 0: + + query_id = get_query_by_name(query_name, token) + + try: + + entries = bc.search( + token=MOONSTREAM_ADMIN_ACCESS_TOKEN, + journal_id=MOONSTREAM_QUERIES_JOURNAL_ID, + query=f"tag:approved tag:query_id:{query_id} !tag:preapprove", + limit=1, + timeout=5, + ) + except BugoutResponseException as e: + logger.error(f"Error in get query: {str(e)}") + raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail) + except Exception as e: + raise MoonstreamHTTPException(status_code=500, internal_error=e) + + if len(entries.results) == 0: + raise MoonstreamHTTPException( + status_code=403, detail="Query not approved yet." + ) + + try: s3_response = None - if entries.results and entries.results[0].content: + if entries.results[0].content: passed_params = dict(request_update.params) tags = entries.results[0].tags @@ -453,9 +461,6 @@ async def get_access_link_handler( http_method="GET", ) s3_response = data.QueryPresignUrl(url=stats_presigned_url) - except BugoutResponseException as e: - logger.error(f"Error in get access link: {str(e)}") - raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail) except Exception as e: logger.error(f"Error in get access link: {str(e)}") raise MoonstreamHTTPException(status_code=500, internal_error=e) diff --git a/moonstreamapi/moonstreamapi/settings.py b/moonstreamapi/moonstreamapi/settings.py index b988a85c..052cbb4b 100644 --- a/moonstreamapi/moonstreamapi/settings.py +++ b/moonstreamapi/moonstreamapi/settings.py @@ -129,3 +129,7 @@ if MOONSTREAM_S3_QUERIES_BUCKET_PREFIX == "": BUGOUT_RESOURCE_TYPE_SUBSCRIPTION = "subscription" BUGOUT_RESOURCE_TYPE_ENTITY_SUBSCRIPTION = "entity_subscription" BUGOUT_RESOURCE_TYPE_DASHBOARD = "dashboards" + +### Moonstream queries + +MOONSTREAM_QUERY_TEMPLATE_CONTEXT_TYPE = "moonstream_query_template" From 0a7a5a7d99401f5b0970536d5c2c3ee5e1719cd6 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 19 Jun 2023 01:19:10 +0300 Subject: [PATCH 07/14] Add changes. --- crawlers/mooncrawl/mooncrawl/api.py | 10 +++---- moonstreamapi/moonstreamapi/admin/cli.py | 29 ++++++++++++++++++- moonstreamapi/moonstreamapi/routes/queries.py | 13 ++++----- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/crawlers/mooncrawl/mooncrawl/api.py b/crawlers/mooncrawl/mooncrawl/api.py index 0065efcd..08bee314 100644 --- a/crawlers/mooncrawl/mooncrawl/api.py +++ b/crawlers/mooncrawl/mooncrawl/api.py @@ -239,7 +239,7 @@ async def queries_data_update_handler( requested_query = request_data.query if request_data.blockchain: - if request_data.blockchain not in AvailableBlockchainType.values(): + if request_data.blockchain not in [i.value for i in AvailableBlockchainType]: logger.error(f"Unknown blockchain {request_data.blockchain}") raise MoonstreamHTTPException(status_code=403, detail="Unknown blockchain") @@ -247,22 +247,22 @@ async def queries_data_update_handler( requested_query = ( requested_query.replace( - "transaction_table", + "__transactions_table__", get_transaction_model(blockchain).__tablename__, ) .replace( - "block_table", + "__blocks_table__", get_block_model(blockchain).__tablename__, ) .replace( - "label_table", + "__labels_table__", get_label_model(blockchain).__tablename__, ) ) # Check if it can transform to TextClause try: - query = text(request_data.query) + query = text(requested_query) except Exception as e: logger.error( f"Can't parse query {query_id} to TextClause in drones /query_update endpoint, error: {e}" diff --git a/moonstreamapi/moonstreamapi/admin/cli.py b/moonstreamapi/moonstreamapi/admin/cli.py index a765e820..5ede37dd 100644 --- a/moonstreamapi/moonstreamapi/admin/cli.py +++ b/moonstreamapi/moonstreamapi/admin/cli.py @@ -15,7 +15,7 @@ from moonstreamdb.db import SessionLocal from ..settings import BUGOUT_BROOD_URL, BUGOUT_SPIRE_URL, MOONSTREAM_APPLICATION_ID from ..web3_provider import yield_web3_provider -from . import subscription_types, subscriptions, moonworm_tasks +from . import subscription_types, subscriptions, moonworm_tasks, queries from .migrations import ( checksum_address, update_dashboard_subscription_key, @@ -478,6 +478,33 @@ This CLI is configured to work with the following API URLs: parser_moonworm_tasks_add.set_defaults(func=moonworm_tasks_add_subscription_handler) + + + queries_parser = subcommands.add_parser( + "queries", description="Manage Moonstream queries" + ) + queries_parser.set_defaults(func=lambda _: queries_parser.print_help()) + + + + queries_subcommands = queries_parser.add_subparsers( + description="Query commands" + ) + + create_query_parser = queries_subcommands.add_parser( + "create-template", description="Create query template" + ) + + create_query_parser.add_argument( + "--query-file", + required=True, + type=argparse.FileType("r"), + help="File containing the query to add", + ) + create_query_parser.add_argument( + "-n", "--name", required=True, help="Name for the new query" + ) + create_query_parser.set_defaults(func=queries.create_query_template) args = parser.parse_args() args.func(args) diff --git a/moonstreamapi/moonstreamapi/routes/queries.py b/moonstreamapi/moonstreamapi/routes/queries.py index e6a9098c..5adfe138 100644 --- a/moonstreamapi/moonstreamapi/routes/queries.py +++ b/moonstreamapi/moonstreamapi/routes/queries.py @@ -292,10 +292,9 @@ async def update_query_data_handler( entries = bc.search( token=MOONSTREAM_ADMIN_ACCESS_TOKEN, journal_id=MOONSTREAM_QUERIES_JOURNAL_ID, - query=f"tag:template", + query=f"tag:query_template tag:query_url:{query_name_normalized}", filters=[ f"context_type:{MOONSTREAM_QUERY_TEMPLATE_CONTEXT_TYPE}", - f"context_id:{query_name_normalized}", ], limit=1, ) @@ -314,6 +313,7 @@ async def update_query_data_handler( detail=f"Provided query name can't be normalize please select different.", ) except Exception as e: + logger.error(f"Error in get query: {str(e)}") raise MoonstreamHTTPException(status_code=500, internal_error=e) try: @@ -335,7 +335,7 @@ async def update_query_data_handler( status_code=403, detail="Query not approved yet." ) else: - query_id = entries.results[0].id + query_id = entries.results[0].entry_url.split("/")[-1] s3_response = None @@ -397,10 +397,9 @@ async def get_access_link_handler( entries = bc.search( token=MOONSTREAM_ADMIN_ACCESS_TOKEN, journal_id=MOONSTREAM_QUERIES_JOURNAL_ID, - query=f"tag:template", + query=f"tag:query_template tag:query_url:{query_name_normalized}", filters=[ - f"context_type:{MOONSTREAM_QUERY_TEMPLATE_CONTEXT_TYPE}", - f"context_id:{query_name_normalized}", + f"context_type:{MOONSTREAM_QUERY_TEMPLATE_CONTEXT_TYPE}" ], limit=1, ) @@ -529,7 +528,7 @@ def get_suggested_queries( Return set of suggested queries for user """ - filters = ["#type:query", "#approved", "#template"] + filters = ["tag:approved", "tag:query_template"] if supported_interfaces: filters.extend( From 39047c8022e25b41e1f7967b511af949b9ac3924 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 19 Jun 2023 01:36:20 +0300 Subject: [PATCH 08/14] Add interfaces response. --- moonstreamapi/moonstreamapi/data.py | 4 + moonstreamapi/moonstreamapi/routes/queries.py | 118 +++++++++--------- 2 files changed, 65 insertions(+), 57 deletions(-) diff --git a/moonstreamapi/moonstreamapi/data.py b/moonstreamapi/moonstreamapi/data.py index ee0b0273..7dcdd79d 100644 --- a/moonstreamapi/moonstreamapi/data.py +++ b/moonstreamapi/moonstreamapi/data.py @@ -302,3 +302,7 @@ class QueryInfoResponse(BaseModel): class QueryCopy(BaseModel): query_id: str name: str + +class SuggestedQueriesResponse(BaseModel): + interfaces: Dict[str, Any] = Field(default_factory=dict) + queries: List[Any] = Field(default_factory=list) \ No newline at end of file diff --git a/moonstreamapi/moonstreamapi/routes/queries.py b/moonstreamapi/moonstreamapi/routes/queries.py index 5adfe138..f727985c 100644 --- a/moonstreamapi/moonstreamapi/routes/queries.py +++ b/moonstreamapi/moonstreamapi/routes/queries.py @@ -155,6 +155,67 @@ async def create_query_handler( return entry + +@router.get("/templates", tags=["queries"]) +def get_suggested_queries( + request: Request, + supported_interfaces: Optional[List[str]] = None, + address: Optional[str] = None, + title: Optional[str] = None, + limit: int = 10, +) -> data.SuggestedQueriesResponse: + """ + Return set of suggested queries for user + """ + + filters = ["tag:approved", "tag:query_template"] + + if supported_interfaces: + filters.extend( + [f"?#interface:{interface}" for interface in supported_interfaces] + ) + + if address: + filters.append(f"?#address:{address}") + + if title: + filters.append(title) + + query = " ".join(filters) + + try: + queries = bc.search( + token=MOONSTREAM_ADMIN_ACCESS_TOKEN, + journal_id=MOONSTREAM_QUERIES_JOURNAL_ID, + query=query, + limit=100, + timeout=5, + ) + except BugoutResponseException as e: + raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail) + except Exception as e: + raise MoonstreamHTTPException(status_code=500, internal_error=e) + + # make split by interfaces + + interfaces: Dict[str, Any] = {} + + for entry in queries.results: + for tag in entry.tags: + if tag.startswith("interface:"): + interface = tag.split(":")[1] + + if interface not in interfaces: + interfaces[interface] = [] + + interfaces[interface].append(entry) + + return data.SuggestedQueriesResponse( + queries=queries.results, + interfaces=interfaces, + ) + + @router.get("/{query_name}/query", tags=["queries"]) async def get_query_handler( request: Request, query_name: str @@ -516,63 +577,6 @@ async def remove_query_handler( return entry -@router.get("/templates", tags=["queries"]) -def get_suggested_queries( - request: Request, - supported_interfaces: Optional[List[str]] = None, - address: Optional[str] = None, - title: Optional[str] = None, - limit: int = 10, -) -> Any: - """ - Return set of suggested queries for user - """ - - filters = ["tag:approved", "tag:query_template"] - - if supported_interfaces: - filters.extend( - [f"?#interface:{interface}" for interface in supported_interfaces] - ) - - if address: - filters.append(f"?#address:{address}") - - if title: - filters.append(title) - - query = " ".join(filters) - - try: - queries = bc.search( - token=MOONSTREAM_ADMIN_ACCESS_TOKEN, - journal_id=MOONSTREAM_QUERIES_JOURNAL_ID, - query=query, - limit=100, - timeout=5, - ) - except BugoutResponseException as e: - raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail) - except Exception as e: - raise MoonstreamHTTPException(status_code=500, internal_error=e) - - # make split by interfaces - - interfaces: Dict[str, Any] = {} - - for entry in queries.results: - for tag in entry.tags: - if tag.startswith("interface:"): - interface = tag.split(":")[1] - - if interface not in interfaces: - interfaces[interface] = [] - - interfaces[interface].append(entry) - - return interfaces - - @router.post("/copy", tags=["queries"]) def copy_query(request: Request, query_copy: data.QueryCopy) -> BugoutJournalEntry: """ From a8b47b630cc6cbecb0afa56397d5c48f471bd9d1 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 19 Jun 2023 13:32:00 +0300 Subject: [PATCH 09/14] Bump bugout client version. --- moonstreamapi/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moonstreamapi/setup.py b/moonstreamapi/setup.py index dc940b79..9602d99a 100644 --- a/moonstreamapi/setup.py +++ b/moonstreamapi/setup.py @@ -13,7 +13,7 @@ setup( install_requires=[ "appdirs", "boto3", - "bugout>=0.1.19", + "bugout>=0.2.9", "moonstream-entity>=0.0.5", "fastapi", "moonstreamdb>=0.3.3", From 59d8342faa70ccb18757c97b0aa5c4510de8e949 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 19 Jun 2023 13:56:47 +0300 Subject: [PATCH 10/14] Add missing cli file --- moonstreamapi/moonstreamapi/admin/queries.py | 84 ++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 moonstreamapi/moonstreamapi/admin/queries.py diff --git a/moonstreamapi/moonstreamapi/admin/queries.py b/moonstreamapi/moonstreamapi/admin/queries.py new file mode 100644 index 00000000..9828a0fa --- /dev/null +++ b/moonstreamapi/moonstreamapi/admin/queries.py @@ -0,0 +1,84 @@ +import argparse +from collections import Counter +import json + +from bugout.data import BugoutResources +from bugout.exceptions import BugoutResponseException +from moonstream.client import Moonstream # type: ignore +import logging +from typing import Dict, Any +import textwrap +from sqlalchemy import text + + +from ..data import BUGOUT_RESOURCE_QUERY_RESOLVER +from ..settings import ( + BUGOUT_REQUEST_TIMEOUT_SECONDS, + MOONSTREAM_ADMIN_ACCESS_TOKEN, + MOONSTREAM_QUERIES_JOURNAL_ID, +) +from ..settings import bugout_client as bc, MOONSTREAM_QUERY_TEMPLATE_CONTEXT_TYPE +from ..actions import get_all_entries_from_search, name_normalization + + +logger = logging.getLogger(__name__) + + + +def create_query_template(args: argparse.Namespace) -> None: + """ + Create query template for all queries resources. + """ + + query = "" + with args.query_file: + query = textwrap.indent(args.query_file.read(), " ") + + ### Create query template + + name = f"template_{name_normalization(args.name)}" + + try: + + entry = bc.create_entry( + journal_id=MOONSTREAM_QUERIES_JOURNAL_ID, + title=args.name, + content=query, + tags=["query_template", f"query_url:{name}"], + context_id=name, + context_type=MOONSTREAM_QUERY_TEMPLATE_CONTEXT_TYPE, + context_url=name, + token=MOONSTREAM_ADMIN_ACCESS_TOKEN, + timeout=BUGOUT_REQUEST_TIMEOUT_SECONDS, + ) + + except BugoutResponseException as err: + logger.error(f"Failed to create query template: {err}") + return + except Exception as err: + logger.error(f"Failed to create query template: {err}") + return + + logger.info(f"Query template created: {entry.id}") + logger.info(f"Query template created url name: {name}") + + + ### Add query id + + try: + bc.create_tags( + journal_id=MOONSTREAM_QUERIES_JOURNAL_ID, + entry_id=entry.id, + tags=[f"query_id:{entry.id}"], + token=MOONSTREAM_ADMIN_ACCESS_TOKEN, + timeout=BUGOUT_REQUEST_TIMEOUT_SECONDS, + ) + + except BugoutResponseException as err: + logger.error(f"Failed to add query id: {err}") + return + except Exception as err: + logger.error(f"Failed to add query id: {err}") + return + + logger.info(f"Query created: {json.dumps(entry.dict(), indent=4)}") \ No newline at end of file From c1fdf253423f9bb594453a498952094ba900fa5a Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 19 Jun 2023 13:58:46 +0300 Subject: [PATCH 11/14] Bump version --- moonstreamapi/moonstreamapi/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moonstreamapi/moonstreamapi/version.py b/moonstreamapi/moonstreamapi/version.py index 286247fc..fbc7f516 100644 --- a/moonstreamapi/moonstreamapi/version.py +++ b/moonstreamapi/moonstreamapi/version.py @@ -2,4 +2,4 @@ Moonstream library and API version. """ -MOONSTREAMAPI_VERSION = "0.2.5" +MOONSTREAMAPI_VERSION = "0.2.6" From c848de471422dc8d4b6d221d406b05baa8117710 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 19 Jun 2023 14:01:44 +0300 Subject: [PATCH 12/14] Remove query copy. --- moonstreamapi/moonstreamapi/data.py | 5 - moonstreamapi/moonstreamapi/routes/queries.py | 103 +----------------- 2 files changed, 1 insertion(+), 107 deletions(-) diff --git a/moonstreamapi/moonstreamapi/data.py b/moonstreamapi/moonstreamapi/data.py index 7dcdd79d..e61e86c0 100644 --- a/moonstreamapi/moonstreamapi/data.py +++ b/moonstreamapi/moonstreamapi/data.py @@ -298,11 +298,6 @@ class QueryInfoResponse(BaseModel): created_at: Optional[datetime] updated_at: Optional[datetime] - -class QueryCopy(BaseModel): - query_id: str - name: str - class SuggestedQueriesResponse(BaseModel): interfaces: Dict[str, Any] = Field(default_factory=dict) queries: List[Any] = Field(default_factory=list) \ No newline at end of file diff --git a/moonstreamapi/moonstreamapi/routes/queries.py b/moonstreamapi/moonstreamapi/routes/queries.py index f727985c..5d364668 100644 --- a/moonstreamapi/moonstreamapi/routes/queries.py +++ b/moonstreamapi/moonstreamapi/routes/queries.py @@ -574,105 +574,4 @@ async def remove_query_handler( except Exception as e: raise MoonstreamHTTPException(status_code=500, internal_error=e) - return entry - - -@router.post("/copy", tags=["queries"]) -def copy_query(request: Request, query_copy: data.QueryCopy) -> BugoutJournalEntry: - """ - Create copy of query - """ - - token = request.state.token - user = request.state.user - - # get real query by id - - try: - entry = bc.get_entry( - token=MOONSTREAM_ADMIN_ACCESS_TOKEN, - journal_id=MOONSTREAM_QUERIES_JOURNAL_ID, - entry_id=query_copy.query_id, - ) - except BugoutResponseException as e: - raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail) - except Exception as e: - raise MoonstreamHTTPException(status_code=500, internal_error=e) - - # Check already existed queries - - params = { - "type": data.BUGOUT_RESOURCE_QUERY_RESOLVER, - } - try: - resources: BugoutResources = bc.list_resources(token=token, params=params) - except BugoutResponseException as e: - raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail) - except Exception as e: - raise MoonstreamHTTPException(status_code=500, internal_error=e) - - used_queries: List[str] = [ - resource.resource_data["name"] for resource in resources.resources - ] - try: - query_name = name_normalization(query_copy.name) - except NameNormalizationException: - raise MoonstreamHTTPException( - status_code=403, - detail=f"Provided query name can't be normalize please select different.", - ) - - if query_name in used_queries: - raise MoonstreamHTTPException( - status_code=404, - detail=f"Provided query name already use. Please remove it or use PUT /{query_name} for update query", - ) - - try: - # Put query to journal - entry = bc.create_entry( - token=MOONSTREAM_ADMIN_ACCESS_TOKEN, - journal_id=MOONSTREAM_QUERIES_JOURNAL_ID, - title=f"Query:{query_name}", - tags=[tag for tag in entry.tags if tag not in ["template", "approved"]], - content=entry.content if entry.content else None, # type: ignore - ) - except BugoutResponseException as e: - raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail) - except Exception as e: - raise MoonstreamHTTPException(status_code=500, internal_error=e) - - try: - # create resource query_name_resolver - bc.create_resource( - token=token, - application_id=MOONSTREAM_APPLICATION_ID, - resource_data={ - "type": data.BUGOUT_RESOURCE_QUERY_RESOLVER, - "user_id": str(user.id), - "user": str(user.username), - "name": query_name, - "entry_id": str(entry.id), - }, - ) - except BugoutResponseException as e: - logger.error(f"Error creating name resolving resource: {str(e)}") - raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail) - except Exception as e: - raise MoonstreamHTTPException(status_code=500, internal_error=e) - - try: - bc.update_tags( - token=MOONSTREAM_ADMIN_ACCESS_TOKEN, - journal_id=MOONSTREAM_QUERIES_JOURNAL_ID, - entry_id=entry.id, - tags=[f"query_id:{entry.id}"], - ) - - except BugoutResponseException as e: - logger.error(f"Error in applind tags to query entry: {str(e)}") - raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail) - except Exception as e: - raise MoonstreamHTTPException(status_code=500, internal_error=e) - - return entry + return entry \ No newline at end of file From 9dbd3b2871c49bec8d210545ee91be5434276f16 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 19 Jun 2023 14:13:16 +0300 Subject: [PATCH 13/14] Delete queries templates from report_crawler. --- crawlers/mooncrawl/mooncrawl/reports_crawler/queries.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/crawlers/mooncrawl/mooncrawl/reports_crawler/queries.py b/crawlers/mooncrawl/mooncrawl/reports_crawler/queries.py index 311f649c..fa936131 100644 --- a/crawlers/mooncrawl/mooncrawl/reports_crawler/queries.py +++ b/crawlers/mooncrawl/mooncrawl/reports_crawler/queries.py @@ -818,10 +818,3 @@ tokenomics_orange_dao_queries = [ """, }, ] - - -""" - -""" - -template_queries = [] From 8051287d6585bd060bea3a7036804ca6839710d9 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 19 Jun 2023 16:14:54 +0300 Subject: [PATCH 14/14] Add changes. --- moonstreamapi/moonstreamapi/routes/queries.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/moonstreamapi/moonstreamapi/routes/queries.py b/moonstreamapi/moonstreamapi/routes/queries.py index 5d364668..ec9f3e34 100644 --- a/moonstreamapi/moonstreamapi/routes/queries.py +++ b/moonstreamapi/moonstreamapi/routes/queries.py @@ -158,7 +158,6 @@ async def create_query_handler( @router.get("/templates", tags=["queries"]) def get_suggested_queries( - request: Request, supported_interfaces: Optional[List[str]] = None, address: Optional[str] = None, title: Optional[str] = None, @@ -188,7 +187,7 @@ def get_suggested_queries( token=MOONSTREAM_ADMIN_ACCESS_TOKEN, journal_id=MOONSTREAM_QUERIES_JOURNAL_ID, query=query, - limit=100, + limit=limit, timeout=5, ) except BugoutResponseException as e: