kopia lustrzana https://github.com/bugout-dev/moonstream
				
				
				
			Change enviroment variables and fix issues on dashboard creation.
							rodzic
							
								
									143fcea6c6
								
							
						
					
					
						commit
						3ae3f9a390
					
				| 
						 | 
				
			
			@ -30,8 +30,8 @@ from .settings import (
 | 
			
		|||
    BUGOUT_REQUEST_TIMEOUT_SECONDS,
 | 
			
		||||
    MOONSTREAM_ADMIN_ACCESS_TOKEN,
 | 
			
		||||
    MOONSTREAM_DATA_JOURNAL_ID,
 | 
			
		||||
    AWS_S3_SMARTCONTRACTS_ABI_BUCKET,
 | 
			
		||||
    AWS_S3_SMARTCONTRACTS_ABI_PREFIX,
 | 
			
		||||
    MOONSTREAM_S3_SMARTCONTRACTS_ABI_BUCKET,
 | 
			
		||||
    MOONSTREAM_S3_SMARTCONTRACTS_ABI_PREFIX,
 | 
			
		||||
)
 | 
			
		||||
from web3 import Web3
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -406,10 +406,10 @@ def upload_abi_to_s3(
 | 
			
		|||
 | 
			
		||||
    s3_client = boto3.client("s3")
 | 
			
		||||
 | 
			
		||||
    bucket = AWS_S3_SMARTCONTRACTS_ABI_BUCKET
 | 
			
		||||
    bucket = MOONSTREAM_S3_SMARTCONTRACTS_ABI_BUCKET
 | 
			
		||||
 | 
			
		||||
    result_bytes = abi.encode("utf-8")
 | 
			
		||||
    result_key = f"{AWS_S3_SMARTCONTRACTS_ABI_PREFIX}/{resource.resource_data['address']}/{resource.id}/abi.json"
 | 
			
		||||
    result_key = f"{MOONSTREAM_S3_SMARTCONTRACTS_ABI_PREFIX}/abi/{resource.resource_data['address']}/{resource.id}/abi.json"
 | 
			
		||||
 | 
			
		||||
    s3_client.put_object(
 | 
			
		||||
        Body=result_bytes,
 | 
			
		||||
| 
						 | 
				
			
			@ -421,9 +421,7 @@ def upload_abi_to_s3(
 | 
			
		|||
 | 
			
		||||
    update["abi"] = True
 | 
			
		||||
 | 
			
		||||
    update["bucket"] = AWS_S3_SMARTCONTRACTS_ABI_BUCKET
 | 
			
		||||
    update[
 | 
			
		||||
        "s3_path"
 | 
			
		||||
    ] = f"{AWS_S3_SMARTCONTRACTS_ABI_PREFIX}/{resource.resource_data['address']}/{resource.id}/abi.json"
 | 
			
		||||
    update["bucket"] = MOONSTREAM_S3_SMARTCONTRACTS_ABI_BUCKET
 | 
			
		||||
    update["s3_path"] = result_key
 | 
			
		||||
 | 
			
		||||
    return update
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,7 +13,6 @@ USER_ONBOARDING_STATE = "onboarding_state"
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
class TimeScale(Enum):
 | 
			
		||||
    year = "year"
 | 
			
		||||
    month = "month"
 | 
			
		||||
    week = "week"
 | 
			
		||||
    day = "day"
 | 
			
		||||
| 
						 | 
				
			
			@ -232,7 +231,7 @@ class OnboardingState(BaseModel):
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
class DashboardMeta(BaseModel):
 | 
			
		||||
    subscription_id: UUID
 | 
			
		||||
    subscription_id: str
 | 
			
		||||
    generic: Optional[List[Dict[str, str]]]
 | 
			
		||||
    all_methods: bool = False
 | 
			
		||||
    all_events: bool = False
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,10 +16,11 @@ from ..reporter import reporter
 | 
			
		|||
from ..settings import (
 | 
			
		||||
    MOONSTREAM_APPLICATION_ID,
 | 
			
		||||
    bugout_client as bc,
 | 
			
		||||
    SMARTCONTRACTS_ABI_BUCKET,
 | 
			
		||||
    BUGOUT_REQUEST_TIMEOUT_SECONDS,
 | 
			
		||||
    SMARTCONTRACTS_ABI_BUCKET,
 | 
			
		||||
    MOONSTREAM_S3_SMARTCONTRACTS_ABI_BUCKET,
 | 
			
		||||
    MOONSTREAM_S3_SMARTCONTRACTS_ABI_PREFIX,
 | 
			
		||||
)
 | 
			
		||||
import pprint
 | 
			
		||||
 | 
			
		||||
logger = logging.getLogger(__name__)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -67,7 +68,7 @@ async def add_dashboard_handler(
 | 
			
		|||
    s3_client = boto3.client("s3")
 | 
			
		||||
 | 
			
		||||
    available_subscriptions = {
 | 
			
		||||
        resource.id: resource.resource_data for resource in resources.resources
 | 
			
		||||
        str(resource.id): resource.resource_data for resource in resources.resources
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for dashboard_subscription in dashboard_subscriptions:
 | 
			
		||||
| 
						 | 
				
			
			@ -135,10 +136,10 @@ async def add_dashboard_handler(
 | 
			
		|||
            resource_data=dashboard_resource.dict(),
 | 
			
		||||
        )
 | 
			
		||||
    except BugoutResponseException as e:
 | 
			
		||||
        logger.error(f"Error creating subscription resource: {str(e)}")
 | 
			
		||||
        logger.error(f"Error creating dashboard resource: {str(e)}")
 | 
			
		||||
        raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail)
 | 
			
		||||
    except Exception as e:
 | 
			
		||||
        logger.error(f"Error creating subscription resource: {str(e)}")
 | 
			
		||||
        logger.error(f"Error creating dashboard resource: {str(e)}")
 | 
			
		||||
        raise MoonstreamHTTPException(status_code=500, internal_error=e)
 | 
			
		||||
 | 
			
		||||
    return resource
 | 
			
		||||
| 
						 | 
				
			
			@ -407,17 +408,20 @@ async def get_dashboard_data_links_handler(
 | 
			
		|||
        stats[subscription.id] = {}
 | 
			
		||||
        for timescale in available_timescales:
 | 
			
		||||
            try:
 | 
			
		||||
                result_key = f'contracts_data/{subscription.resource_data["address"]}/{hash}/v1/{timescale}.json'
 | 
			
		||||
                result_key = f'{MOONSTREAM_S3_SMARTCONTRACTS_ABI_PREFIX}/contracts_data/{subscription.resource_data["address"]}/{hash}/v1/{timescale}.json'
 | 
			
		||||
                stats_presigned_url = s3_client.generate_presigned_url(
 | 
			
		||||
                    "get_object",
 | 
			
		||||
                    Params={"Bucket": SMARTCONTRACTS_ABI_BUCKET, "Key": result_key},
 | 
			
		||||
                    Params={
 | 
			
		||||
                        "Bucket": MOONSTREAM_S3_SMARTCONTRACTS_ABI_BUCKET,
 | 
			
		||||
                        "Key": result_key,
 | 
			
		||||
                    },
 | 
			
		||||
                    ExpiresIn=300,
 | 
			
		||||
                    HttpMethod="GET",
 | 
			
		||||
                )
 | 
			
		||||
                stats[subscription.id][timescale] = stats_presigned_url
 | 
			
		||||
            except Exception as err:
 | 
			
		||||
                logger.warning(
 | 
			
		||||
                    f"Can't generate S3 presigned url in stats endpoint for Bucket:{SMARTCONTRACTS_ABI_BUCKET}, Key:{result_key} get error:{err}"
 | 
			
		||||
                    f"Can't generate S3 presigned url in stats endpoint for Bucket:{MOONSTREAM_S3_SMARTCONTRACTS_ABI_BUCKET}, Key:{result_key} get error:{err}"
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
    return stats
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -24,8 +24,8 @@ from ..reporter import reporter
 | 
			
		|||
from ..settings import (
 | 
			
		||||
    MOONSTREAM_APPLICATION_ID,
 | 
			
		||||
    bugout_client as bc,
 | 
			
		||||
    AWS_S3_SMARTCONTRACTS_ABI_BUCKET,
 | 
			
		||||
    AWS_S3_SMARTCONTRACTS_ABI_PREFIX,
 | 
			
		||||
    MOONSTREAM_S3_SMARTCONTRACTS_ABI_BUCKET,
 | 
			
		||||
    MOONSTREAM_S3_SMARTCONTRACTS_ABI_PREFIX,
 | 
			
		||||
)
 | 
			
		||||
from ..web3_provider import yield_web3_provider
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -73,14 +73,20 @@ MOONSTREAM_NODE_ETHEREUM_IPC_PORT = os.environ.get(
 | 
			
		|||
    "MOONSTREAM_NODE_ETHEREUM_IPC_PORT", 8545
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
AWS_S3_SMARTCONTRACTS_ABI_BUCKET = os.environ.get("AWS_S3_SMARTCONTRACTS_ABI_BUCKET")
 | 
			
		||||
if AWS_S3_SMARTCONTRACTS_ABI_BUCKET is None:
 | 
			
		||||
MOONSTREAM_S3_SMARTCONTRACTS_ABI_BUCKET = os.environ.get(
 | 
			
		||||
    "MOONSTREAM_S3_SMARTCONTRACTS_ABI_BUCKET"
 | 
			
		||||
)
 | 
			
		||||
if MOONSTREAM_S3_SMARTCONTRACTS_ABI_BUCKET is None:
 | 
			
		||||
    raise ValueError(
 | 
			
		||||
        "AWS_S3_SMARTCONTRACTS_ABI_BUCKET environment variable must be set"
 | 
			
		||||
        "MOONSTREAM_S3_SMARTCONTRACTS_ABI_BUCKET environment variable must be set"
 | 
			
		||||
    )
 | 
			
		||||
AWS_S3_SMARTCONTRACTS_ABI_PREFIX = os.environ.get("AWS_S3_SMARTCONTRACTS_ABI_PREFIX")
 | 
			
		||||
if AWS_S3_SMARTCONTRACTS_ABI_PREFIX is None:
 | 
			
		||||
MOONSTREAM_S3_SMARTCONTRACTS_ABI_PREFIX = os.environ.get(
 | 
			
		||||
    "MOONSTREAM_S3_SMARTCONTRACTS_ABI_PREFIX"
 | 
			
		||||
)
 | 
			
		||||
if MOONSTREAM_S3_SMARTCONTRACTS_ABI_PREFIX is None:
 | 
			
		||||
    raise ValueError(
 | 
			
		||||
        "AWS_S3_SMARTCONTRACTS_ABI_PREFIX environment variable must be set"
 | 
			
		||||
        "MOONSTREAM_S3_SMARTCONTRACTS_ABI_PREFIX environment variable must be set"
 | 
			
		||||
    )
 | 
			
		||||
AWS_S3_SMARTCONTRACTS_ABI_PREFIX = AWS_S3_SMARTCONTRACTS_ABI_PREFIX.rstrip("/")
 | 
			
		||||
MOONSTREAM_S3_SMARTCONTRACTS_ABI_PREFIX = (
 | 
			
		||||
    MOONSTREAM_S3_SMARTCONTRACTS_ABI_PREFIX.rstrip("/")
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,8 +7,8 @@ export MOONSTREAM_ADMIN_ACCESS_TOKEN="<Access token to application resources>"
 | 
			
		|||
export MOONSTREAM_INTERNAL_HOSTED_ZONE_ID="<moonstream_internal_hosted_zone_id>"
 | 
			
		||||
export MOONSTREAM_ETHEREUM_WEB3_PROVIDER_URI="<connection_path_uri_to_ethereum_node>"
 | 
			
		||||
export AWS_S3_SMARTCONTRACT_BUCKET="<AWS S3 bucket to store smart contracts>"
 | 
			
		||||
export AWS_S3_SMARTCONTRACTS_ABI_BUCKET="<AWS S3 bucket to store smart contracts ABI>"
 | 
			
		||||
export AWS_S3_SMARTCONTRACTS_ABI_PREFIX="<Previx for AWS S3 bucket (v1/v2/dev/..)>"
 | 
			
		||||
export MOONSTREAM_S3_SMARTCONTRACTS_ABI_BUCKET="<AWS S3 bucket to store smart contracts ABI>"
 | 
			
		||||
export MOONSTREAM_S3_SMARTCONTRACTS_ABI_PREFIX="<Previx for AWS S3 bucket (prod,dev,..)>"
 | 
			
		||||
export BUGOUT_BROOD_URL="https://auth.bugout.dev"
 | 
			
		||||
export BUGOUT_SPIRE_URL="https://spire.bugout.dev"
 | 
			
		||||
export HUMBUG_REPORTER_BACKEND_TOKEN="<Bugout Humbug token for crash reports>"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue