From ea4a2685b51b7adee1b6688c59dae26f65029d20 Mon Sep 17 00:00:00 2001 From: Andrey Dolgolev Date: Mon, 15 Nov 2021 11:53:14 +0200 Subject: [PATCH 1/2] Add fix for resolve blockchain on s3 path in contracts_data. --- backend/moonstreamapi/routes/dashboards.py | 8 +++++++- crawlers/mooncrawl/mooncrawl/stats_worker/dashboard.py | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/backend/moonstreamapi/routes/dashboards.py b/backend/moonstreamapi/routes/dashboards.py index ba92c52d..4711a2f5 100644 --- a/backend/moonstreamapi/routes/dashboards.py +++ b/backend/moonstreamapi/routes/dashboards.py @@ -33,6 +33,12 @@ BUGOUT_RESOURCE_TYPE_DASHBOARD = "dashboards" BUGOUT_RESOURCE_TYPE_SUBSCRIPTION = "subscription" +blockchain_by_subscription_id = { + "ethereum_blockchain": "ethereum", + "polygon_blockchain": "polygon", +} + + @router.post("/", tags=["dashboards"], response_model=BugoutResource) async def add_dashboard_handler( request: Request, dashboard: data.DashboardCreate @@ -410,7 +416,7 @@ async def get_dashboard_data_links_handler( stats[subscription.id] = {} for timescale in available_timescales: try: - result_key = f'{MOONSTREAM_S3_SMARTCONTRACTS_ABI_PREFIX}/contracts_data/{subscription.resource_data["address"]}/{hash}/v1/{timescale}.json' + result_key = f'{MOONSTREAM_S3_SMARTCONTRACTS_ABI_PREFIX}/{blockchain_by_subscription_id[subscription.resource_data["subscription_type_id"]]}/contracts_data/{subscription.resource_data["address"]}/{hash}/v1/{timescale}.json' stats_presigned_url = s3_client.generate_presigned_url( "get_object", Params={ diff --git a/crawlers/mooncrawl/mooncrawl/stats_worker/dashboard.py b/crawlers/mooncrawl/mooncrawl/stats_worker/dashboard.py index a6a3382e..4da0114d 100644 --- a/crawlers/mooncrawl/mooncrawl/stats_worker/dashboard.py +++ b/crawlers/mooncrawl/mooncrawl/stats_worker/dashboard.py @@ -35,6 +35,11 @@ subscription_id_by_blockchain = { "polygon": "polygon_blockchain", } +blockchain_by_subscription_id = { + "ethereum_blockchain": "ethereum", + "polygon_blockchain": "polygon", +} + class TimeScale(Enum): # year = "year" @@ -70,7 +75,7 @@ def push_statistics( ) -> None: result_bytes = json.dumps(statistics_data).encode("utf-8") - result_key = f'{MOONSTREAM_S3_SMARTCONTRACTS_ABI_PREFIX}/contracts_data/{subscription.resource_data["address"]}/{hash}/v1/{timescale}.json' + result_key = f'{MOONSTREAM_S3_SMARTCONTRACTS_ABI_PREFIX}/{blockchain_by_subscription_id[subscription.resource_data["subscription_type_id"]]}/contracts_data/{subscription.resource_data["address"]}/{hash}/v1/{timescale}.json' s3 = boto3.client("s3") s3.put_object( From ea0a81476f53a1a21f4ffb2a44d41a37f66bf893 Mon Sep 17 00:00:00 2001 From: Andrey Dolgolev Date: Mon, 15 Nov 2021 12:27:45 +0200 Subject: [PATCH 2/2] Add blockchain name to s3 path for contract abi. --- backend/moonstreamapi/actions.py | 8 +++++++- crawlers/mooncrawl/mooncrawl/stats_worker/dashboard.py | 4 +--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/backend/moonstreamapi/actions.py b/backend/moonstreamapi/actions.py index 0c61df2c..597af7d5 100644 --- a/backend/moonstreamapi/actions.py +++ b/backend/moonstreamapi/actions.py @@ -38,6 +38,12 @@ from web3 import Web3 logger = logging.getLogger(__name__) +blockchain_by_subscription_id = { + "ethereum_blockchain": "ethereum", + "polygon_blockchain": "polygon", +} + + class StatusAPIException(Exception): """ Raised during checking Moonstream API statuses. @@ -409,7 +415,7 @@ def upload_abi_to_s3( bucket = MOONSTREAM_S3_SMARTCONTRACTS_ABI_BUCKET result_bytes = abi.encode("utf-8") - result_key = f"{MOONSTREAM_S3_SMARTCONTRACTS_ABI_PREFIX}/abi/{resource.resource_data['address']}/{resource.id}/abi.json" + result_key = f"{MOONSTREAM_S3_SMARTCONTRACTS_ABI_PREFIX}/{blockchain_by_subscription_id[resource.resource_data['subscription_type_id']]}/abi/{resource.resource_data['address']}/{resource.id}/abi.json" s3_client.put_object( Body=result_bytes, diff --git a/crawlers/mooncrawl/mooncrawl/stats_worker/dashboard.py b/crawlers/mooncrawl/mooncrawl/stats_worker/dashboard.py index 4da0114d..d5f5d83f 100644 --- a/crawlers/mooncrawl/mooncrawl/stats_worker/dashboard.py +++ b/crawlers/mooncrawl/mooncrawl/stats_worker/dashboard.py @@ -8,7 +8,7 @@ import logging import time from datetime import datetime, timedelta from enum import Enum -from typing import Any, Callable, Dict, List +from typing import Any, Dict, List import boto3 # type: ignore from bugout.data import BugoutResources @@ -465,8 +465,6 @@ def stats_generate_handler(args: argparse.Namespace): ) already_processed.append(f"{address}/{hash}") - time.sleep(10) - def main() -> None: parser = argparse.ArgumentParser(description="Command Line Interface")