Skip to content

Commit

Permalink
multiple fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Bobrikov committed Oct 18, 2023
1 parent 754d631 commit 46fc3bc
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic

### Added

- tezos.tzkt: Added new index token_balances
- tezos.tzkt.token_balances: Added new index.
- env: Added `DIPDUP_DEBUG` environment variable to enable debug logging.

### Fixed
Expand All @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic
- evm.node: Fixed incorrect log request parameters.
- evm.subsquid.events: Fixed issue with determining the last level when syncing with node.
- hasura: Increated retry count for initial connection (healthcheck).
- tezos.tzkt: Fixed token_id handler in token transfers index.

## [7.0.0] - 2023-09-25

Expand Down
2 changes: 1 addition & 1 deletion docs/2.indexes/8.tezos_tzkt_token_balances.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ network: "tezos"

# `tezos.tzkt.token_balances` index

This index allows indexing token balances of contracts compatible with [FA1.2](https://gitlab.com/tzip/tzip/-/blob/master/proposals/tzip-7/README.md) or [FA2](https://gitlab.com/tzip/tzip/-/blob/master/proposals/tzip-12/tzip-12.md) standards.
This index allows indexing token balances of contracts compatible with [FA1.2](https://gitlab.com/tzip/tzip/-/blob/master/proposals/tzip-7/README.md) or [FA2](https://gitlab.com/tzip/tzip/-/blob/master/proposals/tzip-12/tzip-12.md) standards. You can either index transfers and cumulatively calculate balances or use this index type to fetch the latest balance information directly.

```yaml [dipdup.yaml]
{{ #include ../src/demo_token_balances/dipdup.yaml }}
Expand Down
2 changes: 1 addition & 1 deletion src/dipdup/config/tezos_tzkt_token_balances.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

@dataclass
class TzktTokenBalancesHandlerConfig(HandlerConfig):
"""Token transfer handler config
"""Token balance handler config
:param callback: Callback name
:param contract: Filter by contract
Expand Down
6 changes: 4 additions & 2 deletions src/dipdup/indexes/tezos_tzkt_token_balances/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ def push_token_balances(self, token_balances: TokenBalanceQueueItem) -> None:
self.push_realtime_message(token_balances)

async def _synchronize(self, sync_level: int) -> None:
await self._enter_sync_state(sync_level)
await self._synchronize_actual(sync_level)
await self._exit_sync_state(sync_level)

async def _synchronize_actual(self, head_level: int) -> None:
"""Retrieve data for last level"""
"""Retrieve data for the current level"""
# TODO: think about logging and metrics

addresses, token_ids = set(), set()
for handler in self._config.handlers:
if handler.contract and handler.contract.address is not None:
Expand All @@ -37,7 +39,7 @@ async def _synchronize_actual(self, head_level: int) -> None:
token_ids.add(handler.token_id)

async with self._ctx.transactions.in_transaction(head_level, head_level, self.name):
# NOTE: in case of desynchronization filter balances for head_level
# NOTE: If index is out of date fetch balances as of the current head.
async for balances_batch in self._datasource.iter_token_balances(
addresses, token_ids, last_level=head_level
):
Expand Down
8 changes: 6 additions & 2 deletions src/dipdup/models/tezos_tzkt.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ class TzktTokenBalanceData(HasLevel):
first_time: datetime
# level is not defined in tzkt balances data, so it is
# Level of the block where the token balance was last changed.
level: int
last_level: int
last_time: datetime
# owner account
account_address: str | None = None
Expand All @@ -580,6 +580,10 @@ class TzktTokenBalanceData(HasLevel):
balance: str | None = None
balance_value: float | None = None

@property
def level(self) -> int:
return self.last_level

@classmethod
def from_json(cls, token_transfer_json: dict[str, Any]) -> 'TzktTokenBalanceData':
"""Convert raw token transfer message from REST or WS into dataclass"""
Expand All @@ -593,7 +597,7 @@ def from_json(cls, token_transfer_json: dict[str, Any]) -> 'TzktTokenBalanceData
transfers_count=token_transfer_json['transfersCount'],
first_level=token_transfer_json['firstLevel'],
first_time=_parse_timestamp(token_transfer_json['firstTime']),
level=token_transfer_json['lastLevel'],
last_level=token_transfer_json['lastLevel'],
last_time=_parse_timestamp(token_transfer_json['lastTime']),
account_address=token_transfer_json.get('account', {}).get('address'),
account_alias=token_transfer_json.get('account', {}).get('alias'),
Expand Down

0 comments on commit 46fc3bc

Please sign in to comment.