Skip to content

Commit

Permalink
Fix BCD datasource get_tokens method (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
droserasprout authored Jul 10, 2021
1 parent bb51567 commit f25d4e9
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/dipdup/datasources/bcd/datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from dipdup.config import HTTPConfig
from dipdup.datasources.proxy import HTTPRequestProxy

Address = str
TOKENS_REQUEST_LIMIT = 10


class BcdDatasource:
Expand All @@ -31,8 +31,21 @@ async def run(self) -> None:
async def resync(self) -> None:
pass

async def get_tokens(self, address: Address) -> List[Dict[str, Any]]:
async def get_tokens(self, address: str) -> List[Dict[str, Any]]:
tokens, offset = [], 0
while True:
tokens_batch = await self._proxy.http_request(
'get',
url=f'{self._url}/v1/contract/{self._network}/{address}/tokens?offset={offset}',
)
tokens += tokens_batch
offset += TOKENS_REQUEST_LIMIT
if len(tokens_batch) < TOKENS_REQUEST_LIMIT:
break
return tokens

async def get_token(self, address: str, token_id: int) -> Dict[str, Any]:
return await self._proxy.http_request(
'get',
url=f'{self._url}/v1/contract/{self._network}/{address}/tokens',
url=f'{self._url}/v1/contract/{self._network}/{address}/tokens?token_id={token_id}',
)

0 comments on commit f25d4e9

Please sign in to comment.