-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathinfo.py
More file actions
49 lines (42 loc) · 1.44 KB
/
info.py
File metadata and controls
49 lines (42 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from typing import List
from fastapi import APIRouter, Depends, HTTPException, Path
from meta_aggregation_api.models.chain import (
AllProvidersConfigModel,
ProvidersConfigModel,
)
from meta_aggregation_api.rest_api import dependencies
info_route = APIRouter()
@info_route.get('/', response_model=List[AllProvidersConfigModel])
@info_route.get('', include_in_schema=False)
async def get_all_info(
providers: dependencies.ProvidersConfig = Depends(dependencies.providers),
):
"""
Returns information about the providers on all supported chains.
This includes name, spender_address and display_name.
"""
info = providers.get_all_providers()
return info
@info_route.get(
'/{chain_id}',
response_model=ProvidersConfigModel,
response_model_exclude={'chain_id'},
responses={404: {"description": "Chain ID not found"}},
)
@info_route.get(
'/{chain_id}/',
include_in_schema=False,
response_model=ProvidersConfigModel,
response_model_exclude={'chain_id'},
)
async def get_info(
chain_id: int = Path(..., description='Chain ID'),
providers: dependencies.ProvidersConfig = Depends(dependencies.providers),
) -> ProvidersConfigModel:
"""Returns information about the providers for a given chain ID."""
try:
info = providers.get_providers_on_chain(chain_id)
except ValueError:
raise HTTPException(status_code=404, detail='Chain ID not found')
else:
return info