Skip to content

Commit

Permalink
Linter
Browse files Browse the repository at this point in the history
  • Loading branch information
igorsereda committed Dec 21, 2024
1 parent 54604ba commit 65f6635
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 86 deletions.
14 changes: 4 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.ONESHELL:
.DEFAULT_GOAL: all

py := poetry run
py := uv run

source_dir := bridge_indexer
unit_tests_dir := tests
Expand All @@ -14,12 +14,6 @@ test:
install:
poetry install `if [ "${DEV}" = "0" ]; then echo "--only main"; fi` --sync

isort:
$(py) isort $(source_dir) $(unit_tests_dir)

ssort:
$(py) ssort $(source_dir) $(unit_tests_dir)

black:
$(py) black $(source_dir) $(unit_tests_dir)

Expand All @@ -29,7 +23,7 @@ ruff:
mypy:
$(py) mypy $(source_dir) $(unit_tests_dir)

lint: isort ssort black ruff mypy
lint: black ruff mypy

wipe:
$(py) dipdup $(dipdup_args) schema wipe --force
Expand All @@ -41,7 +35,7 @@ run:
$(py) dipdup $(dipdup_args) run

up:
docker-compose up --build --remove-orphans --force-recreate --abort-on-container-exit
docker compose up --build --remove-orphans --force-recreate --abort-on-container-exit

down:
docker-compose down --volumes
docker compose down --volumes
103 changes: 62 additions & 41 deletions bridge_indexer/handlers/bridge_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class BridgeMatcher:
async def check_pending_tezos_deposits(cls):
if not BridgeMatcherLocks.pending_tezos_deposits:
return
else:
BridgeMatcherLocks.pending_tezos_deposits = False
BridgeMatcherLocks.pending_tezos_deposits = False

qs = TezosDepositOperation.filter(bridge_deposits=None)
async for l1_deposit in qs:
Expand All @@ -45,20 +44,29 @@ async def check_pending_tezos_deposits(cls):
async def check_pending_inbox(cls):
if not BridgeMatcherLocks.pending_inbox:
return
else:
BridgeMatcherLocks.pending_inbox = False

qs = BridgeDepositOperation.filter(
inbox_message=None,
).order_by(
'l1_transaction__level', 'l1_transaction__counter', 'l1_transaction__nonce',
).prefetch_related('l1_transaction')
BridgeMatcherLocks.pending_inbox = False

qs = (
BridgeDepositOperation.filter(
inbox_message=None,
)
.order_by(
'l1_transaction__level',
'l1_transaction__counter',
'l1_transaction__nonce',
)
.prefetch_related('l1_transaction')
)
async for bridge_deposit in qs:
bridge_deposit: BridgeDepositOperation
inbox_message = await RollupInboxMessage.filter(
parameters_hash=bridge_deposit.l1_transaction.parameters_hash,
level=bridge_deposit.l1_transaction.level,
).order_by('index').first()
inbox_message = (
await RollupInboxMessage.filter(
parameters_hash=bridge_deposit.l1_transaction.parameters_hash,
level=bridge_deposit.l1_transaction.level,
)
.order_by('index')
.first()
)

if inbox_message:
bridge_deposit.inbox_message = inbox_message
Expand All @@ -72,12 +80,15 @@ async def check_pending_inbox(cls):
async def check_pending_etherlink_deposits(cls):
if not BridgeMatcherLocks.pending_etherlink_deposits:
return
else:
BridgeMatcherLocks.pending_etherlink_deposits = False
BridgeMatcherLocks.pending_etherlink_deposits = False

qs = EtherlinkDepositOperation.filter(
bridge_deposits=None,
).prefetch_related('l2_token').order_by('level', 'transaction_index', 'log_index')
qs = (
EtherlinkDepositOperation.filter(
bridge_deposits=None,
)
.prefetch_related('l2_token')
.order_by('level', 'transaction_index', 'log_index')
)

async for l2_deposit in qs:
l2_deposit: EtherlinkDepositOperation
Expand Down Expand Up @@ -114,13 +125,16 @@ async def check_pending_etherlink_deposits(cls):
async def check_pending_etherlink_xtz_deposits(cls):
if not BridgeMatcherLocks.pending_etherlink_xtz_deposits:
return
else:
BridgeMatcherLocks.pending_etherlink_xtz_deposits = False
BridgeMatcherLocks.pending_etherlink_xtz_deposits = False

