Skip to content

Commit

Permalink
correct metadata for subsquid event decoding, small inheritance fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Wizard1209 committed Nov 20, 2024
1 parent 6d2cd2c commit 3a5f7cf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/dipdup/datasources/substrate_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
from dataclasses import field
from pathlib import Path
from typing import TYPE_CHECKING
from scalecodec.base import RuntimeConfigurationObject
from scalecodec.base import ScaleBytes

import orjson
import pysignalr.exceptions
from scalecodec.base import ScaleBytes

from dipdup.config import HttpConfig
from dipdup.config.substrate import SubstrateDatasourceConfigU
Expand Down Expand Up @@ -158,17 +157,18 @@ async def get_events_storage(self, hash: str) -> dict:
async def get_events(self, height: int, decoder: SubstrateRuntime) -> tuple[SubstrateEventData]:
# TODO: get info for storage request for events
block_hash = await self.get_block_hash(height)
header = await self._jsonrpc_request('chain_getHeader', [block_hash])
#spec_version = header['specVersion']# for event decoding
event_data = await self.get_events_storage(block_hash)
runtime_config = decoder.runtime_config
spec = decoder.get_spec_version('v701')

# take type from runtime config
metadata_bin: str = await self.get_raw_metadata(block_hash)
metadata = runtime_config.create_scale_object(
'MetadataVersioned', data=ScaleBytes(metadata_bin)
)
metadata.decode()

# add runtime metadata using metadata kwarg
scale_object = runtime_config.create_scale_object(
'Vec<EventRecord>', metadata=spec._metadata
'Vec<EventRecord>', metadata=metadata
)
event_bytes = ScaleBytes(event_data)
event = scale_object.decode(event_bytes)
Expand Down
1 change: 0 additions & 1 deletion src/dipdup/indexes/evm_events/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ async def fetch_by_level(self) -> AsyncIterator[tuple[int, tuple[EvmEventData, .


class EvmNodeEventFetcher(EvmNodeFetcher[EvmEventData]):
_datasource: EvmNodeDatasource

def __init__(
self,
Expand Down
4 changes: 2 additions & 2 deletions src/dipdup/indexes/starknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from dipdup.datasources.starknet_node import StarknetNodeDatasource
from dipdup.datasources.starknet_subsquid import StarknetSubsquidDatasource
from dipdup.index import IndexQueueItemT
from dipdup.indexes.evm import EvmIndex
from dipdup.indexes._subsquid import SubsquidIndex

StarknetDatasource = StarknetSubsquidDatasource | StarknetNodeDatasource

Expand All @@ -20,7 +20,7 @@

class StarknetIndex(
Generic[IndexConfigT, IndexQueueItemT, DatasourceT],
EvmIndex[IndexConfigT, IndexQueueItemT, DatasourceT],
SubsquidIndex[IndexConfigT, IndexQueueItemT, DatasourceT],
ABC,
):
def __init__(
Expand Down

0 comments on commit 3a5f7cf

Please sign in to comment.