-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d76b37
commit 47f18ed
Showing
6 changed files
with
37 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,36 @@ | ||
import datetime | ||
|
||
from dipdup.context import HookContext | ||
|
||
from dex_screener.models import Block | ||
|
||
|
||
async def refresh_blocks( | ||
ctx: HookContext, | ||
) -> None: | ||
await ctx.execute_sql_script('refresh_blocks') | ||
await ctx.execute_sql_script('refresh_blocks') | ||
|
||
levels: list[int] = await Block.filter(timestamp__isnull=True).order_by('level').limit(100).values_list('level', flat=True) | ||
if len(levels) == 0: | ||
return | ||
request_payload = { | ||
'query': ' '.join([ | ||
'query { blocks(where: {height_in:', | ||
str(levels), | ||
'}) { height timestamp } }', | ||
]), | ||
} | ||
|
||
explorer = ctx.get_http_datasource('explorer') | ||
response = await explorer.request('post', 'graphql', json=request_payload) | ||
|
||
blocks = [ | ||
Block( | ||
level=block_data['height'], | ||
timestamp=datetime.datetime.fromisoformat(block_data['timestamp']).timestamp(), | ||
) for block_data in response['data']['blocks'] | ||
] | ||
|
||
await Block.bulk_update( | ||
objects=blocks, fields=['timestamp'] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters