Skip to content

Commit

Permalink
cr: changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kgarbacinski committed Jan 13, 2025
1 parent 8a86933 commit a8ebdd9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion backend/v2/projects/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async def get_project_addresses(self, epoch_number: int) -> list[str]:
)
return await self.contract.functions.getProposalAddresses(epoch_number).call()

async def get_project_cid(self):
async def get_project_cid(self) -> str:
logging.debug("[Projects contract] Getting projects CID")
return await self.contract.functions.cid().call()

Expand Down
9 changes: 3 additions & 6 deletions backend/v2/projects/core.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from app.infrastructure.database.models import ProjectsDetails


def parse_cids_to_epochs_dict(cids_str: str) -> dict[int, str]:
def parse_cids_to_epochs_dict(cids: list[str]) -> dict[int, str]:
"""
Parse a string of comma-separated CIDs to a dictionary of epoch to CID.
Convert a list of CIDs to a dictionary mapping epochs to CIDs.
"""
return {
index: element.strip()
for index, element in enumerate(cids_str.split(","), start=1)
}
return {index: cid.strip() for index, cid in enumerate(cids, start=1)}


def process_search_params(
Expand Down
6 changes: 5 additions & 1 deletion backend/v2/projects/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ class ProjectsSettings(OctantSettings):
Field(validation_alias="chain_id"), ChainTypes.MAINNET
)
)
mainnet_project_cids: str = Field(
mainnet_project_cids_raw: str = Field(
validation_alias="mainnet_proposal_cids", default=DEFAULT_MAINNET_PROJECT_CIDS
)

@property
def mainnet_project_cids(self) -> list[str]:
return self.mainnet_project_cids_raw.split(",")


class ProjectsAllocationThresholdSettings(OctantSettings):
project_count_multiplier: int = Field(
Expand Down
2 changes: 1 addition & 1 deletion backend/v2/projects/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ class ProjectsDetailsResponseV1(OctantModel):
SearchPhrasesParameter = Annotated[
str, Query(..., alias="searchPhrases", description="Comma-separated search phrases")
]
EpochNumberPath = Annotated[str, Path(..., description="Epoch number")]
EpochNumberPath = Annotated[int, Path(..., description="Epoch number")]
25 changes: 15 additions & 10 deletions backend/v2/projects/services/projects_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ async def get_by_search_phrase(self) -> list[ProjectModel]:
all_filtered_projects_details = []

for epoch_number in self.epoch_numbers:
projects_details = await get_projects_details_for_epoch(
self.session, epoch_number
)
for search_phrase in self.search_phrases:
projects_details = await get_projects_details_for_epoch(
self.session, epoch_number
)
filtered_projects_details = filter_projects_details(
projects_details, search_phrase
)
Expand All @@ -50,18 +50,13 @@ class ProjectsMetadataGetter:
# Parameters
epoch_number: int
is_mainnet: bool
mainnet_project_cids: str
mainnet_project_cids: list[str]

# Dependencies
session: AsyncSession
projects_contracts: ProjectsContracts

async def get(self) -> ProjectsMetadataResponseV1:
"""
Get projects metadata for a specific epoch.
"""
logging.debug(f"Getting projects metadata for epoch {self.epoch_number}")

async def _get_projects_cid(self) -> str:
if self.is_mainnet:
epoch_to_cid_dict = parse_cids_to_epochs_dict(self.mainnet_project_cids)
projects_cid = (
Expand All @@ -72,6 +67,16 @@ async def get(self) -> ProjectsMetadataResponseV1:
else:
projects_cid = await self.projects_contracts.get_project_cid()

return projects_cid

async def get(self) -> ProjectsMetadataResponseV1:
"""
Get projects metadata for a specific epoch.
"""
logging.debug(f"Getting projects metadata for epoch {self.epoch_number}")

projects_cid = await self._get_projects_cid()

logging.debug(f"Projects CID: {projects_cid}")

projects_address_list = await self.projects_contracts.get_project_addresses(
Expand Down

0 comments on commit a8ebdd9

Please sign in to comment.