Skip to content

Commit

Permalink
Merge branch 'next' into fix/subsquid_complex_kind_payload
Browse files Browse the repository at this point in the history
  • Loading branch information
droserasprout authored Feb 1, 2025
2 parents ef951b7 + cc50655 commit ff5319c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/dipdup/codegen/substrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ async def _generate_types(self, force: bool = False) -> None:
name = event_name
break
else:
raise Exception(f'Event not found for {typeclass_dir.stem}')
continue

# NOTE: Don't extract from typeclass path! XYK.Sell -> xyk_sell -> XykSellPayload; should be XYKSellPayload.
typeclass_name = f'{snake_to_pascal(name)}Payload'
Expand Down
14 changes: 14 additions & 0 deletions src/dipdup/runtimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,17 @@ def extract_subsquid_payload(data: Any) -> Any:
return kind

return data


def extract_multilocation_payload(data: Any) -> Any:
if isinstance(data, list | tuple):
return tuple(extract_multilocation_payload(item) for item in data)

if isinstance(data, dict):

if len(data) == 1 and (key := next(iter(data.keys()))).startswith('X'):
return data[key]

return {key: extract_multilocation_payload(value) for key, value in data.items()}

return data
27 changes: 26 additions & 1 deletion tests/test_datasources/test_substrate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

from dipdup.runtimes import extract_multilocation_payload
from dipdup.runtimes import extract_subsquid_payload

path_1 = [
Expand Down Expand Up @@ -160,6 +161,26 @@
},
}

extracted_path_1 = (
(
{
'parents': 0,
'interior': (
{'PalletInstance': 50},
{'GeneralIndex': '1337'},
),
},
84640,
),
(
{
'parents': 1,
'interior': 'Here',
},
122612710,
),
)


@pytest.mark.parametrize(
'subsquid_payload, expected_node_payload',
Expand All @@ -177,5 +198,9 @@
),
),
)
def test_extract_subsquid_payload(subsquid_payload, expected_node_payload) -> None:
def test_extract_subsquid_payload(subsquid_payload, expected_node_payload) -> None: # type: ignore
assert extract_subsquid_payload(subsquid_payload) == expected_node_payload


def test_extract_multilocation_payload() -> None:
assert extract_multilocation_payload(processed_path_1) == extracted_path_1

0 comments on commit ff5319c

Please sign in to comment.