Skip to content

Commit

Permalink
don't deserialize args twice
Browse files Browse the repository at this point in the history
  • Loading branch information
droserasprout committed Jan 15, 2025
1 parent 254ee0d commit b29465c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 1 addition & 5 deletions src/dipdup/models/substrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from dipdup.fetcher import HasLevel
from dipdup.runtimes import SubstrateRuntime
from dipdup.runtimes import get_event_arg_names


class _BlockHeader(TypedDict):
Expand Down Expand Up @@ -114,10 +113,7 @@ class SubstrateEvent(Generic[PayloadT]):
def payload(self) -> PayloadT:
# NOTE: We receive decoded args from node datasource and encoded from subsquid datasource
if self.data.decoded_args is not None:
spec_version = self.runtime.get_spec_version(self.runtime.runtime_config.active_spec_version_id)
abi = spec_version.get_event_abi(self.data.name)
arg_names = get_event_arg_names(abi)
payload = dict(zip(arg_names, self.data.decoded_args, strict=False))
payload = self.data.decoded_args
elif self.data.args is not None and self.data.header_extra is not None:
payload = self.runtime.decode_event_args(
name=self.data.name,
Expand Down
10 changes: 7 additions & 3 deletions src/dipdup/runtimes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import re
from contextlib import suppress
from copy import copy
from functools import cache
from functools import cached_property
from pathlib import Path
Expand Down Expand Up @@ -174,13 +175,16 @@ def decode_event_args(

args = dict(zip(arg_names, args, strict=True))
else:
arg_names = event_abi['args_name']
arg_names = get_event_arg_names(event_abi)

payload = {}
for (key, value), type_ in zip(args.items(), arg_types, strict=True):
if isinstance(value, int):
payload[key] = value
continue
if isinstance(value, str) and value[:2] != '0x':
payload[key] = int(value)
continue
if isinstance(value, dict) and '__kind' in value:
payload[key] = value['__kind']
continue
Expand All @@ -197,8 +201,8 @@ def decode_event_args(

payload[key] = scale_obj.value_serialized

# FIXME: Subsquid camelcases arg keys for some reason
for key in payload:
# NOTE: Subsquid camelcases arg keys for some reason
for key in copy(payload):
if key not in arg_names:
new_key = pascal_to_snake(key)
payload[new_key] = payload.pop(key)
Expand Down

0 comments on commit b29465c

Please sign in to comment.