Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smart Rollup Execute Operation #915

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/dipdup/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,10 @@ def _resolve_index_links(self, index_config: ResolvedIndexConfigU) -> None:
pattern_config.originated_contract
)

elif isinstance(pattern_config, OperationsHandlerSmartRollupExecutePatternConfig):
if isinstance(pattern_config.destination, str):
pattern_config.destination = self.get_tezos_contract(pattern_config.destination)

elif isinstance(index_config, TzktBigMapsIndexConfig):
for handler_config in index_config.handlers:
handler_config.parent = index_config
Expand Down Expand Up @@ -1021,6 +1025,7 @@ def _set_names(self) -> None:
from dipdup.config.tezos_tzkt_events import TzktEventsIndexConfig
from dipdup.config.tezos_tzkt_head import TzktHeadIndexConfig
from dipdup.config.tezos_tzkt_operations import OperationsHandlerOriginationPatternConfig
from dipdup.config.tezos_tzkt_operations import OperationsHandlerSmartRollupExecutePatternConfig
from dipdup.config.tezos_tzkt_operations import OperationsHandlerTransactionPatternConfig
from dipdup.config.tezos_tzkt_operations import TzktOperationsIndexConfig
from dipdup.config.tezos_tzkt_operations import TzktOperationsUnfilteredIndexConfig
Expand Down
39 changes: 38 additions & 1 deletion src/dipdup/config/tezos_tzkt_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ def format_untyped_operation_argument(
return arg_name, 'TzktOperationData | None'
return arg_name, 'TzktOperationData'

@classmethod
def format_sr_execute_argument(
cls,
) -> tuple[str, str]:
arg_name = 'execute'
igorsereda marked this conversation as resolved.
Show resolved Hide resolved
return pascal_to_snake(arg_name), 'TzktSmartRollupExecute'


@dataclass
class OperationsHandlerTransactionPatternConfig(PatternConfig, SubgroupIndexMixin):
Expand Down Expand Up @@ -236,6 +243,36 @@ def typed_contract(self) -> TezosContractConfig | None:
return None


@dataclass
class OperationsHandlerSmartRollupExecutePatternConfig(PatternConfig, SubgroupIndexMixin):
"""Operation handler pattern config

:param type: always 'sr_execute'
:param source: Match operations by source contract alias
:param destination: Match operations by destination contract alias
:param optional: Whether can operation be missing in operation group
"""

type: Literal['sr_execute'] = 'sr_execute'
source: TezosContractConfig | None = None
destination: TezosContractConfig | None = None
optional: bool = False

def __post_init_post_parse__(self) -> None:
SubgroupIndexMixin.__post_init_post_parse__(self)

def iter_imports(self, package: str) -> Iterator[tuple[str, str]]:
yield 'dipdup.models.tezos_tzkt', 'TzktSmartRollupExecute'

def iter_arguments(self) -> Iterator[tuple[str, str]]:
yield self.format_sr_execute_argument()

@property
def typed_contract(self) -> TezosContractConfig | None:
if self.destination:
return self.destination
return None

@dataclass
class TzktOperationsIndexConfig(TzktIndexConfig):
"""Operation index config
Expand Down Expand Up @@ -281,7 +318,7 @@ def strip(cls, config_dict: dict[str, Any]) -> None:


# FIXME: Reversed for new Pydantic. Why?
OperationsHandlerPatternConfigU = OperationsHandlerTransactionPatternConfig | OperationsHandlerOriginationPatternConfig
OperationsHandlerPatternConfigU = OperationsHandlerTransactionPatternConfig | OperationsHandlerOriginationPatternConfig | OperationsHandlerSmartRollupExecutePatternConfig


@dataclass
Expand Down
57 changes: 57 additions & 0 deletions src/dipdup/datasources/tezos_tzkt.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@
'parameter',
'hasInternals',
)
SR_EXECUTE_OPERATION_FIELDS = (
*OPERATION_FIELDS,
'rollup',
'commitment',
'ticketTransfersCount',
)
BIGMAP_FIELDS = (
'ptr',
'contract',
Expand Down Expand Up @@ -766,6 +772,57 @@ async def iter_transactions(
):
yield batch

async def get_sr_execute(
self,
field: str,
addresses: set[str] | None,
first_level: int | None = None,
last_level: int | None = None,
offset: int | None = None,
limit: int | None = None,
) -> tuple[TzktOperationData, ...]:
params = self._get_request_params(
first_level=first_level,
last_level=last_level,
offset=None,
limit=limit,
select=SR_EXECUTE_OPERATION_FIELDS,
values=True,
sort='level',
status='applied',
)
# TODO: TzKT doesn't support sort+cr currently
if offset is not None:
params['id.gt'] = offset

if addresses:
params[f'{field}.in'] = ','.join(addresses)

raw_transactions = await self._request_values_dict(
'get',
url='v1/operations/sr_execute',
params=params,
)

# NOTE: `type` field needs to be set manually when requesting operations by specific type
return tuple(TzktOperationData.from_json(op, type_='sr_execute') for op in raw_transactions)

async def iter_sr_execute(
self,
field: str,
addresses: set[str],
first_level: int,
last_level: int,
) -> AsyncIterator[tuple[TzktOperationData, ...]]:
async for batch in self._iter_batches(
self.get_sr_execute,
field,
addresses,
first_level,
last_level,
):
yield batch

async def get_big_maps(
self,
addresses: set[str],
Expand Down
Loading