Skip to content

Commit

Permalink
fix padding issues
Browse files Browse the repository at this point in the history
  • Loading branch information
droserasprout committed Jan 15, 2025
1 parent 224c335 commit be5fe9e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
9 changes: 4 additions & 5 deletions src/dipdup/codegen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,10 @@ async def _generate_type(self, schema_path: Path, force: bool) -> None:
self._logger.info('Generating type `%s`', class_name)
output_path.parent.mkdir(parents=True, exist_ok=True)
# TODO: make it configurable
model_type = (
dmcg.DataModelType.TypingTypedDict
if 'substrate' in str(output_path)
else dmcg.DataModelType.PydanticV2BaseModel
)
if 'substrate' in str(output_path):
model_type = dmcg.DataModelType.TypingTypedDict
else:
model_type = dmcg.DataModelType.PydanticV2BaseModel
dmcg.generate(
input_=schema_path,
output=output_path,
Expand Down
15 changes: 3 additions & 12 deletions src/dipdup/runtimes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import re
from contextlib import suppress
from functools import cache
from functools import cached_property
from pathlib import Path
Expand Down Expand Up @@ -151,7 +152,7 @@ def decode_event_args(
spec_version: str,
) -> dict[str, Any]:
from scalecodec.base import ScaleBytes
from scalecodec.exceptions import RemainingScaleBytesNotEmptyException
from scalecodec.exceptions import RemainingScaleBytesNotEmptyException # type: ignore[import-untyped]

spec_obj = self.get_spec_version(spec_version)
event_abi = spec_obj.get_event_abi(
Expand Down Expand Up @@ -189,17 +190,7 @@ def decode_event_args(
metadata=spec_obj._metadata,
)

# FIXME: padding
try:
scale_obj.decode(check_remaining=False)
except RemainingScaleBytesNotEmptyException:
padded_value = value + ('00' * (scale_obj.data.offset - scale_obj.data.length))
print(padded_value)
scale_obj = self.runtime_config.create_scale_object(
type_string=type_,
data=ScaleBytes(padded_value),
metadata=spec_obj._metadata,
)
with suppress(RemainingScaleBytesNotEmptyException):
scale_obj.decode(check_remaining=False)

payload[key] = scale_obj.value_serialized
Expand Down

0 comments on commit be5fe9e

Please sign in to comment.