kopia lustrzana https://github.com/bugout-dev/moonstream
Add changes.
rodzic
8cb7dfb8be
commit
b2bf46ad7e
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
Ładowanie…
Reference in New Issue