Skip to content

Commit

Permalink
Add dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
moisses89 committed Dec 19, 2024
1 parent a4b4315 commit 51614cb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
9 changes: 7 additions & 2 deletions app/routers/contracts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import Annotated

from fastapi import APIRouter, Depends, Query
from fastapi import APIRouter, Depends, HTTPException, Query

from hexbytes import HexBytes
from safe_eth.eth.utils import fast_is_checksum_address
from sqlmodel.ext.asyncio.session import AsyncSession

from ..datasources.db.database import get_database_session
Expand All @@ -24,5 +26,8 @@ async def list_contracts(
offset: int = Query(None),
session: AsyncSession = Depends(get_database_session),
) -> PaginatedResponse[Contract]:
if not fast_is_checksum_address(address):
raise HTTPException(status_code=400, detail="Address is not checksumed")

contracts_service = ContractService(limit, offset)
return await contracts_service.get_contract(session, address, chain_ids)
return await contracts_service.get_contract(session, HexBytes(address), chain_ids)
5 changes: 2 additions & 3 deletions app/services/contract.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Any, Sequence

from hexbytes import HexBytes
from sqlmodel.ext.asyncio.session import AsyncSession

from app.datasources.db.models import Contract
Expand All @@ -25,7 +24,7 @@ async def get_all(session: AsyncSession) -> Sequence[Contract]:
return await Contract.get_all(session)

async def get_contract(
self, session: AsyncSession, address: str, chain_ids: list[int] | None
self, session: AsyncSession, address: bytes, chain_ids: list[int] | None
) -> PaginatedResponse[Any]:
"""
Get the contract by address and/or chain_ids
Expand All @@ -37,5 +36,5 @@ async def get_contract(
"""

return await self.pagination.paginate(
session, Contract.get_contract(HexBytes(address), chain_ids)
session, Contract.get_contract(address, chain_ids)
)
2 changes: 2 additions & 0 deletions requirements/prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ alembic==1.14.0
asyncpg==0.30.0
dramatiq[redis, watch]==1.17.1
fastapi[all]==0.115.6
hexbytes==1.2.1
periodiq==0.13.0
pydantic-settings==2.7.0
redis[hiredis]==5.2.1
safe-eth-py==6.1.0
sqladmin[full]==0.20.1
sqlmodel==0.0.22

0 comments on commit 51614cb

Please sign in to comment.