kopia lustrzana https://github.com/bugout-dev/moonstream
Merge pull request #469 from bugout-dev/rid-of-public-provider
Remove public provider and nfts endpoint.pull/483/head clients/python/v0.0.3
commit
6c895bc114
|
@ -11,7 +11,6 @@ from fastapi.middleware.cors import CORSMiddleware
|
|||
from . import actions
|
||||
from . import data
|
||||
from .routes.address_info import router as addressinfo_router
|
||||
from .routes.nft import router as nft_router
|
||||
from .routes.streams import router as streams_router
|
||||
from .routes.subscriptions import router as subscriptions_router
|
||||
from .routes.txinfo import router as txinfo_router
|
||||
|
@ -32,7 +31,6 @@ tags_metadata = [
|
|||
"name": "labels",
|
||||
"description": "Labels for transactions, addresses with additional information.",
|
||||
},
|
||||
{"name": "nft", "description": "NFT market summaries."},
|
||||
{"name": "streams", "description": "Operations with data streams and filters."},
|
||||
{"name": "subscriptions", "description": "Operations with user subscriptions."},
|
||||
{"name": "time", "description": "Server timestamp endpoints."},
|
||||
|
@ -124,7 +122,6 @@ async def status_handler() -> data.StatusResponse:
|
|||
|
||||
|
||||
app.include_router(addressinfo_router)
|
||||
app.include_router(nft_router)
|
||||
app.include_router(streams_router)
|
||||
app.include_router(subscriptions_router)
|
||||
app.include_router(txinfo_router)
|
||||
|
|
|
@ -327,34 +327,6 @@ class EthereumTXPoolProvider(BugoutEventProvider):
|
|||
return subscriptions_filters
|
||||
|
||||
|
||||
class PublicDataProvider(BugoutEventProvider):
|
||||
def __init__(
|
||||
self,
|
||||
event_type: str,
|
||||
description: str,
|
||||
default_time_interval_seconds: int,
|
||||
estimated_events_per_time_interval: float,
|
||||
tags: Optional[List[str]] = None,
|
||||
batch_size: int = 100,
|
||||
timeout: float = 30.0,
|
||||
):
|
||||
|
||||
super().__init__(
|
||||
event_type=event_type,
|
||||
description=description,
|
||||
default_time_interval_seconds=default_time_interval_seconds,
|
||||
estimated_events_per_time_interval=estimated_events_per_time_interval,
|
||||
tags=tags,
|
||||
batch_size=batch_size,
|
||||
timeout=timeout,
|
||||
)
|
||||
|
||||
def parse_filters(
|
||||
self, query: StreamQuery, user_subscriptions: Dict[str, List[BugoutResource]]
|
||||
) -> Optional[List[str]]:
|
||||
return []
|
||||
|
||||
|
||||
whalewatch_description = """Event provider for Ethereum whale watch.
|
||||
|
||||
Shows the top 10 addresses active on the Ethereum blockchain over the last hour in the following categories:
|
||||
|
@ -364,7 +336,7 @@ Shows the top 10 addresses active on the Ethereum blockchain over the last hour
|
|||
4. Amount (in WEI) received
|
||||
|
||||
To restrict your queries to this provider, add a filter of \"type:ethereum_whalewatch\" to your query (query parameter: \"q\") on the /streams endpoint."""
|
||||
whalewatch_provider = PublicDataProvider(
|
||||
whalewatch_provider = BugoutEventProvider(
|
||||
event_type="ethereum_whalewatch",
|
||||
description=whalewatch_description,
|
||||
default_time_interval_seconds=310,
|
||||
|
@ -384,21 +356,3 @@ ethereum_txpool_provider = EthereumTXPoolProvider(
|
|||
estimated_events_per_time_interval=50,
|
||||
tags=[f"client:{ETHTXPOOL_HUMBUG_CLIENT_ID}"],
|
||||
)
|
||||
|
||||
nft_summary_description = """Event provider for NFT market summaries.
|
||||
|
||||
This provider periodically generates NFT market summaries for the last hour of market activity.
|
||||
|
||||
Currently, it summarizes the activities on the following NFT markets:
|
||||
1. The Ethereum market
|
||||
|
||||
This provider is currently not accessible for subscription. The data from this provider is publicly
|
||||
available at the /nft endpoint."""
|
||||
nft_summary_provider = PublicDataProvider(
|
||||
event_type="nft_summary",
|
||||
description=nft_summary_description,
|
||||
# 40 blocks per summary, 15 seconds per block + 2 seconds wiggle room.
|
||||
default_time_interval_seconds=40 * 17,
|
||||
estimated_events_per_time_interval=1,
|
||||
tags=["crawl_type:nft_ethereum"],
|
||||
)
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
"""
|
||||
Moonstream's /nft endpoints.
|
||||
|
||||
These endpoints provide public access to NFT market summaries. No authentication required.
|
||||
"""
|
||||
import logging
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from moonstreamdb import db
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .. import data
|
||||
from ..providers.bugout import nft_summary_provider
|
||||
from ..settings import (
|
||||
bugout_client,
|
||||
MOONSTREAM_ADMIN_ACCESS_TOKEN,
|
||||
MOONSTREAM_DATA_JOURNAL_ID,
|
||||
)
|
||||
from ..stream_queries import StreamQuery
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
router = APIRouter(prefix="/nft")
|
||||
|
||||
|
||||
@router.get("/", tags=["streams"], response_model=data.GetEventsResponse)
|
||||
async def stream_handler(
|
||||
start_time: int = Query(0),
|
||||
end_time: Optional[int] = Query(None),
|
||||
include_start: bool = Query(False),
|
||||
include_end: bool = Query(False),
|
||||
db_session: Session = Depends(db.yield_db_session),
|
||||
) -> data.GetEventsResponse:
|
||||
stream_boundary = data.StreamBoundary(
|
||||
start_time=start_time,
|
||||
end_time=end_time,
|
||||
include_start=include_start,
|
||||
include_end=include_end,
|
||||
)
|
||||
|
||||
result = nft_summary_provider.get_events(
|
||||
db_session=db_session,
|
||||
bugout_client=bugout_client,
|
||||
data_journal_id=MOONSTREAM_DATA_JOURNAL_ID,
|
||||
data_access_token=MOONSTREAM_ADMIN_ACCESS_TOKEN,
|
||||
stream_boundary=stream_boundary,
|
||||
user_subscriptions={nft_summary_provider.event_type: []},
|
||||
query=StreamQuery(subscription_types=[nft_summary_provider.event_type]),
|
||||
)
|
||||
|
||||
if result is None:
|
||||
return data.GetEventsResponse(stream_boundary=stream_boundary, events=[])
|
||||
|
||||
provider_stream_boundary, events = result
|
||||
return data.GetEventsResponse(
|
||||
stream_boundary=provider_stream_boundary, events=events
|
||||
)
|
Ładowanie…
Reference in New Issue