diff --git a/.github/workflows/lint.backend.yml b/.github/workflows/lint.backend.yml index e5514ae4..8aae8ed9 100644 --- a/.github/workflows/lint.backend.yml +++ b/.github/workflows/lint.backend.yml @@ -19,9 +19,9 @@ jobs: - name: Install test requirements working-directory: ./backend run: pip install -r requirements.txt - # - name: Mypy type check - # working-directory: ./backend - # run: mypy moonstream/ + - name: Mypy type check + working-directory: ./backend + run: mypy moonstream/ - name: Black syntax check working-directory: ./backend run: black --check moonstream/ diff --git a/backend/moonstream/actions.py b/backend/moonstream/actions.py index eed979a9..87a2dce6 100644 --- a/backend/moonstream/actions.py +++ b/backend/moonstream/actions.py @@ -1,14 +1,11 @@ -from datetime import datetime +import json import logging +from typing import Dict, Any, List, Optional - -from typing import Dict, Any, List, Optional, Union - -from sqlalchemy.engine.base import Transaction +import boto3 # type: ignore from moonstreamdb.models import ( EthereumBlock, EthereumTransaction, - EthereumPendingTransaction, EthereumAddress, EthereumLabel, ) @@ -16,10 +13,7 @@ from sqlalchemy import or_, and_, text from sqlalchemy.orm import Session from . import data - from .settings import DEFAULT_STREAM_TIMEINTERVAL, ETHERSCAN_SMARTCONTRACTS_BUCKET -import boto3 -import json logger = logging.getLogger(__name__) @@ -299,8 +293,8 @@ def get_source_code( def get_address_labels( - db_session: Session, start: int, limit: int, addresses: Optional[List[str]] = None -) -> List[EthereumAddress]: + db_session: Session, start: int, limit: int, addresses: Optional[str] = None +) -> data.AddressListLabelsResponse: """ Attach labels to addresses. """ diff --git a/backend/moonstream/routes/txinfo.py b/backend/moonstream/routes/txinfo.py index ee0716a9..2e980425 100644 --- a/backend/moonstream/routes/txinfo.py +++ b/backend/moonstream/routes/txinfo.py @@ -97,8 +97,8 @@ async def txinfo_ethereum_blockchain_handler( ) async def addresses_labels_handler( addresses: Optional[str] = Query(None), - start: Optional[int] = Query(0), - limit: Optional[int] = Query(100), + start: int = Query(0), + limit: int = Query(100), db_session: Session = Depends(yield_db_session), ) -> data.AddressListLabelsResponse: """ @@ -110,11 +110,11 @@ async def addresses_labels_handler( status_code=406, detail="The limit cannot exceed 100 addresses" ) try: - addresses = actions.get_address_labels( + addresses_response = actions.get_address_labels( db_session=db_session, start=start, limit=limit, addresses=addresses ) except Exception as err: logger.error(f"Unable to get info about Ethereum addresses {err}") raise HTTPException(status_code=500) - return addresses + return addresses_response diff --git a/backend/moonstream/settings.py b/backend/moonstream/settings.py index 440176f6..4b31e73c 100644 --- a/backend/moonstream/settings.py +++ b/backend/moonstream/settings.py @@ -16,8 +16,8 @@ MOONSTREAM_DATA_JOURNAL_ID = os.environ.get("MOONSTREAM_DATA_JOURNAL_ID") if MOONSTREAM_DATA_JOURNAL_ID is None: raise ValueError("MOONSTREAM_DATA_JOURNAL_ID environment variable must be set") -MOONSTREAM_ADMIN_ACCESS_TOKEN = os.environ.get("MOONSTREAM_ADMIN_ACCESS_TOKEN") -if MOONSTREAM_ADMIN_ACCESS_TOKEN is None: +MOONSTREAM_ADMIN_ACCESS_TOKEN = os.environ.get("MOONSTREAM_ADMIN_ACCESS_TOKEN", "") +if MOONSTREAM_ADMIN_ACCESS_TOKEN == "": raise ValueError("MOONSTREAM_ADMIN_ACCESS_TOKEN environment variable must be set") # Origin