From 637be3beaeb9fc8dd745de060e928dec02cf443d Mon Sep 17 00:00:00 2001 From: Lev Gorodetskiy Date: Thu, 16 Jan 2025 14:25:05 -0300 Subject: [PATCH] tuples wip, hidden command --- src/dipdup/cli.py | 43 +++++++++++++++++++++++++++++++++ src/dipdup/codegen/substrate.py | 5 ++++ src/dipdup/runtimes.py | 14 +++-------- 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/dipdup/cli.py b/src/dipdup/cli.py index 81c6a4bdd..a36ab4383 100644 --- a/src/dipdup/cli.py +++ b/src/dipdup/cli.py @@ -1,6 +1,7 @@ # NOTE: All imports except the basic ones are very lazy in this module. Let's keep it that way. import asyncio import atexit +from collections import defaultdict import logging import sys import traceback @@ -978,6 +979,48 @@ async def self_env(ctx: click.Context) -> None: env.refresh() env.print() +@cli.group(hidden=True) +@click.pass_context +@_cli_wrapper +async def abi(ctx: click.Context) -> None: + pass + +@abi.command(name='lookup', hidden=True) +@click.pass_context +@click.argument('query', type=str) +@_cli_wrapper +async def abi_lookup(ctx: click.Context, query: str) -> None: + import subprocess + + from dipdup.package import DipDupPackage + + config: DipDupConfig = ctx.obj.config + package = DipDupPackage(config.package_path) + package.initialize() + + abi_paths = ( + package.abi, + package.abi_local, + ) + # NOTE: save output instead of printing it + res = subprocess.run( + ('grep', '-n', '-r', query, *abi_paths), + capture_output=True, + check=True, + ) + out = res.stdout.decode() + lines = out.splitlines() + grouped_lines = defaultdict(list) + for line in lines: + path, lineno, content = line.split(':', 2) + grouped_lines[path].append(f'{lineno:>6}: {content}') + + for path, lines in grouped_lines.items(): + echo('') + echo(path) + for line in sorted(lines): + echo('- ' + line) + echo('') @cli.group() @click.pass_context diff --git a/src/dipdup/codegen/substrate.py b/src/dipdup/codegen/substrate.py index 7d0927c75..f8d946543 100644 --- a/src/dipdup/codegen/substrate.py +++ b/src/dipdup/codegen/substrate.py @@ -67,6 +67,11 @@ def scale_type_to_jsonschema( schema['type'] = 'boolean' elif type_string in ['String', 'str']: schema['type'] = 'string' + # FIXME: We need to parse weird values like `Tuple:staging_xcm:v4:location:Locationstaging_xcm:v4:location:Location`; mind the missing delimeters + elif type_string.startswith('Tuple:'): + # inner_types = type_string[6:] + raise NotImplementedError + elif type_string.startswith('Vec<'): inner_type = type_string[4:-1] schema['type'] = 'array' diff --git a/src/dipdup/runtimes.py b/src/dipdup/runtimes.py index a0e7a55a7..cb2f64a4d 100644 --- a/src/dipdup/runtimes.py +++ b/src/dipdup/runtimes.py @@ -155,9 +155,8 @@ def decode_event_args( from scalecodec.base import ScaleBytes spec_obj = self.get_spec_version(spec_version) - event_abi = spec_obj.get_event_abi( - qualname=name, - ) + event_abi = spec_obj.get_event_abi(name) + # FIXME: Do we need original type names? # arg_types = event_abi.get('args_type_name') or event_abi['args'] arg_types = event_abi['args'] @@ -183,19 +182,14 @@ def decode_event_args( payload[key] = int(value) continue - # FIXME: Unwrap correctly - if isinstance(value, dict) and '__kind' in value: - payload[key] = value['__kind'] - continue - - # NOTE: Scale decoder expects vec length at the beginning + # NOTE: Scale decoder expects vec length at the beginning; Subsquid strips it if type_.startswith('Vec<'): value_len = len(value[2:]) * 2 value = f'0x{value_len:02x}{value[2:]}' scale_obj = self.runtime_config.create_scale_object( type_string=type_, - data=ScaleBytes(value), + data=ScaleBytes(value) if isinstance(value, str) else value, ) payload[key] = scale_obj.process()