qs = EtherlinkDepositOperation.filter(
bridge_deposits=None,
l2_token_id='xtz',
).order_by('level', 'transaction_index').prefetch_related('l2_token', 'l2_token__ticket')
qs = (
EtherlinkDepositOperation.filter(
bridge_deposits=None,
l2_token_id='xtz',
)
.order_by('level', 'transaction_index')
.prefetch_related('l2_token', 'l2_token__ticket')
)
async for l2_deposit in qs:
l2_deposit: EtherlinkDepositOperation
bridge_deposit = (
Expand Down Expand Up @@ -159,8 +173,7 @@ async def check_pending_etherlink_xtz_deposits(cls):
async def check_pending_etherlink_withdrawals(cls):
if not BridgeMatcherLocks.pending_etherlink_withdrawals:
return
else:
BridgeMatcherLocks.pending_etherlink_withdrawals = False
BridgeMatcherLocks.pending_etherlink_withdrawals = False

qs = EtherlinkWithdrawOperation.filter(bridge_withdrawals=None)
async for l2_withdrawal in qs:
Expand All @@ -179,20 +192,29 @@ async def check_pending_etherlink_withdrawals(cls):
async def check_pending_outbox(cls):
if not BridgeMatcherLocks.pending_outbox:
return
else:
BridgeMatcherLocks.pending_outbox = False

qs = BridgeWithdrawOperation.filter(
outbox_message=None,
).order_by(
'l2_transaction__level', 'l2_transaction__transaction_index', 'l2_transaction__log_index',
).prefetch_related('l2_transaction')
BridgeMatcherLocks.pending_outbox = False

qs = (
BridgeWithdrawOperation.filter(
outbox_message=None,
)
.order_by(
'l2_transaction__level',
'l2_transaction__transaction_index',
'l2_transaction__log_index',
)
.prefetch_related('l2_transaction')
)
async for bridge_withdrawal in qs:
bridge_withdrawal: BridgeWithdrawOperation
outbox_message = await RollupOutboxMessage.filter(
parameters_hash=bridge_withdrawal.l2_transaction.parameters_hash,
bridge_withdrawals=None,
).order_by('level', 'index').first()
outbox_message = (
await RollupOutboxMessage.filter(
parameters_hash=bridge_withdrawal.l2_transaction.parameters_hash,
bridge_withdrawals=None,
)
.order_by('level', 'index')
.first()
)

if outbox_message:
bridge_withdrawal.outbox_message = outbox_message
Expand All @@ -206,8 +228,7 @@ async def check_pending_outbox(cls):
async def check_pending_tezos_withdrawals(cls):
if not BridgeMatcherLocks.pending_tezos_withdrawals:
return
else:
BridgeMatcherLocks.pending_tezos_withdrawals = False
BridgeMatcherLocks.pending_tezos_withdrawals = False

qs = TezosWithdrawOperation.filter(bridge_withdrawals=None).order_by('level')
async for l1_withdrawal in qs:
Expand Down
21 changes: 12 additions & 9 deletions bridge_indexer/handlers/rollup_message.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import threading

from collections.abc import AsyncGenerator
from datetime import datetime
from typing import Any
from typing import AsyncGenerator
from typing import TYPE_CHECKING
from typing import Any
from uuid import NAMESPACE_OID
from uuid import uuid5

Expand Down Expand Up @@ -32,7 +31,6 @@
from bridge_indexer.models import TezosTicket
from bridge_indexer.types.kernel.evm_events.withdrawal import WithdrawalPayload as FAWithdrawalPayload
from bridge_indexer.types.kernel_native.evm_events.withdrawal import WithdrawalPayload as NativeWithdrawalPayload

from bridge_indexer.types.rollup.tezos_parameters.default import DefaultParameter
from bridge_indexer.types.rollup.tezos_parameters.default import TicketContent as RollupParametersTicketContent
from bridge_indexer.types.rollup.tezos_storage import RollupStorage
Expand Down Expand Up @@ -98,7 +96,10 @@ async def update_proof(self):
bridge_withdraw_operation: BridgeWithdrawOperation
outbox_message = bridge_withdraw_operation.outbox_message

if head_data.level > outbox_message.level + self._protocol.smart_rollup_challenge_window + self._protocol.smart_rollup_max_active_outbox_levels:
if (
head_data.level
> outbox_message.level + self._protocol.smart_rollup_challenge_window + self._protocol.smart_rollup_max_active_outbox_levels
):
continue

if await RollupCementedCommitment.filter(inbox_level__gte=outbox_message.level).count() == 0:
Expand Down Expand Up @@ -391,10 +392,12 @@ async def from_outbox_message(self, ticket_service: TicketService) -> str:

ticket = await ticket_service.fetch_ticket(
parameters.ticket.ticketer,
RollupParametersTicketContent.model_validate(obj={
'nat': str(parameters.ticket.content.ticket_id),
'bytes': bytes_field,
}),
RollupParametersTicketContent.model_validate(
obj={
'nat': str(parameters.ticket.content.ticket_id),
'bytes': bytes_field,
}
),
)

comparable_data = ComparableDTO(
Expand Down
3 changes: 2 additions & 1 deletion bridge_indexer/handlers/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
if TYPE_CHECKING:
from dipdup.datasources.tezos_tzkt import TezosTzktDatasource
from dipdup.datasources.tzip_metadata import TzipMetadataDatasource

from bridge_indexer.handlers.service_container import BridgeConstantStorage

from bridge_indexer.models import EtherlinkToken
Expand Down Expand Up @@ -160,7 +161,7 @@ def get_ticket_content_bytes(
)

ticket_content_hex = ''.join(
remove_0x_prefix(hex_encode_abi_type(abi_type, value)) for abi_type, value in zip(abi_types, normalized_values)
remove_0x_prefix(hex_encode_abi_type(abi_type, value)) for abi_type, value in zip(abi_types, normalized_values, strict=False)
)

return bytes.fromhex(ticket_content_hex)
Expand Down
1 change: 0 additions & 1 deletion bridge_indexer/types/output_proof/output_proof.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import

from bridge_indexer.types.output_proof.tree_encoding import TreeEncoding
from bridge_indexer.types.output_proof.unpacker import BaseBinarySchema
Expand Down
3 changes: 1 addition & 2 deletions bridge_indexer/types/output_proof/unpacker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sys
from collections import OrderedDict
from typing import Any
from typing import Type

from pydantic import BaseModel

Expand All @@ -11,7 +10,7 @@
class Part(BaseModel):
name: str
size: int | str | None
type: Type['BaseBinarySchema'] | str
type: type['BaseBinarySchema'] | str


class BaseBinarySchema:
Expand Down
12 changes: 2 additions & 10 deletions bridge_indexer/types/rollup_node/proof.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import json
from typing import TYPE_CHECKING

from base58 import b58decode_check
from base58 import b58encode_check
from pydantic import BaseModel

if TYPE_CHECKING:
from typing import Generator
from collections.abc import Generator

from pydantic.typing import AnyCallable
from pydantic.deprecated.decorator import AnyCallable

CallableGenerator = Generator[AnyCallable, None, None]

Expand Down Expand Up @@ -81,10 +80,3 @@ class Proof(str):
class OutputProof(BaseModel):
commitment: SmartRollupCommitmentHash
proof: Proof


data = '{"commitment":"src139Y6mMHjFv1sLG8hAx9SP4sNT8Wz52DRZSos5gZqBxJUcS8cj4","proof":"03000248499c9d41a8ad43af5c2143d08d3046c0fcda8c0ccca35a493c62d9a71b2cb448499c9d41a8ad43af5c2143d08d3046c0fcda8c0ccca35a493c62d9a71b2cb40005820764757261626c65d059a01a146cc0254fb559ac85e2bcc1e6e51ccde65f6bda09869f4e86cbf442a903746167c00800000004536f6d650003c08cd439daf609f838d2c8a43aa75ed227baaaca7f4a9312448959d2641896f5b6820576616c7565810370766d8107627566666572738205696e707574820468656164c00100066c656e677468c00100066f75747075740004820132810a6c6173745f6c6576656cc004002d42a70133810f76616c69646974795f706572696f64c00400013b0082013181086f7574626f78657301c184015f5d012fa2c09e9d0fb1f84ba48fc95ba3b90a9404cc8e31e3cb434601b0fb23d45d39fbf6a301179a010bfac0c699abb5e9b26ce388c58d1712bd11b79d7ac52d2c5d296578fc0cea8dc4685c010609c0713ac44b458e045d6ba3fd64685bfa03f512c655fafea361d8ae2909b70cd33e010302c0ef8a57be3c044cc0852c87c9c0c0a818649935c58f48e63e659766ba9a1539c601018fc0730f6f5c72cf675562c3808fbb1a8c7d6d77cc9a3457c7c7e89295b5f728ead500dcc0762d69ead8181946282f52bde668ab7789d5538a99ea660a22ccc6f2fa3516b8006f003d0024c063cff88ca82e2c6e0b5cdfea29819148427f4f86cb3a791f2e45822a880f01360018c0f6913ff706bd5195c84a8f0bce104d258e86f5292ddd86ac4835844c24c48fae000d00070003c0a301ecbe3b8643e33f5462e08aa448a77d81ab4450b819b5ba8dcbdae347304b8107323931393133360003810468656164c001008208636f6e74656e74730003820130c0e8000000e400000000df07070a0000001600008a7390072a389159c73687165cd7910e8a39160607070a000000160155c34fe2c664715ec4c0a43a01f1e4141fa9b3cc0007070707002a05090a0000007405020000006e07040100000010636f6e74726163745f616464726573730a0000001c050a000000160158827df9def8a4d2c92152c872c553b01ff3de0b0007040100000008746f6b656e5f69640a0000000305002a0704010000000a746f6b656e5f747970650a0000000905010000000346413200050155c34fe2c664715ec4c0a43a01f1e4141fa9b3cc000000000877697468647261770132c0e8000000e400000000df07070a0000001600008a7390072a389159c73687165cd7910e8a39160607070a000000160155c34fe2c664715ec4c0a43a01f1e4141fa9b3cc0007070707002a05090a0000007405020000006e07040100000010636f6e74726163745f616464726573730a0000001c050a000000160158827df9def8a4d2c92152c872c553b01ff3de0b0007040100000008746f6b656e5f69640a0000000305002a0704010000000a746f6b656e5f747970650a0000000905010000000346413200050155c34fe2c664715ec4c0a43a01f1e4141fa9b3cc00000000087769746864726177c04c4bee8b261e5aa4de96a58dcb00a8c69a0125fcaed4e8844d1501776867852e066c656e677468c00103c09b2a388621c7631a1cb7ba04a2befdff5ba9411eee89f2e97b54e36ec3081a8cc0f16c32fc0389207e2a49d6c949950399d78cebfedd65ec1a63e208f626aa3036c085f8e370f9722a724dfa244ec6322c9dd23ebd31e914d1f796faf21e650f5f80c0883eae96313f9934c2b34264155923b34bd63ca3e421d5e566c90e2149490c78c095cf380de310d3eea4bbab05ffca1e5009bd6fe38318d68c57287ae4e013fd5cc0355175ef3f98242f1ecd6f9035c95a359b7795e8bf9124db7aaa4fb090e43054c0722759fdcd2027211b4a1d994562c1dd0d108e51106e52cd516b19040eb9dede0134810d6d6573736167655f6c696d6974c002a401047761736dd0c793e2bb253ac6f51153c363fe3acb12dd711522feb80c2c1ae125b427113f4e48499c9d41a8ad43af5c2143d08d3046c0fcda8c0ccca35a493c62d9a71b2cb4002c8ae00000000000df07070a0000001600008a7390072a389159c73687165cd7910e8a39160607070a000000160155c34fe2c664715ec4c0a43a01f1e4141fa9b3cc0007070707002a05090a0000007405020000006e07040100000010636f6e74726163745f616464726573730a0000001c050a000000160158827df9def8a4d2c92152c872c553b01ff3de0b0007040100000008746f6b656e5f69640a0000000305002a0704010000000a746f6b656e5f747970650a0000000905010000000346413200050155c34fe2c664715ec4c0a43a01f1e4141fa9b3cc00000000087769746864726177"}'

op = OutputProof.parse_obj(json.loads(data))
opc = op.commitment
assert opc
9 changes: 5 additions & 4 deletions bridge_indexer/types/ticketer/tezos_parameters/withdraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@

from __future__ import annotations

from typing import Literal

from pydantic import BaseModel
from pydantic import Extra

from bridge_indexer.types.tezos.forged_tezos_account import ForgedTezosAccount


class TicketContent(BaseModel):
class Config:
extra = Extra.forbid
forbid: Literal[forbid] = 'forbid'

ticket_id: int
metadata: bytes | None


class Ticket(BaseModel):
class Config:
extra = Extra.forbid
forbid: Literal[forbid] = 'forbid'

ticketer: ForgedTezosAccount
content: TicketContent
Expand All @@ -28,7 +29,7 @@ class Config:

class WithdrawParameter(BaseModel):
class Config:
extra = Extra.forbid
forbid: Literal[forbid] = 'forbid'

receiver: ForgedTezosAccount
ticket: Ticket
Loading

0 comments on commit 65f6635

Please sign in to comment.