Skip to content

Commit

Permalink
fix generated union
Browse files Browse the repository at this point in the history
  • Loading branch information
droserasprout committed Jan 15, 2025
1 parent 0842080 commit 7d72bf1
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/dipdup/codegen/substrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from dipdup.codegen import CodeGenerator
from dipdup.config import DipDupConfig
from dipdup.config import HandlerConfig
from dipdup.config.substrate import SubstrateIndexConfig
from dipdup.config.substrate_events import SubstrateEventsIndexConfig
from dipdup.config.substrate_subscan import SubstrateSubscanDatasourceConfig
Expand Down Expand Up @@ -152,10 +151,7 @@ async def generate_abis(self) -> None:

processed.add(name)

async def generate_schemas(self) -> None:
self._cleanup_schemas()

handler_config: HandlerConfig
def get_target_events(self) -> dict[str, list[str]]:
target_events: dict[str, list[str]] = {}

for index_config in self._config.indexes.values():
Expand All @@ -166,6 +162,13 @@ async def generate_schemas(self) -> None:
for handler_config in index_config.handlers:
target_events[runtime_name].append(handler_config.name)

return target_events

async def generate_schemas(self) -> None:
self._cleanup_schemas()

target_events = self.get_target_events()

if not target_events:
return

Expand Down Expand Up @@ -216,9 +219,28 @@ async def generate_schemas(self) -> None:
async def _generate_types(self, force: bool = False) -> None:
await super()._generate_types(force)

target_events = self.get_target_events()

for typeclass_dir in self._package.types.glob('**/substrate_events/*'):

typeclass_name = f'{snake_to_pascal(typeclass_dir.name)}Payload'
# NOTE: Find corresponding event
try:
events = target_events[typeclass_dir.parts[-3]]
except KeyError:
self._logger.info(
'No indexes in config use `%s` runtime; skipping `%s`', typeclass_dir.parts[-3], typeclass_dir.name
)
continue

for event_name in events:
if pascal_to_snake(event_name.replace('.', '')) == typeclass_dir.stem:
name = event_name
break
else:
raise Exception(f'Event not found for {typeclass_dir}')

# NOTE: Don't extract from typeclass path! XYK.Sell -> xyk_sell -> XykSellPayload; should be XYKSellPayload.
typeclass_name = f'{snake_to_pascal(name)}Payload'

versions = [p.stem[1:] for p in sorted_glob(typeclass_dir, '*.py') if p.name.startswith('v')]
root_lines = [
Expand Down

0 comments on commit 7d72bf1

Please sign in to comment.