From b29465c0c0f602626868cc586143d6bfaceef92d Mon Sep 17 00:00:00 2001 From: Lev Gorodetskiy Date: Wed, 15 Jan 2025 02:17:07 -0300 Subject: [PATCH] don't deserialize args twice --- src/dipdup/models/substrate.py | 6 +----- src/dipdup/runtimes.py | 10 +++++++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/dipdup/models/substrate.py b/src/dipdup/models/substrate.py index 10cbf2cf7..470a3e99c 100644 --- a/src/dipdup/models/substrate.py +++ b/src/dipdup/models/substrate.py @@ -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): @@ -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, diff --git a/src/dipdup/runtimes.py b/src/dipdup/runtimes.py index 3c38b8f2e..230ad261b 100644 --- a/src/dipdup/runtimes.py +++ b/src/dipdup/runtimes.py @@ -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 @@ -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 @@ -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)